asOctetString() ->string(); return match (mb_strlen($octets, '8bit')) { 4, 8 => IPv4Address::fromOctets($octets), 16, 32 => IPv6Address::fromOctets($octets), default => throw new UnexpectedValueException('Invalid octet length for IP address.'), }; } public function string(): string { return $this->ip . (isset($this->mask) ? '/' . $this->mask : ''); } /** * Get IP address as a string. */ public function address(): string { return $this->ip; } /** * Check whether mask is present. */ public function hasMask(): bool { return isset($this->mask); } /** * Get subnet mask as a string. */ public function mask(): string { if (! $this->hasMask()) { throw new LogicException('mask is not set.'); } return $this->mask; } /** * Get octet representation of the IP address. */ abstract protected function octets(): string; protected function choiceASN1(): TaggedType { return ImplicitlyTaggedType::create($this->tag, OctetString::create($this->octets())); } }