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:----kkTmlW3YOK98WXHERwJhuvqcxXjuwt+VICDIKUkwiCZnXkgLE8Wwxpu0m7i+jOXX2SgR1K/hmDPl4pBU8TpNwg0SIMrolN3TbVBCz5q/HRVQXEzdiOYfsLbr6zwz5wfhPrUlWY+fkVH14FLU42GACzikRtn7+n5h8Q+biP64f70nXDmE1cemppuRqJz+k7xlHyrhl5L8qiIr/EwM+NC9xc/Gq5X+41wl0qhaQz5ThOzaVL6U2uPgcMoTA/SPOJIcS3P+Wp/+lxNoU5ifFXCno41FZj5nsfkbyqWkj3ghWSxMijUhBwkhbJuNceKIel+vEtln7JkNnn11dx+28hPWcCVu//+lqf6pBTJNLlmBIY3fruUVZZYpwUngzsIVls+Y07B3I+xptBtNZim+Vhrp0d4YP4kE2V8U6c2mJCnvBMfgnjRUOBGTxCzI5h7ksJoj0758FMaCFW8e75Mm6C/WN16lWMq1gvjlCQqZ+XFB6vo7I+pISLZpIQoYs1Fqy3TaP4WwUrSiLiRbS7WgHNYfQmBfSGgY8F405xK8ulDVSRyWNH9k9WkuENx5utIuy5TtnApbOs9IWnxhBWQb+TISC5LFSQnmsA9QSu0WgLw5ZrcbrafKLJ1+yVjjvPSm7HUcvSUf6+EaMAhMTz/LXwVWJvlGIiDETlHX9bTqWfWLph4=----ATTACHMENT:----NDQ3MTQ1MTY1NzMwMDMyMyA0OTQwODg0NTEyNTExNDMgOTUxNDU1ODg2Mzk5MzIwOQ==