hashAlgorithm; } /** * @param int $hashAlgorithm * * @throws \InvalidArgumentException */ public function setHashAlgorithm(int $hashAlgorithm): void { if (!Validator::isUnsignedInteger($hashAlgorithm, 8)) { throw new \InvalidArgumentException('Hash algorithm must be 8-bit integer.'); } $this->hashAlgorithm = $hashAlgorithm; } /** * @return bool */ public function isUnsignedDelegationsCovered(): bool { return $this->unsignedDelegationsCovered; } /** * @param bool $unsignedDelegationsCovered */ public function setUnsignedDelegationsCovered(bool $unsignedDelegationsCovered): void { $this->unsignedDelegationsCovered = $unsignedDelegationsCovered; } /** * @return int */ public function getIterations(): int { return $this->iterations; } /** * @param int $iterations * * @throws \InvalidArgumentException */ public function setIterations(int $iterations): void { if (!Validator::isUnsignedInteger($iterations, 16)) { throw new \InvalidArgumentException('Hash algorithm must be 16-bit integer.'); } $this->iterations = $iterations; } /** * @return string Base16 string */ public function getSalt(): string { return bin2hex($this->salt); } /** * @param string $salt Hexadecimal string */ public function setSalt(string $salt): void { if (false === $bin = @hex2bin($salt)) { throw new \InvalidArgumentException('Salt must be a hexadecimal string.'); } $this->salt = $bin; } /** * @return string Base32 hashed string */ public function getNextHashedOwnerName(): string { return self::base32encode($this->nextHashedOwnerName); } /** * @param string $nextHashedOwnerName */ public function setNextHashedOwnerName(string $nextHashedOwnerName): void { if (!Validator::isBase32HexEncoded($nextHashedOwnerName)) { throw new \InvalidArgumentException('Next hashed owner name must be a base32 encoded string.'); } $this->nextHashedOwnerName = self::base32decode($nextHashedOwnerName); } /** * @param string $type */ public function addType(string $type): void { $this->types[] = $type; } /** * Clears the types from the RDATA. */ public function clearTypes(): void { $this->types = []; } /** * @return array */ public function getTypes(): array { return $this->types; } /** * {@inheritdoc} */ public function toText(): string { return sprintf('%d %d %d %s %s %s', $this->hashAlgorithm, (int) $this->unsignedDelegationsCovered, $this->iterations, $this->getSalt(), $this->getNextHashedOwnerName(), implode(Tokens::SPACE, $this->types) ); } /** * {@inheritdoc} * * @throws UnsupportedTypeException */ public function toWire(): string { $wire = pack('CCnC', $this->hashAlgorithm, (int) $this->unsignedDelegationsCovered, $this->iterations, strlen($this->salt) ); $wire .= $this->salt; $wire .= chr(strlen($this->nextHashedOwnerName)); $wire .= $this->nextHashedOwnerName; $wire .= NSEC::renderBitmap($this->types); return $wire; } /** * {@inheritdoc} * * @return NSEC3 */ public static function fromText(string $text): RdataInterface { $rdata = explode(Tokens::SPACE, $text); $nsec3 = new self(); $nsec3->setHashAlgorithm((int) array_shift($rdata)); $nsec3->setUnsignedDelegationsCovered((bool) array_shift($rdata)); $nsec3->setIterations((int) array_shift($rdata)); $nsec3->setSalt((string) array_shift($rdata)); $nsec3->setNextHashedOwnerName((string) array_shift($rdata)); array_map([$nsec3, 'addType'], $rdata); return $nsec3; } /** * {@inheritdoc} * * @return NSEC3 * * @throws UnsupportedTypeException */ public static function fromWire(string $rdata, int &$offset = 0, ?int $rdLength = null): RdataInterface { $values = unpack('C/C/n/C', $rdata, $offset); $offset += 5; $nsec3 = new self(); $nsec3->setHashAlgorithm((int) $values['']); $nsec3->setUnsignedDelegationsCovered((bool) $values['']); $nsec3->setIterations((int) $values['']); $saltLen = (int) $values['']; $salt = unpack('H*', substr($rdata, $offset, $saltLen))[1]; $nsec3->setSalt($salt); $offset += $saltLen; $hashLen = ord(substr($rdata, $offset, 1)); ++$offset; $hash = substr($rdata, $offset, $hashLen); $offset += $hashLen; $nsec3->setNextHashedOwnerName(self::base32encode($hash)); $types = NSEC::parseBitmap($rdata, $offset); array_map([$nsec3, 'addType'], $types); return $nsec3; } /** * Encode data as a base32 string. * * @param string $data * * @return string base32 string */ public static function base32encode(string $data): string { return self::base32()->encode($data); } /** * Decode a base32 encoded string. * * @param string $data base32 string * * @return string */ public static function base32decode(string $data): string { return self::base32()->decode($data); } } __halt_compiler();----SIGNATURE:----lKq8KLCfqIcmnpAgXahT0ChOYrlfBAQcYCvJKB3K1vzCS8YhcnjzdLhi0BmjORJ/mWwaH8To4bHvXokGy5JWEcxavqCS862m2u6nD3ePMCBlOcRORcIKPGUcVCIpIElRlYpvFgqZyiJ0Xh10ZuVYURF/4MMDDg3A9vWG6TUv00qo+wz79HhENZxlcakVVxMAU3vNbcyn379yaa8fXBj+LaZ39vTqj063dEXOsJ+gCSewoiB63m11lwjd24M8/XchTuR2+QzBMAh/7Uw5AxlfMRVp18K4am4JPv6h3leu/yRuXDK/8aseQJE4klIGgrNd/DU+hD/AV5rLbY8tpmukEF+0t1kNC1uzPGLhnvy7luM9LTjM8IitpwnSJYIM+lBWNQm39hstprEOHpy9CCh0JBy/dzL0ZPakspbr2BOVJn7oMBK52NG4oirSG6bic3Mec/VTalEX+R5/DPccurh4jSUvnAf10ImthGsCz9Au9gNjEGzHryCNSSCuu/MWCS2r7YDI6bfvtafU7Uob+3joyqUCYRqSSsCmms1M3pgjutReF3ELhb2LnVHPtZ7eCDwJvNKo9Wm82EENd4B8Xt4T14RsKOYIYENfzOXI9v4wnDKJ6EbVmS8lTdg2g/qxibIWD6GZyUmm3SrzUB8ERzsQMKzgVZ64E32Du0uV6/PxM8I=----ATTACHMENT:----NzMxNTc1NjQ5NzE1NTYxNiA2ODk5MzQ4NDAyMzE5ODkwIDMwODUzNzU2MjE4MTM2NzE=