PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 6.3.0
Defender Security – Malware Scanner, Login Security & Firewall v6.3.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 / lib / packages / Webauthn / MetadataService / MetadataTOCPayload.php

MetadataTOCPayload.php in Defender Security – Malware Scanner, Login Security & Firewall 6.3.0, at lib/packages/Webauthn/MetadataService/MetadataTOCPayload.php

143 lines 3.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 WP_DEFENDER_VENDOR\Webauthn\MetadataService;
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
21 class MetadataTOCPayload implements JsonSerializable
22 {
23 /**
24 * @var string|null
25 */
26 private $legalHeader;
27
28 /**
29 * @var int
30 */
31 private $no;
32
33 /**
34 * @var string
35 */
36 private $nextUpdate;
37
38 /**
39 * @var MetadataTOCPayloadEntry[]
40 */
41 private $entries = [];
42
43 /**
44 * @var string[]
45 */
46 private $rootCertificates;
47
48 public function __construct(int $no, string $nextUpdate, ?string $legalHeader = null)
49 {
50 $this->no = $no;
51 $this->nextUpdate = $nextUpdate;
52 $this->legalHeader = $legalHeader;
53 }
54
55 public function addEntry(MetadataTOCPayloadEntry $entry): self
56 {
57 $this->entries[] = $entry;
58
59 return $this;
60 }
61
62 public function getLegalHeader(): ?string
63 {
64 return $this->legalHeader;
65 }
66
67 public function getNo(): int
68 {
69 return $this->no;
70 }
71
72 public function getNextUpdate(): string
73 {
74 return $this->nextUpdate;
75 }
76
77 /**
78 * @return MetadataTOCPayloadEntry[]
79 */
80 public function getEntries(): array
81 {
82 return $this->entries;
83 }
84
85 public static function createFromArray(array $data): self
86 {
87 $data = Utils::filterNullValues($data);
88 foreach (['no', 'nextUpdate', 'entries'] as $key) {
89 Assertion::keyExists($data, $key, Utils::logicException(sprintf('Invalid data. The parameter "%s" is missing', $key)));
90 }
91 Assertion::integer($data['no'], Utils::logicException('Invalid data. The parameter "no" shall be an integer'));
92 Assertion::string($data['nextUpdate'], Utils::logicException('Invalid data. The parameter "nextUpdate" shall be a string'));
93 Assertion::isArray($data['entries'], Utils::logicException('Invalid data. The parameter "entries" shall be a n array of entries'));
94 if (array_key_exists('legalHeader', $data)) {
95 Assertion::string($data['legalHeader'], Utils::logicException('Invalid data. The parameter "legalHeader" shall be a string'));
96 }
97 $object = new self(
98 $data['no'],
99 $data['nextUpdate'],
100 $data['legalHeader'] ?? null
101 );
102 foreach ($data['entries'] as $k => $entry) {
103 $object->addEntry(MetadataTOCPayloadEntry::createFromArray($entry));
104 }
105 $object->rootCertificates = $data['rootCertificates'] ?? [];
106
107 return $object;
108 }
109
110 public function jsonSerialize(): array
111 {
112 $data = [
113 'legalHeader' => $this->legalHeader,
114 'nextUpdate' => $this->nextUpdate,
115 'no' => $this->no,
116 'entries' => array_map(static function (MetadataTOCPayloadEntry $object): array {
117 return $object->jsonSerialize();
118 }, $this->entries),
119 'rootCertificates' => $this->rootCertificates,
120 ];
121
122 return Utils::filterNullValues($data);
123 }
124
125 /**
126 * @return string[]
127 */
128 public function getRootCertificates(): array
129 {
130 return $this->rootCertificates;
131 }
132
133 /**
134 * @param string[] $rootCertificates
135 */
136 public function setRootCertificates(array $rootCertificates): self
137 {
138 $this->rootCertificates = $rootCertificates;
139
140 return $this;
141 }
142 }
143