1 | <?php |
||
27 | class NSEC3 implements RdataInterface |
||
28 | { |
||
29 | 1 | use RdataTrait; |
|
30 | |||
31 | const TYPE = 'NSEC3'; |
||
32 | const TYPE_CODE = 50; |
||
33 | |||
34 | /** |
||
35 | * {@link https://www.iana.org/assignments/dnssec-nsec3-parameters/dnssec-nsec3-parameters.xhtml}. |
||
36 | * |
||
37 | * @var int the Hash Algorithm field identifies the cryptographic hash algorithm used to construct the hash-value |
||
38 | */ |
||
39 | private $hashAlgorithm = 1; |
||
40 | |||
41 | /** |
||
42 | * @var bool |
||
43 | */ |
||
44 | private $unsignedDelegationsCovered = false; |
||
45 | |||
46 | /** |
||
47 | * @var int |
||
48 | */ |
||
49 | private $iterations; |
||
50 | |||
51 | /** |
||
52 | * @var string Binary encoded string |
||
53 | */ |
||
54 | private $salt; |
||
55 | |||
56 | /** |
||
57 | * @var string fully qualified next owner name |
||
58 | */ |
||
59 | private $nextOwnerName; |
||
60 | |||
61 | /** |
||
62 | * @var string Binary encoded hash |
||
63 | */ |
||
64 | private $nextHashedOwnerName; |
||
65 | |||
66 | /** |
||
67 | * @var array |
||
68 | */ |
||
69 | private $types = []; |
||
70 | |||
71 | public function getHashAlgorithm(): int |
||
75 | |||
76 | /** |
||
77 | * @throws InvalidArgumentException |
||
78 | */ |
||
79 | 8 | public function setHashAlgorithm(int $hashAlgorithm): void |
|
86 | |||
87 | public function isUnsignedDelegationsCovered(): bool |
||
91 | |||
92 | public function setUnsignedDelegationsCovered(bool $unsignedDelegationsCovered): void |
||
96 | 4 | ||
97 | public function getIterations(): int |
||
101 | 4 | ||
102 | 4 | /** |
|
103 | * @throws InvalidArgumentException |
||
104 | 2 | */ |
|
105 | public function setIterations(int $iterations): void |
||
112 | 8 | ||
113 | /** |
||
114 | 2 | * @return string Base16 string |
|
115 | */ |
||
116 | 2 | public function getSalt(): string |
|
120 | |||
121 | /** |
||
122 | 8 | * @param string $salt Hexadecimal string |
|
123 | */ |
||
124 | 8 | public function setSalt(string $salt): void |
|
131 | |||
132 | public function getNextOwnerName(): string |
||
136 | |||
137 | /** |
||
138 | * Set the next owner name. |
||
139 | * |
||
140 | * @param string $nextOwnerName the fully qualified next owner name |
||
141 | 8 | * |
|
142 | * @throws InvalidArgumentException |
||
143 | 8 | */ |
|
144 | public function setNextOwnerName(string $nextOwnerName): void |
||
151 | |||
152 | public function getNextHashedOwnerName(): string |
||
156 | |||
157 | public function setNextHashedOwnerName(string $nextHashedOwnerName): void |
||
161 | 4 | ||
162 | public function addType(string $type): void |
||
166 | 4 | ||
167 | 4 | public function setTypes(array $types): void |
|
171 | 6 | ||
172 | /** |
||
173 | * Clears the types from the RDATA. |
||
174 | 4 | */ |
|
175 | public function clearTypes(): void |
||
179 | 4 | ||
180 | public function getTypes(): array |
||
184 | 6 | ||
185 | public function toText(): string |
||
196 | |||
197 | 2 | /** |
|
198 | * @throws UnsupportedTypeException |
||
199 | 2 | */ |
|
200 | public function toWire(): string |
||
215 | |||
216 | public function fromText(string $text): void |
||
230 | 2 | ||
231 | /** |
||
232 | * @throws UnsupportedTypeException|DecodeException |
||
233 | 2 | */ |
|
234 | public function fromWire(string $rdata, int &$offset = 0, ?int $rdLength = null): void |
||
260 | 2 | ||
261 | 2 | /** |
|
262 | 2 | * Calculate and set NSEC3::nextOwnerHash. Requires NSEC3::salt, NSEC3::nextOwnerName, and NSEC3::iterations to be set. |
|
263 | * |
||
264 | 2 | * @throws InvalidArgumentException |
|
265 | 2 | */ |
|
266 | 2 | public function calculateNextOwnerHash(): void |
|
274 | |||
275 | /** |
||
276 | * @param string $salt the salt |
||
277 | * @param string $x the value to be hashed |
||
278 | * @param int $k the number of recursive iterations of the hash function |
||
279 | 4 | * |
|
280 | * @return string the hashed value |
||
281 | 4 | * |
|
282 | * @throws DomainException |
||
283 | */ |
||
284 | private static function hash(string $salt, string $x, int $k = 0): string |
||
297 | } |
||
298 |