PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 6.1.0
Defender Security – Malware Scanner, Login Security & Firewall v6.1.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 / metadata-service / src / MetadataTOCPayloadEntry.php

MetadataTOCPayloadEntry.php in Defender Security – Malware Scanner, Login Security & Firewall 6.1.0, at vendor/web-auth/metadata-service/src/MetadataTOCPayloadEntry.php

189 lines 5.5 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\MetadataService;
15
16 use Assert\Assertion;
17 use Base64Url\Base64Url;
18 use function count;
19 use JsonSerializable;
20 use LogicException;
21
22 class MetadataTOCPayloadEntry implements JsonSerializable
23 {
24 /**
25 * @var string|null
26 */
27 private $aaid;
28
29 /**
30 * @var string|null
31 */
32 private $aaguid;
33
34 /**
35 * @var string[]
36 */
37 private $attestationCertificateKeyIdentifiers = [];
38
39 /**
40 * @var string|null
41 */
42 private $hash;
43
44 /**
45 * @var string|null
46 */
47 private $url;
48
49 /**
50 * @var StatusReport[]
51 */
52 private $statusReports = [];
53
54 /**
55 * @var string
56 */
57 private $timeOfLastStatusChange;
58
59 /**
60 * @var string
61 */
62 private $rogueListURL;
63
64 /**
65 * @var string
66 */
67 private $rogueListHash;
68
69 public function __construct(?string $aaid, ?string $aaguid, array $attestationCertificateKeyIdentifiers, ?string $hash, ?string $url, string $timeOfLastStatusChange, ?string $rogueListURL, ?string $rogueListHash)
70 {
71 if (null !== $aaid && null !== $aaguid) {
72 throw new LogicException('Authenticators cannot support both AAID and AAGUID');
73 }
74 if (null === $aaid && null === $aaguid && 0 === count($attestationCertificateKeyIdentifiers)) {
75 throw new LogicException('If neither AAID nor AAGUID are set, the attestation certificate identifier list shall not be empty');
76 }
77 foreach ($attestationCertificateKeyIdentifiers as $attestationCertificateKeyIdentifier) {
78 Assertion::string($attestationCertificateKeyIdentifier, Utils::logicException('Invalid attestation certificate identifier. Shall be a list of strings'));
79 Assertion::notEmpty($attestationCertificateKeyIdentifier, Utils::logicException('Invalid attestation certificate identifier. Shall be a list of strings'));
80 Assertion::regex($attestationCertificateKeyIdentifier, '/^[0-9a-f]+$/', Utils::logicException('Invalid attestation certificate identifier. Shall be a list of strings'));
81 }
82 $this->aaid = $aaid;
83 $this->aaguid = $aaguid;
84 $this->attestationCertificateKeyIdentifiers = $attestationCertificateKeyIdentifiers;
85 $this->hash = Base64Url::decode($hash);
86 $this->url = $url;
87 $this->timeOfLastStatusChange = $timeOfLastStatusChange;
88 $this->rogueListURL = $rogueListURL;
89 $this->rogueListHash = $rogueListHash;
90 }
91
92 public function getAaid(): ?string
93 {
94 return $this->aaid;
95 }
96
97 public function getAaguid(): ?string
98 {
99 return $this->aaguid;
100 }
101
102 public function getAttestationCertificateKeyIdentifiers(): array
103 {
104 return $this->attestationCertificateKeyIdentifiers;
105 }
106
107 public function getHash(): ?string
108 {
109 return $this->hash;
110 }
111
112 public function getUrl(): ?string
113 {
114 return $this->url;
115 }
116
117 public function addStatusReports(StatusReport $statusReport): self
118 {
119 $this->statusReports[] = $statusReport;
120
121 return $this;
122 }
123
124 /**
125 * @return StatusReport[]
126 */
127 public function getStatusReports(): array
128 {
129 return $this->statusReports;
130 }
131
132 public function getTimeOfLastStatusChange(): string
133 {
134 return $this->timeOfLastStatusChange;
135 }
136
137 public function getRogueListURL(): string
138 {
139 return $this->rogueListURL;
140 }
141
142 public function getRogueListHash(): string
143 {
144 return $this->rogueListHash;
145 }
146
147 public static function createFromArray(array $data): self
148 {
149 $data = Utils::filterNullValues($data);
150 Assertion::keyExists($data, 'timeOfLastStatusChange', Utils::logicException('Invalid data. The parameter "timeOfLastStatusChange" is missing'));
151 Assertion::keyExists($data, 'statusReports', Utils::logicException('Invalid data. The parameter "statusReports" is missing'));
152 Assertion::isArray($data['statusReports'], Utils::logicException('Invalid data. The parameter "statusReports" shall be an array of StatusReport objects'));
153 $object = new self(
154 $data['aaid'] ?? null,
155 $data['aaguid'] ?? null,
156 $data['attestationCertificateKeyIdentifiers'] ?? [],
157 $data['hash'] ?? null,
158 $data['url'] ?? null,
159 $data['timeOfLastStatusChange'],
160 $data['rogueListURL'] ?? null,
161 $data['rogueListHash'] ?? null
162 );
163 foreach ($data['statusReports'] as $statusReport) {
164 $object->addStatusReports(StatusReport::createFromArray($statusReport));
165 }
166
167 return $object;
168 }
169
170 public function jsonSerialize(): array
171 {
172 $data = [
173 'aaid' => $this->aaid,
174 'aaguid' => $this->aaguid,
175 'attestationCertificateKeyIdentifiers' => $this->attestationCertificateKeyIdentifiers,
176 'hash' => Base64Url::encode($this->hash),
177 'url' => $this->url,
178 'statusReports' => array_map(static function (StatusReport $object): array {
179 return $object->jsonSerialize();
180 }, $this->statusReports),
181 'timeOfLastStatusChange' => $this->timeOfLastStatusChange,
182 'rogueListURL' => $this->rogueListURL,
183 'rogueListHash' => $this->rogueListHash,
184 ];
185
186 return Utils::filterNullValues($data);
187 }
188 }
189