PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 6.2.2
Defender Security – Malware Scanner, Login Security & Firewall v6.2.2
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 / lib / packages / Webauthn / AttestationStatement / AttestationStatement.php

AttestationStatement.php in Defender Security – Malware Scanner, Login Security & Firewall 6.2.2, at lib/packages/Webauthn/AttestationStatement/AttestationStatement.php

176 lines 4.1 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 WP_DEFENDER_VENDOR\Webauthn\AttestationStatement;
15
16 use function array_key_exists;
17 use WP_DEFENDER_VENDOR\Assert\Assertion;
18 use JsonSerializable;
19 use function WP_DEFENDER_VENDOR\Safe\sprintf;
20 use WP_DEFENDER_VENDOR\Webauthn\TrustPath\TrustPath;
21 use WP_DEFENDER_VENDOR\Webauthn\TrustPath\TrustPathLoader;
22
23 class AttestationStatement implements JsonSerializable
24 {
25 public const TYPE_NONE = 'none';
26 public const TYPE_BASIC = 'basic';
27 public const TYPE_SELF = 'self';
28 public const TYPE_ATTCA = 'attca';
29 public const TYPE_ECDAA = 'ecdaa';
30 public const TYPE_ANONCA = 'anonca';
31
32 /**
33 * @var string
34 */
35 private $fmt;
36
37 /**
38 * @var mixed[]
39 */
40 private $attStmt;
41
42 /**
43 * @var TrustPath
44 */
45 private $trustPath;
46
47 /**
48 * @var string
49 */
50 private $type;
51
52 /**
53 * @param mixed[] $attStmt
54 */
55 public function __construct(string $fmt, array $attStmt, string $type, TrustPath $trustPath)
56 {
57 $this->fmt = $fmt;
58 $this->attStmt = $attStmt;
59 $this->type = $type;
60 $this->trustPath = $trustPath;
61 }
62
63 /**
64 * @param mixed[] $attStmt
65 */
66 public static function createNone(string $fmt, array $attStmt, TrustPath $trustPath): self
67 {
68 return new self($fmt, $attStmt, self::TYPE_NONE, $trustPath);
69 }
70
71 /**
72 * @param mixed[] $attStmt
73 */
74 public static function createBasic(string $fmt, array $attStmt, TrustPath $trustPath): self
75 {
76 return new self($fmt, $attStmt, self::TYPE_BASIC, $trustPath);
77 }
78
79 /**
80 * @param mixed[] $attStmt
81 */
82 public static function createSelf(string $fmt, array $attStmt, TrustPath $trustPath): self
83 {
84 return new self($fmt, $attStmt, self::TYPE_SELF, $trustPath);
85 }
86
87 /**
88 * @param mixed[] $attStmt
89 */
90 public static function createAttCA(string $fmt, array $attStmt, TrustPath $trustPath): self
91 {
92 return new self($fmt, $attStmt, self::TYPE_ATTCA, $trustPath);
93 }
94
95 /**
96 * @param mixed[] $attStmt
97 */
98 public static function createEcdaa(string $fmt, array $attStmt, TrustPath $trustPath): self
99 {
100 return new self($fmt, $attStmt, self::TYPE_ECDAA, $trustPath);
101 }
102
103 public static function createAnonymizationCA(string $fmt, array $attStmt, TrustPath $trustPath): self
104 {
105 return new self($fmt, $attStmt, self::TYPE_ANONCA, $trustPath);
106 }
107
108 public function getFmt(): string
109 {
110 return $this->fmt;
111 }
112
113 /**
114 * @return mixed[]
115 */
116 public function getAttStmt(): array
117 {
118 return $this->attStmt;
119 }
120
121 public function has(string $key): bool
122 {
123 return array_key_exists($key, $this->attStmt);
124 }
125
126 /**
127 * @return mixed
128 */
129 public function get(string $key)
130 {
131 Assertion::true($this->has($key), sprintf('The attestation statement has no key "%s".', $key));
132
133 return $this->attStmt[$key];
134 }
135
136 public function getTrustPath(): TrustPath
137 {
138 return $this->trustPath;
139 }
140
141 public function getType(): string
142 {
143 return $this->type;
144 }
145
146 /**
147 * @param mixed[] $data
148 */
149 public static function createFromArray(array $data): self
150 {
151 foreach (['fmt', 'attStmt', 'trustPath', 'type'] as $key) {
152 Assertion::keyExists($data, $key, sprintf('The key "%s" is missing', $key));
153 }
154
155 return new self(
156 $data['fmt'],
157 $data['attStmt'],
158 $data['type'],
159 TrustPathLoader::loadTrustPath($data['trustPath'])
160 );
161 }
162
163 /**
164 * @return mixed[]
165 */
166 public function jsonSerialize(): array
167 {
168 return [
169 'fmt' => $this->fmt,
170 'attStmt' => $this->attStmt,
171 'trustPath' => $this->trustPath->jsonSerialize(),
172 'type' => $this->type,
173 ];
174 }
175 }
176