PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 5.7.0
Defender Security – Malware Scanner, Login Security & Firewall v5.7.0
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / vendor / web-auth / webauthn-lib / src / TrustPath / TrustPathLoader.php

TrustPathLoader.php in Defender Security – Malware Scanner, Login Security & Firewall 5.7.0, at vendor/web-auth/webauthn-lib/src/TrustPath/TrustPathLoader.php

59 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 /*
6 * The MIT License (MIT)
7 *
8 * Copyright (c) 2014-2021 Spomky-Labs
9 *
10 * This software may be modified and distributed under the terms
11 * of the MIT license. See the LICENSE file for details.
12 */
13
14 namespace Webauthn\TrustPath;
15
16 use function array_key_exists;
17 use Assert\Assertion;
18 use function in_array;
19 use InvalidArgumentException;
20 use function Safe\class_implements;
21 use function Safe\sprintf;
22
23 abstract class TrustPathLoader
24 {
25 /**
26 * @param mixed[] $data
27 */
28 public static function loadTrustPath(array $data): TrustPath
29 {
30 Assertion::keyExists($data, 'type', 'The trust path type is missing');
31 $type = $data['type'];
32 $oldTypes = self::oldTrustPathTypes();
33 switch (true) {
34 case array_key_exists($type, $oldTypes):
35 return $oldTypes[$type]::createFromArray($data);
36 case class_exists($type):
37 $implements = class_implements($type);
38 if (in_array(TrustPath::class, $implements, true)) {
39 return $type::createFromArray($data);
40 }
41 // no break
42 default:
43 throw new InvalidArgumentException(sprintf('The trust path type "%s" is not supported', $data['type']));
44 }
45 }
46
47 /**
48 * @return string[]
49 */
50 private static function oldTrustPathTypes(): array
51 {
52 return [
53 'empty' => EmptyTrustPath::class,
54 'ecdaa_key_id' => EcdaaKeyIdTrustPath::class,
55 'x5c' => CertificateTrustPath::class,
56 ];
57 }
58 }
59