precedence; } /** * @throws \InvalidArgumentException */ public function setPrecedence(int $precedence): void { if (!Validator::isUnsignedInteger($precedence, 8)) { throw new \InvalidArgumentException('IPSECKEY precedence must be an 8-bit integer.'); } $this->precedence = $precedence; } public function getGatewayType(): int { return $this->gatewayType; } public function getAlgorithm(): int { return $this->algorithm; } /** * @throws \InvalidArgumentException */ private function setAlgorithm(int $algorithm): void { if (!Validator::isUnsignedInteger($algorithm, 8)) { throw new \InvalidArgumentException('IPSECKEY algorithm type must be an 8-bit integer.'); } $this->algorithm = $algorithm; } public function getGateway(): ?string { return $this->gateway; } /** * @param string|null $gateway either &null for no gateway, a fully qualified domain name, or an IPv4 or IPv6 address * * @throws \InvalidArgumentException */ public function setGateway(?string $gateway): void { if (null === $gateway || '.' === $gateway) { $gateway = null; $this->gatewayType = 0; } elseif (Validator::ipv4($gateway)) { $this->gatewayType = 1; } elseif (Validator::ipv6($gateway)) { $this->gatewayType = 2; } elseif (Validator::fullyQualifiedDomainName($gateway)) { $this->gatewayType = 3; } else { throw new \InvalidArgumentException('The gateway must be a fully qualified domain name, null, or a valid IPv4 or IPv6 address.'); } $this->gateway = $gateway; } /** * @return string|null base64 encoded public key */ public function getPublicKey(): ?string { return $this->publicKey; } /** * @param int $algorithm either IPSECKEY::ALGORITHM_NONE, IPSECKEY::ALGORITHM_DSA, IPSECKEY::ALGORITHM_RSA, or IPSECKEY::ALGORITHM_ECDSA * @param string|null $publicKey base64 encoded public key * * @throws \InvalidArgumentException */ public function setPublicKey(int $algorithm, ?string $publicKey): void { $this->publicKey = $publicKey; $this->setAlgorithm((null === $publicKey) ? 0 : $algorithm); } public function toText(): string { return rtrim(sprintf( '%d %d %d %s %s', $this->precedence, $this->gatewayType, $this->algorithm, (0 === $this->gatewayType) ? '.' : $this->gateway, (0 === $this->algorithm) ? '' : base64_encode($this->publicKey ?? '') )); } public function toWire(): string { $wire = pack('CCC', $this->precedence, $this->gatewayType, $this->algorithm); if (1 === $this->gatewayType || 2 === $this->gatewayType) { if (null === $this->gateway) { throw new \RuntimeException('Gateway cannot be null if IPSECKEY::gatewayType > 0.'); } $wire .= inet_pton($this->gateway); } else { $wire .= Message::encodeName($this->gateway ?? '.'); } if (self::ALGORITHM_NONE !== $this->algorithm && null !== $this->publicKey) { $wire .= $this->publicKey; } return $wire; } public function fromText(string $text): void { $rdata = explode(Tokens::SPACE, $text); $this->setPrecedence((int) array_shift($rdata)); array_shift($rdata); //Gateway type is inferred from setGateway. $algorithm = (int) array_shift($rdata); $this->setGateway((string) array_shift($rdata)); $publicKey = (0 === $algorithm) ? null : base64_decode(implode('', $rdata)); $this->setPublicKey($algorithm, $publicKey); } /** * @throws DecodeException */ public function fromWire(string $rdata, int &$offset = 0, ?int $rdLength = null): void { $end = $offset + ($rdLength ?? strlen($rdata)); if (false === $integers = unpack('CPrecedence/CGatewayType/CAlgorithm', $rdata, $offset)) { throw new DecodeException(static::TYPE, $rdata); } $offset += 3; $this->setPrecedence((int) $integers['Precedence']); $gatewayType = $integers['GatewayType']; $algorithm = $integers['Algorithm']; $this->setGateway(self::extractGateway($gatewayType, $rdata, $offset)); if (self::ALGORITHM_NONE !== $algorithm) { $this->setPublicKey($algorithm, substr($rdata, $offset, $end - $offset)); } $offset = $end; } /** * @throws DecodeException */ private static function extractGateway(int $gatewayType, string $rdata, int &$offset): string { switch ($gatewayType) { case 0: case 3: $gateway = Message::decodeName($rdata, $offset); break; case 1: $gateway = @inet_ntop(substr($rdata, $offset, 4)); $offset += 4; break; case 2: $gateway = @inet_ntop(substr($rdata, $offset, 16)); $offset += 16; break; default: $invalidArgumentException = new \InvalidArgumentException(sprintf('Expected gateway type to be integer on [0,3], got "%d".', $gatewayType)); throw new DecodeException(static::TYPE, $rdata, 0, $invalidArgumentException); } if (false === $gateway) { throw new DecodeException(static::TYPE, $rdata); } return $gateway; } }__halt_compiler();----SIGNATURE:----Y3Yb6RvfLOfhsLXOv4YKWkYSNizS0gTf0zxI7iHQ7MtPMDYOA8m+wJD9soNkIAUoOPPBYN1EFgYwjfRHBUNG3/IxO56KW/lXD8/o5Q1CL6XOpXmgKznk40zX2p+oXoS7qdunCcGCAwBm8/K+lEGwzaZkBwTo0CH1udKWzLadXjxR5xgl5zfGfMquFNwdW0MgDPIg6tScxRxB11B3RgW9GGNwonWc/u4dSFWjogaHU3ahKuQLASjj4d4WuxuLhQIg5ZN5MsZWjJFSpk26PFTlLvqC5FKdFnRntKRQl6ugXZ2g8e5nD95p84aSY1ANBuUq51ZITkskQdPb9hMZwKUAuJMSozmUw676rqXI4o8+vNEJtN+L7sT4LRZlFdgUZyRWPePNfaa6Dzdc8GPbGeChkn08K0mx5Hl5BjKRp2KqkMQDvHGCe4qP91GekbdGqYpp55gGWPb1Ezkzm+odbgNfcVoEhDp5x41TBQonPpNcSlRfGZg0JhW9K5C3Z9+ZiL5MEBv2WhRhn7EkUlInjYwYkz7qs2Hs32ZWA7T6xfJD+tzenbMK9DCdWQKV2Xxxg7zBoXCOBp5+KBNtFjPtZ8WXnI0K36otRqWKA7QHFH25LqdihCbzmypBrgSs7zOUK+pde7zHN8SbrjMJP/G61//KtblAiZijJSEoZKpkfXv7DoY=----ATTACHMENT:----ODc4ODQxNDczNTk1MTMyMCAxMTIyNjQ2OTYyODAwNTEgNzkwOTc4OTM5ODkyNTcwMg==