@@ -16,15 +16,15 @@ |
||
| 16 | 16 | $mask = null; |
| 17 | 17 | $bytes = unpack("C*", $octets); |
| 18 | 18 | switch (count($bytes)) { |
| 19 | - case 4: |
|
| 20 | - $ip = implode(".", $bytes); |
|
| 21 | - break; |
|
| 22 | - case 8: |
|
| 23 | - $ip = implode(".", array_slice($bytes, 0, 4)); |
|
| 24 | - $mask = implode(".", array_slice($bytes, 4, 4)); |
|
| 25 | - break; |
|
| 26 | - default: |
|
| 27 | - throw new \UnexpectedValueException("Invalid IPv4 octet length."); |
|
| 19 | + case 4: |
|
| 20 | + $ip = implode(".", $bytes); |
|
| 21 | + break; |
|
| 22 | + case 8: |
|
| 23 | + $ip = implode(".", array_slice($bytes, 0, 4)); |
|
| 24 | + $mask = implode(".", array_slice($bytes, 4, 4)); |
|
| 25 | + break; |
|
| 26 | + default: |
|
| 27 | + throw new \UnexpectedValueException("Invalid IPv4 octet length."); |
|
| 28 | 28 | } |
| 29 | 29 | return new self($ip, $mask); |
| 30 | 30 | } |
@@ -6,42 +6,42 @@ |
||
| 6 | 6 | |
| 7 | 7 | class IPv4Address extends IPAddress |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * Initialize from octets. |
|
| 11 | - * |
|
| 12 | - * @param string $octets |
|
| 13 | - * @throws \InvalidArgumentException |
|
| 14 | - * @return self |
|
| 15 | - */ |
|
| 16 | - public static function fromOctets(string $octets) |
|
| 17 | - { |
|
| 18 | - $mask = null; |
|
| 19 | - $bytes = unpack("C*", $octets); |
|
| 20 | - switch (count($bytes)) { |
|
| 21 | - case 4: |
|
| 22 | - $ip = implode(".", $bytes); |
|
| 23 | - break; |
|
| 24 | - case 8: |
|
| 25 | - $ip = implode(".", array_slice($bytes, 0, 4)); |
|
| 26 | - $mask = implode(".", array_slice($bytes, 4, 4)); |
|
| 27 | - break; |
|
| 28 | - default: |
|
| 29 | - throw new \UnexpectedValueException("Invalid IPv4 octet length."); |
|
| 30 | - } |
|
| 31 | - return new self($ip, $mask); |
|
| 32 | - } |
|
| 9 | + /** |
|
| 10 | + * Initialize from octets. |
|
| 11 | + * |
|
| 12 | + * @param string $octets |
|
| 13 | + * @throws \InvalidArgumentException |
|
| 14 | + * @return self |
|
| 15 | + */ |
|
| 16 | + public static function fromOctets(string $octets) |
|
| 17 | + { |
|
| 18 | + $mask = null; |
|
| 19 | + $bytes = unpack("C*", $octets); |
|
| 20 | + switch (count($bytes)) { |
|
| 21 | + case 4: |
|
| 22 | + $ip = implode(".", $bytes); |
|
| 23 | + break; |
|
| 24 | + case 8: |
|
| 25 | + $ip = implode(".", array_slice($bytes, 0, 4)); |
|
| 26 | + $mask = implode(".", array_slice($bytes, 4, 4)); |
|
| 27 | + break; |
|
| 28 | + default: |
|
| 29 | + throw new \UnexpectedValueException("Invalid IPv4 octet length."); |
|
| 30 | + } |
|
| 31 | + return new self($ip, $mask); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * |
|
| 36 | - * {@inheritdoc} |
|
| 37 | - */ |
|
| 38 | - protected function _octets(): string |
|
| 39 | - { |
|
| 40 | - $bytes = array_map("intval", explode(".", $this->_ip)); |
|
| 41 | - if (isset($this->_mask)) { |
|
| 42 | - $bytes = array_merge($bytes, |
|
| 43 | - array_map("intval", explode(".", $this->_mask))); |
|
| 44 | - } |
|
| 45 | - return pack("C*", ...$bytes); |
|
| 46 | - } |
|
| 34 | + /** |
|
| 35 | + * |
|
| 36 | + * {@inheritdoc} |
|
| 37 | + */ |
|
| 38 | + protected function _octets(): string |
|
| 39 | + { |
|
| 40 | + $bytes = array_map("intval", explode(".", $this->_ip)); |
|
| 41 | + if (isset($this->_mask)) { |
|
| 42 | + $bytes = array_merge($bytes, |
|
| 43 | + array_map("intval", explode(".", $this->_mask))); |
|
| 44 | + } |
|
| 45 | + return pack("C*", ...$bytes); |
|
| 46 | + } |
|
| 47 | 47 | } |
@@ -59,15 +59,15 @@ |
||
| 59 | 59 | { |
| 60 | 60 | $octets = $el->asOctetString()->string(); |
| 61 | 61 | switch (strlen($octets)) { |
| 62 | - case 4: |
|
| 63 | - case 8: |
|
| 64 | - return IPv4Address::fromOctets($octets); |
|
| 65 | - case 16: |
|
| 66 | - case 32: |
|
| 67 | - return IPv6Address::fromOctets($octets); |
|
| 68 | - default: |
|
| 69 | - throw new \UnexpectedValueException( |
|
| 70 | - "Invalid octet length for IP address."); |
|
| 62 | + case 4: |
|
| 63 | + case 8: |
|
| 64 | + return IPv4Address::fromOctets($octets); |
|
| 65 | + case 16: |
|
| 66 | + case 32: |
|
| 67 | + return IPv6Address::fromOctets($octets); |
|
| 68 | + default: |
|
| 69 | + throw new \UnexpectedValueException( |
|
| 70 | + "Invalid octet length for IP address."); |
|
| 71 | 71 | } |
| 72 | 72 | } |
| 73 | 73 | |
@@ -18,97 +18,97 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | abstract class IPAddress extends GeneralName |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * IP address. |
|
| 23 | - * |
|
| 24 | - * @var string $_ip |
|
| 25 | - */ |
|
| 26 | - protected $_ip; |
|
| 21 | + /** |
|
| 22 | + * IP address. |
|
| 23 | + * |
|
| 24 | + * @var string $_ip |
|
| 25 | + */ |
|
| 26 | + protected $_ip; |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * Subnet mask. |
|
| 30 | - * |
|
| 31 | - * @var string|null $_mask |
|
| 32 | - */ |
|
| 33 | - protected $_mask; |
|
| 28 | + /** |
|
| 29 | + * Subnet mask. |
|
| 30 | + * |
|
| 31 | + * @var string|null $_mask |
|
| 32 | + */ |
|
| 33 | + protected $_mask; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Get octet representation of the IP address. |
|
| 37 | - * |
|
| 38 | - * @return string |
|
| 39 | - */ |
|
| 40 | - abstract protected function _octets(); |
|
| 35 | + /** |
|
| 36 | + * Get octet representation of the IP address. |
|
| 37 | + * |
|
| 38 | + * @return string |
|
| 39 | + */ |
|
| 40 | + abstract protected function _octets(); |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Constructor. |
|
| 44 | - * |
|
| 45 | - * @param string $ip |
|
| 46 | - * @param string|null $mask |
|
| 47 | - */ |
|
| 48 | - public function __construct(string $ip, $mask = null) |
|
| 49 | - { |
|
| 50 | - $this->_tag = self::TAG_IP_ADDRESS; |
|
| 51 | - $this->_ip = $ip; |
|
| 52 | - $this->_mask = $mask; |
|
| 53 | - } |
|
| 42 | + /** |
|
| 43 | + * Constructor. |
|
| 44 | + * |
|
| 45 | + * @param string $ip |
|
| 46 | + * @param string|null $mask |
|
| 47 | + */ |
|
| 48 | + public function __construct(string $ip, $mask = null) |
|
| 49 | + { |
|
| 50 | + $this->_tag = self::TAG_IP_ADDRESS; |
|
| 51 | + $this->_ip = $ip; |
|
| 52 | + $this->_mask = $mask; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * |
|
| 57 | - * @param UnspecifiedType $el |
|
| 58 | - * @return self |
|
| 59 | - */ |
|
| 60 | - public static function fromChosenASN1(UnspecifiedType $el) |
|
| 61 | - { |
|
| 62 | - $octets = $el->asOctetString()->string(); |
|
| 63 | - switch (strlen($octets)) { |
|
| 64 | - case 4: |
|
| 65 | - case 8: |
|
| 66 | - return IPv4Address::fromOctets($octets); |
|
| 67 | - case 16: |
|
| 68 | - case 32: |
|
| 69 | - return IPv6Address::fromOctets($octets); |
|
| 70 | - default: |
|
| 71 | - throw new \UnexpectedValueException( |
|
| 72 | - "Invalid octet length for IP address."); |
|
| 73 | - } |
|
| 74 | - } |
|
| 55 | + /** |
|
| 56 | + * |
|
| 57 | + * @param UnspecifiedType $el |
|
| 58 | + * @return self |
|
| 59 | + */ |
|
| 60 | + public static function fromChosenASN1(UnspecifiedType $el) |
|
| 61 | + { |
|
| 62 | + $octets = $el->asOctetString()->string(); |
|
| 63 | + switch (strlen($octets)) { |
|
| 64 | + case 4: |
|
| 65 | + case 8: |
|
| 66 | + return IPv4Address::fromOctets($octets); |
|
| 67 | + case 16: |
|
| 68 | + case 32: |
|
| 69 | + return IPv6Address::fromOctets($octets); |
|
| 70 | + default: |
|
| 71 | + throw new \UnexpectedValueException( |
|
| 72 | + "Invalid octet length for IP address."); |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * |
|
| 78 | - * {@inheritdoc} |
|
| 79 | - */ |
|
| 80 | - public function string(): string |
|
| 81 | - { |
|
| 82 | - return $this->_ip . (isset($this->_mask) ? "/" . $this->_mask : ""); |
|
| 83 | - } |
|
| 76 | + /** |
|
| 77 | + * |
|
| 78 | + * {@inheritdoc} |
|
| 79 | + */ |
|
| 80 | + public function string(): string |
|
| 81 | + { |
|
| 82 | + return $this->_ip . (isset($this->_mask) ? "/" . $this->_mask : ""); |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * Get IP address as a string. |
|
| 87 | - * |
|
| 88 | - * @return string |
|
| 89 | - */ |
|
| 90 | - public function address(): string |
|
| 91 | - { |
|
| 92 | - return $this->_ip; |
|
| 93 | - } |
|
| 85 | + /** |
|
| 86 | + * Get IP address as a string. |
|
| 87 | + * |
|
| 88 | + * @return string |
|
| 89 | + */ |
|
| 90 | + public function address(): string |
|
| 91 | + { |
|
| 92 | + return $this->_ip; |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * Get subnet mask as a string. |
|
| 97 | - * |
|
| 98 | - * @return string |
|
| 99 | - */ |
|
| 100 | - public function mask(): string |
|
| 101 | - { |
|
| 102 | - return $this->_mask; |
|
| 103 | - } |
|
| 95 | + /** |
|
| 96 | + * Get subnet mask as a string. |
|
| 97 | + * |
|
| 98 | + * @return string |
|
| 99 | + */ |
|
| 100 | + public function mask(): string |
|
| 101 | + { |
|
| 102 | + return $this->_mask; |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * |
|
| 107 | - * {@inheritdoc} |
|
| 108 | - */ |
|
| 109 | - protected function _choiceASN1() |
|
| 110 | - { |
|
| 111 | - return new ImplicitlyTaggedType($this->_tag, |
|
| 112 | - new OctetString($this->_octets())); |
|
| 113 | - } |
|
| 105 | + /** |
|
| 106 | + * |
|
| 107 | + * {@inheritdoc} |
|
| 108 | + */ |
|
| 109 | + protected function _choiceASN1() |
|
| 110 | + { |
|
| 111 | + return new ImplicitlyTaggedType($this->_tag, |
|
| 112 | + new OctetString($this->_octets())); |
|
| 113 | + } |
|
| 114 | 114 | } |
@@ -16,15 +16,15 @@ |
||
| 16 | 16 | $mask = null; |
| 17 | 17 | $words = unpack("n*", $octets); |
| 18 | 18 | switch (count($words)) { |
| 19 | - case 8: |
|
| 20 | - $ip = self::_wordsToIPv6String($words); |
|
| 21 | - break; |
|
| 22 | - case 16: |
|
| 23 | - $ip = self::_wordsToIPv6String(array_slice($words, 0, 8)); |
|
| 24 | - $mask = self::_wordsToIPv6String(array_slice($words, 8, 8)); |
|
| 25 | - break; |
|
| 26 | - default: |
|
| 27 | - throw new \UnexpectedValueException("Invalid IPv6 octet length."); |
|
| 19 | + case 8: |
|
| 20 | + $ip = self::_wordsToIPv6String($words); |
|
| 21 | + break; |
|
| 22 | + case 16: |
|
| 23 | + $ip = self::_wordsToIPv6String(array_slice($words, 0, 8)); |
|
| 24 | + $mask = self::_wordsToIPv6String(array_slice($words, 8, 8)); |
|
| 25 | + break; |
|
| 26 | + default: |
|
| 27 | + throw new \UnexpectedValueException("Invalid IPv6 octet length."); |
|
| 28 | 28 | } |
| 29 | 29 | return new self($ip, $mask); |
| 30 | 30 | } |
@@ -6,57 +6,57 @@ |
||
| 6 | 6 | |
| 7 | 7 | class IPv6Address extends IPAddress |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * Initialize from octets. |
|
| 11 | - * |
|
| 12 | - * @param string $octets |
|
| 13 | - * @throws \InvalidArgumentException |
|
| 14 | - * @return self |
|
| 15 | - */ |
|
| 16 | - public static function fromOctets(string $octets) |
|
| 17 | - { |
|
| 18 | - $mask = null; |
|
| 19 | - $words = unpack("n*", $octets); |
|
| 20 | - switch (count($words)) { |
|
| 21 | - case 8: |
|
| 22 | - $ip = self::_wordsToIPv6String($words); |
|
| 23 | - break; |
|
| 24 | - case 16: |
|
| 25 | - $ip = self::_wordsToIPv6String(array_slice($words, 0, 8)); |
|
| 26 | - $mask = self::_wordsToIPv6String(array_slice($words, 8, 8)); |
|
| 27 | - break; |
|
| 28 | - default: |
|
| 29 | - throw new \UnexpectedValueException("Invalid IPv6 octet length."); |
|
| 30 | - } |
|
| 31 | - return new self($ip, $mask); |
|
| 32 | - } |
|
| 9 | + /** |
|
| 10 | + * Initialize from octets. |
|
| 11 | + * |
|
| 12 | + * @param string $octets |
|
| 13 | + * @throws \InvalidArgumentException |
|
| 14 | + * @return self |
|
| 15 | + */ |
|
| 16 | + public static function fromOctets(string $octets) |
|
| 17 | + { |
|
| 18 | + $mask = null; |
|
| 19 | + $words = unpack("n*", $octets); |
|
| 20 | + switch (count($words)) { |
|
| 21 | + case 8: |
|
| 22 | + $ip = self::_wordsToIPv6String($words); |
|
| 23 | + break; |
|
| 24 | + case 16: |
|
| 25 | + $ip = self::_wordsToIPv6String(array_slice($words, 0, 8)); |
|
| 26 | + $mask = self::_wordsToIPv6String(array_slice($words, 8, 8)); |
|
| 27 | + break; |
|
| 28 | + default: |
|
| 29 | + throw new \UnexpectedValueException("Invalid IPv6 octet length."); |
|
| 30 | + } |
|
| 31 | + return new self($ip, $mask); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Convert an array of 16 bit words to an IPv6 string representation. |
|
| 36 | - * |
|
| 37 | - * @param int[] $words |
|
| 38 | - * @return string |
|
| 39 | - */ |
|
| 40 | - protected static function _wordsToIPv6String(array $words): string |
|
| 41 | - { |
|
| 42 | - $groups = array_map( |
|
| 43 | - function ($word) { |
|
| 44 | - return sprintf("%04x", $word); |
|
| 45 | - }, $words); |
|
| 46 | - return implode(":", $groups); |
|
| 47 | - } |
|
| 34 | + /** |
|
| 35 | + * Convert an array of 16 bit words to an IPv6 string representation. |
|
| 36 | + * |
|
| 37 | + * @param int[] $words |
|
| 38 | + * @return string |
|
| 39 | + */ |
|
| 40 | + protected static function _wordsToIPv6String(array $words): string |
|
| 41 | + { |
|
| 42 | + $groups = array_map( |
|
| 43 | + function ($word) { |
|
| 44 | + return sprintf("%04x", $word); |
|
| 45 | + }, $words); |
|
| 46 | + return implode(":", $groups); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * |
|
| 51 | - * {@inheritdoc} |
|
| 52 | - */ |
|
| 53 | - protected function _octets(): string |
|
| 54 | - { |
|
| 55 | - $words = array_map("hexdec", explode(":", $this->_ip)); |
|
| 56 | - if (isset($this->_mask)) { |
|
| 57 | - $words = array_merge($words, |
|
| 58 | - array_map("hexdec", explode(":", $this->_mask))); |
|
| 59 | - } |
|
| 60 | - return pack("n*", ...$words); |
|
| 61 | - } |
|
| 49 | + /** |
|
| 50 | + * |
|
| 51 | + * {@inheritdoc} |
|
| 52 | + */ |
|
| 53 | + protected function _octets(): string |
|
| 54 | + { |
|
| 55 | + $words = array_map("hexdec", explode(":", $this->_ip)); |
|
| 56 | + if (isset($this->_mask)) { |
|
| 57 | + $words = array_merge($words, |
|
| 58 | + array_map("hexdec", explode(":", $this->_mask))); |
|
| 59 | + } |
|
| 60 | + return pack("n*", ...$words); |
|
| 61 | + } |
|
| 62 | 62 | } |
@@ -13,147 +13,147 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | abstract class GeneralName |
| 15 | 15 | { |
| 16 | - // GeneralName CHOICE tags |
|
| 17 | - const TAG_OTHER_NAME = 0; |
|
| 18 | - const TAG_RFC822_NAME = 1; |
|
| 19 | - const TAG_DNS_NAME = 2; |
|
| 20 | - const TAG_X400_ADDRESS = 3; |
|
| 21 | - const TAG_DIRECTORY_NAME = 4; |
|
| 22 | - const TAG_EDI_PARTY_NAME = 5; |
|
| 23 | - const TAG_URI = 6; |
|
| 24 | - const TAG_IP_ADDRESS = 7; |
|
| 25 | - const TAG_REGISTERED_ID = 8; |
|
| 16 | + // GeneralName CHOICE tags |
|
| 17 | + const TAG_OTHER_NAME = 0; |
|
| 18 | + const TAG_RFC822_NAME = 1; |
|
| 19 | + const TAG_DNS_NAME = 2; |
|
| 20 | + const TAG_X400_ADDRESS = 3; |
|
| 21 | + const TAG_DIRECTORY_NAME = 4; |
|
| 22 | + const TAG_EDI_PARTY_NAME = 5; |
|
| 23 | + const TAG_URI = 6; |
|
| 24 | + const TAG_IP_ADDRESS = 7; |
|
| 25 | + const TAG_REGISTERED_ID = 8; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Chosen tag. |
|
| 29 | - * |
|
| 30 | - * @var int $_tag |
|
| 31 | - */ |
|
| 32 | - protected $_tag; |
|
| 27 | + /** |
|
| 28 | + * Chosen tag. |
|
| 29 | + * |
|
| 30 | + * @var int $_tag |
|
| 31 | + */ |
|
| 32 | + protected $_tag; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Get string value of the type. |
|
| 36 | - * |
|
| 37 | - * @return string |
|
| 38 | - */ |
|
| 39 | - abstract public function string(); |
|
| 34 | + /** |
|
| 35 | + * Get string value of the type. |
|
| 36 | + * |
|
| 37 | + * @return string |
|
| 38 | + */ |
|
| 39 | + abstract public function string(); |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Get ASN.1 value in GeneralName CHOICE context. |
|
| 43 | - * |
|
| 44 | - * @return TaggedType |
|
| 45 | - */ |
|
| 46 | - abstract protected function _choiceASN1(); |
|
| 41 | + /** |
|
| 42 | + * Get ASN.1 value in GeneralName CHOICE context. |
|
| 43 | + * |
|
| 44 | + * @return TaggedType |
|
| 45 | + */ |
|
| 46 | + abstract protected function _choiceASN1(); |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Initialize concrete object from the chosen ASN.1 element. |
|
| 50 | - * |
|
| 51 | - * @param UnspecifiedType $el |
|
| 52 | - * @return self |
|
| 53 | - */ |
|
| 54 | - public static function fromChosenASN1(UnspecifiedType $el) |
|
| 55 | - { |
|
| 56 | - throw new \BadMethodCallException( |
|
| 57 | - __FUNCTION__ . " must be implemented in the derived class."); |
|
| 58 | - } |
|
| 48 | + /** |
|
| 49 | + * Initialize concrete object from the chosen ASN.1 element. |
|
| 50 | + * |
|
| 51 | + * @param UnspecifiedType $el |
|
| 52 | + * @return self |
|
| 53 | + */ |
|
| 54 | + public static function fromChosenASN1(UnspecifiedType $el) |
|
| 55 | + { |
|
| 56 | + throw new \BadMethodCallException( |
|
| 57 | + __FUNCTION__ . " must be implemented in the derived class."); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * Initialize from ASN.1. |
|
| 62 | - * |
|
| 63 | - * @param TaggedType $el |
|
| 64 | - * @throws \UnexpectedValueException |
|
| 65 | - * @return self |
|
| 66 | - */ |
|
| 67 | - public static function fromASN1(TaggedType $el) |
|
| 68 | - { |
|
| 69 | - switch ($el->tag()) { |
|
| 70 | - // otherName |
|
| 71 | - case self::TAG_OTHER_NAME: |
|
| 72 | - return OtherName::fromChosenASN1( |
|
| 73 | - $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
| 74 | - // rfc822Name |
|
| 75 | - case self::TAG_RFC822_NAME: |
|
| 76 | - return RFC822Name::fromChosenASN1( |
|
| 77 | - $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
| 78 | - // dNSName |
|
| 79 | - case self::TAG_DNS_NAME: |
|
| 80 | - return DNSName::fromChosenASN1( |
|
| 81 | - $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
| 82 | - // x400Address |
|
| 83 | - case self::TAG_X400_ADDRESS: |
|
| 84 | - return X400Address::fromChosenASN1( |
|
| 85 | - $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
| 86 | - // directoryName |
|
| 87 | - case self::TAG_DIRECTORY_NAME: |
|
| 88 | - // because Name is a CHOICE, albeit having only one option, |
|
| 89 | - // explicit tagging must be used |
|
| 90 | - // (see X.680 07/2002 30.6.c) |
|
| 91 | - return DirectoryName::fromChosenASN1($el->asExplicit()); |
|
| 92 | - // ediPartyName |
|
| 93 | - case self::TAG_EDI_PARTY_NAME: |
|
| 94 | - return EDIPartyName::fromChosenASN1( |
|
| 95 | - $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
| 96 | - // uniformResourceIdentifier |
|
| 97 | - case self::TAG_URI: |
|
| 98 | - return UniformResourceIdentifier::fromChosenASN1( |
|
| 99 | - $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
| 100 | - // iPAddress |
|
| 101 | - case self::TAG_IP_ADDRESS: |
|
| 102 | - return IPAddress::fromChosenASN1( |
|
| 103 | - $el->asImplicit(Element::TYPE_OCTET_STRING)); |
|
| 104 | - // registeredID |
|
| 105 | - case self::TAG_REGISTERED_ID: |
|
| 106 | - return RegisteredID::fromChosenASN1( |
|
| 107 | - $el->asImplicit(Element::TYPE_OBJECT_IDENTIFIER)); |
|
| 108 | - } |
|
| 109 | - throw new \UnexpectedValueException( |
|
| 110 | - "GeneralName type " . $el->tag() . " not supported."); |
|
| 111 | - } |
|
| 60 | + /** |
|
| 61 | + * Initialize from ASN.1. |
|
| 62 | + * |
|
| 63 | + * @param TaggedType $el |
|
| 64 | + * @throws \UnexpectedValueException |
|
| 65 | + * @return self |
|
| 66 | + */ |
|
| 67 | + public static function fromASN1(TaggedType $el) |
|
| 68 | + { |
|
| 69 | + switch ($el->tag()) { |
|
| 70 | + // otherName |
|
| 71 | + case self::TAG_OTHER_NAME: |
|
| 72 | + return OtherName::fromChosenASN1( |
|
| 73 | + $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
| 74 | + // rfc822Name |
|
| 75 | + case self::TAG_RFC822_NAME: |
|
| 76 | + return RFC822Name::fromChosenASN1( |
|
| 77 | + $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
| 78 | + // dNSName |
|
| 79 | + case self::TAG_DNS_NAME: |
|
| 80 | + return DNSName::fromChosenASN1( |
|
| 81 | + $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
| 82 | + // x400Address |
|
| 83 | + case self::TAG_X400_ADDRESS: |
|
| 84 | + return X400Address::fromChosenASN1( |
|
| 85 | + $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
| 86 | + // directoryName |
|
| 87 | + case self::TAG_DIRECTORY_NAME: |
|
| 88 | + // because Name is a CHOICE, albeit having only one option, |
|
| 89 | + // explicit tagging must be used |
|
| 90 | + // (see X.680 07/2002 30.6.c) |
|
| 91 | + return DirectoryName::fromChosenASN1($el->asExplicit()); |
|
| 92 | + // ediPartyName |
|
| 93 | + case self::TAG_EDI_PARTY_NAME: |
|
| 94 | + return EDIPartyName::fromChosenASN1( |
|
| 95 | + $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
| 96 | + // uniformResourceIdentifier |
|
| 97 | + case self::TAG_URI: |
|
| 98 | + return UniformResourceIdentifier::fromChosenASN1( |
|
| 99 | + $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
| 100 | + // iPAddress |
|
| 101 | + case self::TAG_IP_ADDRESS: |
|
| 102 | + return IPAddress::fromChosenASN1( |
|
| 103 | + $el->asImplicit(Element::TYPE_OCTET_STRING)); |
|
| 104 | + // registeredID |
|
| 105 | + case self::TAG_REGISTERED_ID: |
|
| 106 | + return RegisteredID::fromChosenASN1( |
|
| 107 | + $el->asImplicit(Element::TYPE_OBJECT_IDENTIFIER)); |
|
| 108 | + } |
|
| 109 | + throw new \UnexpectedValueException( |
|
| 110 | + "GeneralName type " . $el->tag() . " not supported."); |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - /** |
|
| 114 | - * Get type tag. |
|
| 115 | - * |
|
| 116 | - * @return int |
|
| 117 | - */ |
|
| 118 | - public function tag() |
|
| 119 | - { |
|
| 120 | - return $this->_tag; |
|
| 121 | - } |
|
| 113 | + /** |
|
| 114 | + * Get type tag. |
|
| 115 | + * |
|
| 116 | + * @return int |
|
| 117 | + */ |
|
| 118 | + public function tag() |
|
| 119 | + { |
|
| 120 | + return $this->_tag; |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | - /** |
|
| 124 | - * Generate ASN.1 element. |
|
| 125 | - * |
|
| 126 | - * @return Element |
|
| 127 | - */ |
|
| 128 | - public function toASN1() |
|
| 129 | - { |
|
| 130 | - return $this->_choiceASN1(); |
|
| 131 | - } |
|
| 123 | + /** |
|
| 124 | + * Generate ASN.1 element. |
|
| 125 | + * |
|
| 126 | + * @return Element |
|
| 127 | + */ |
|
| 128 | + public function toASN1() |
|
| 129 | + { |
|
| 130 | + return $this->_choiceASN1(); |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - /** |
|
| 134 | - * Check whether GeneralName is equal to other. |
|
| 135 | - * |
|
| 136 | - * @param GeneralName $other GeneralName to compare to |
|
| 137 | - * @return boolean True if names are equal |
|
| 138 | - */ |
|
| 139 | - public function equals(GeneralName $other) |
|
| 140 | - { |
|
| 141 | - if ($this->_tag != $other->_tag) { |
|
| 142 | - return false; |
|
| 143 | - } |
|
| 144 | - if ($this->_choiceASN1()->toDER() != $other->_choiceASN1()->toDER()) { |
|
| 145 | - return false; |
|
| 146 | - } |
|
| 147 | - return true; |
|
| 148 | - } |
|
| 133 | + /** |
|
| 134 | + * Check whether GeneralName is equal to other. |
|
| 135 | + * |
|
| 136 | + * @param GeneralName $other GeneralName to compare to |
|
| 137 | + * @return boolean True if names are equal |
|
| 138 | + */ |
|
| 139 | + public function equals(GeneralName $other) |
|
| 140 | + { |
|
| 141 | + if ($this->_tag != $other->_tag) { |
|
| 142 | + return false; |
|
| 143 | + } |
|
| 144 | + if ($this->_choiceASN1()->toDER() != $other->_choiceASN1()->toDER()) { |
|
| 145 | + return false; |
|
| 146 | + } |
|
| 147 | + return true; |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - /** |
|
| 151 | - * Get general name as a string. |
|
| 152 | - * |
|
| 153 | - * @return string |
|
| 154 | - */ |
|
| 155 | - public function __toString() |
|
| 156 | - { |
|
| 157 | - return $this->string(); |
|
| 158 | - } |
|
| 150 | + /** |
|
| 151 | + * Get general name as a string. |
|
| 152 | + * |
|
| 153 | + * @return string |
|
| 154 | + */ |
|
| 155 | + public function __toString() |
|
| 156 | + { |
|
| 157 | + return $this->string(); |
|
| 158 | + } |
|
| 159 | 159 | } |
@@ -68,43 +68,43 @@ |
||
| 68 | 68 | { |
| 69 | 69 | switch ($el->tag()) { |
| 70 | 70 | // otherName |
| 71 | - case self::TAG_OTHER_NAME: |
|
| 72 | - return OtherName::fromChosenASN1( |
|
| 73 | - $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
| 74 | - // rfc822Name |
|
| 75 | - case self::TAG_RFC822_NAME: |
|
| 76 | - return RFC822Name::fromChosenASN1( |
|
| 77 | - $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
| 78 | - // dNSName |
|
| 79 | - case self::TAG_DNS_NAME: |
|
| 80 | - return DNSName::fromChosenASN1( |
|
| 81 | - $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
| 82 | - // x400Address |
|
| 83 | - case self::TAG_X400_ADDRESS: |
|
| 84 | - return X400Address::fromChosenASN1( |
|
| 85 | - $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
| 86 | - // directoryName |
|
| 87 | - case self::TAG_DIRECTORY_NAME: |
|
| 88 | - // because Name is a CHOICE, albeit having only one option, |
|
| 89 | - // explicit tagging must be used |
|
| 90 | - // (see X.680 07/2002 30.6.c) |
|
| 91 | - return DirectoryName::fromChosenASN1($el->asExplicit()); |
|
| 92 | - // ediPartyName |
|
| 93 | - case self::TAG_EDI_PARTY_NAME: |
|
| 94 | - return EDIPartyName::fromChosenASN1( |
|
| 95 | - $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
| 96 | - // uniformResourceIdentifier |
|
| 97 | - case self::TAG_URI: |
|
| 98 | - return UniformResourceIdentifier::fromChosenASN1( |
|
| 99 | - $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
| 100 | - // iPAddress |
|
| 101 | - case self::TAG_IP_ADDRESS: |
|
| 102 | - return IPAddress::fromChosenASN1( |
|
| 103 | - $el->asImplicit(Element::TYPE_OCTET_STRING)); |
|
| 104 | - // registeredID |
|
| 105 | - case self::TAG_REGISTERED_ID: |
|
| 106 | - return RegisteredID::fromChosenASN1( |
|
| 107 | - $el->asImplicit(Element::TYPE_OBJECT_IDENTIFIER)); |
|
| 71 | + case self::TAG_OTHER_NAME: |
|
| 72 | + return OtherName::fromChosenASN1( |
|
| 73 | + $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
| 74 | + // rfc822Name |
|
| 75 | + case self::TAG_RFC822_NAME: |
|
| 76 | + return RFC822Name::fromChosenASN1( |
|
| 77 | + $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
| 78 | + // dNSName |
|
| 79 | + case self::TAG_DNS_NAME: |
|
| 80 | + return DNSName::fromChosenASN1( |
|
| 81 | + $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
| 82 | + // x400Address |
|
| 83 | + case self::TAG_X400_ADDRESS: |
|
| 84 | + return X400Address::fromChosenASN1( |
|
| 85 | + $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
| 86 | + // directoryName |
|
| 87 | + case self::TAG_DIRECTORY_NAME: |
|
| 88 | + // because Name is a CHOICE, albeit having only one option, |
|
| 89 | + // explicit tagging must be used |
|
| 90 | + // (see X.680 07/2002 30.6.c) |
|
| 91 | + return DirectoryName::fromChosenASN1($el->asExplicit()); |
|
| 92 | + // ediPartyName |
|
| 93 | + case self::TAG_EDI_PARTY_NAME: |
|
| 94 | + return EDIPartyName::fromChosenASN1( |
|
| 95 | + $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
| 96 | + // uniformResourceIdentifier |
|
| 97 | + case self::TAG_URI: |
|
| 98 | + return UniformResourceIdentifier::fromChosenASN1( |
|
| 99 | + $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
| 100 | + // iPAddress |
|
| 101 | + case self::TAG_IP_ADDRESS: |
|
| 102 | + return IPAddress::fromChosenASN1( |
|
| 103 | + $el->asImplicit(Element::TYPE_OCTET_STRING)); |
|
| 104 | + // registeredID |
|
| 105 | + case self::TAG_REGISTERED_ID: |
|
| 106 | + return RegisteredID::fromChosenASN1( |
|
| 107 | + $el->asImplicit(Element::TYPE_OBJECT_IDENTIFIER)); |
|
| 108 | 108 | } |
| 109 | 109 | throw new \UnexpectedValueException( |
| 110 | 110 | "GeneralName type " . $el->tag() . " not supported."); |
@@ -16,91 +16,91 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class GeneralSubtree |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * Constraint. |
|
| 21 | - * |
|
| 22 | - * @var GeneralName |
|
| 23 | - */ |
|
| 24 | - protected $_base; |
|
| 19 | + /** |
|
| 20 | + * Constraint. |
|
| 21 | + * |
|
| 22 | + * @var GeneralName |
|
| 23 | + */ |
|
| 24 | + protected $_base; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Not used, must be zero. |
|
| 28 | - * |
|
| 29 | - * @var int $_min |
|
| 30 | - */ |
|
| 31 | - protected $_min; |
|
| 26 | + /** |
|
| 27 | + * Not used, must be zero. |
|
| 28 | + * |
|
| 29 | + * @var int $_min |
|
| 30 | + */ |
|
| 31 | + protected $_min; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Not used, must be null. |
|
| 35 | - * |
|
| 36 | - * @var int|null $_max |
|
| 37 | - */ |
|
| 38 | - protected $_max; |
|
| 33 | + /** |
|
| 34 | + * Not used, must be null. |
|
| 35 | + * |
|
| 36 | + * @var int|null $_max |
|
| 37 | + */ |
|
| 38 | + protected $_max; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Constructor. |
|
| 42 | - * |
|
| 43 | - * @param GeneralName $base |
|
| 44 | - * @param int $min |
|
| 45 | - * @param int|null $max |
|
| 46 | - */ |
|
| 47 | - public function __construct(GeneralName $base, $min = 0, $max = null) |
|
| 48 | - { |
|
| 49 | - $this->_base = $base; |
|
| 50 | - $this->_min = $min; |
|
| 51 | - $this->_max = $max; |
|
| 52 | - } |
|
| 40 | + /** |
|
| 41 | + * Constructor. |
|
| 42 | + * |
|
| 43 | + * @param GeneralName $base |
|
| 44 | + * @param int $min |
|
| 45 | + * @param int|null $max |
|
| 46 | + */ |
|
| 47 | + public function __construct(GeneralName $base, $min = 0, $max = null) |
|
| 48 | + { |
|
| 49 | + $this->_base = $base; |
|
| 50 | + $this->_min = $min; |
|
| 51 | + $this->_max = $max; |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Initialize from ASN.1. |
|
| 56 | - * |
|
| 57 | - * @param Sequence $seq |
|
| 58 | - * @return self |
|
| 59 | - */ |
|
| 60 | - public static function fromASN1(Sequence $seq) |
|
| 61 | - { |
|
| 62 | - $base = GeneralName::fromASN1($seq->at(0)->asTagged()); |
|
| 63 | - $min = 0; |
|
| 64 | - $max = null; |
|
| 65 | - if ($seq->hasTagged(0)) { |
|
| 66 | - $min = $seq->getTagged(0) |
|
| 67 | - ->asImplicit(Element::TYPE_INTEGER) |
|
| 68 | - ->asInteger() |
|
| 69 | - ->number(); |
|
| 70 | - } |
|
| 71 | - if ($seq->hasTagged(1)) { |
|
| 72 | - $max = $seq->getTagged(1) |
|
| 73 | - ->asImplicit(Element::TYPE_INTEGER) |
|
| 74 | - ->asInteger() |
|
| 75 | - ->number(); |
|
| 76 | - } |
|
| 77 | - return new self($base, $min, $max); |
|
| 78 | - } |
|
| 54 | + /** |
|
| 55 | + * Initialize from ASN.1. |
|
| 56 | + * |
|
| 57 | + * @param Sequence $seq |
|
| 58 | + * @return self |
|
| 59 | + */ |
|
| 60 | + public static function fromASN1(Sequence $seq) |
|
| 61 | + { |
|
| 62 | + $base = GeneralName::fromASN1($seq->at(0)->asTagged()); |
|
| 63 | + $min = 0; |
|
| 64 | + $max = null; |
|
| 65 | + if ($seq->hasTagged(0)) { |
|
| 66 | + $min = $seq->getTagged(0) |
|
| 67 | + ->asImplicit(Element::TYPE_INTEGER) |
|
| 68 | + ->asInteger() |
|
| 69 | + ->number(); |
|
| 70 | + } |
|
| 71 | + if ($seq->hasTagged(1)) { |
|
| 72 | + $max = $seq->getTagged(1) |
|
| 73 | + ->asImplicit(Element::TYPE_INTEGER) |
|
| 74 | + ->asInteger() |
|
| 75 | + ->number(); |
|
| 76 | + } |
|
| 77 | + return new self($base, $min, $max); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * Get constraint. |
|
| 82 | - * |
|
| 83 | - * @return GeneralName |
|
| 84 | - */ |
|
| 85 | - public function base() |
|
| 86 | - { |
|
| 87 | - return $this->_base; |
|
| 88 | - } |
|
| 80 | + /** |
|
| 81 | + * Get constraint. |
|
| 82 | + * |
|
| 83 | + * @return GeneralName |
|
| 84 | + */ |
|
| 85 | + public function base() |
|
| 86 | + { |
|
| 87 | + return $this->_base; |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * Generate ASN.1 structure. |
|
| 92 | - * |
|
| 93 | - * @return Sequence |
|
| 94 | - */ |
|
| 95 | - public function toASN1() |
|
| 96 | - { |
|
| 97 | - $elements = array($this->_base->toASN1()); |
|
| 98 | - if (isset($this->_min) && $this->_min != 0) { |
|
| 99 | - $elements[] = new ImplicitlyTaggedType(0, new Integer($this->_min)); |
|
| 100 | - } |
|
| 101 | - if (isset($this->_max)) { |
|
| 102 | - $elements[] = new ImplicitlyTaggedType(1, new Integer($this->_max)); |
|
| 103 | - } |
|
| 104 | - return new Sequence(...$elements); |
|
| 105 | - } |
|
| 90 | + /** |
|
| 91 | + * Generate ASN.1 structure. |
|
| 92 | + * |
|
| 93 | + * @return Sequence |
|
| 94 | + */ |
|
| 95 | + public function toASN1() |
|
| 96 | + { |
|
| 97 | + $elements = array($this->_base->toASN1()); |
|
| 98 | + if (isset($this->_min) && $this->_min != 0) { |
|
| 99 | + $elements[] = new ImplicitlyTaggedType(0, new Integer($this->_min)); |
|
| 100 | + } |
|
| 101 | + if (isset($this->_max)) { |
|
| 102 | + $elements[] = new ImplicitlyTaggedType(1, new Integer($this->_max)); |
|
| 103 | + } |
|
| 104 | + return new Sequence(...$elements); |
|
| 105 | + } |
|
| 106 | 106 | } |
@@ -43,16 +43,16 @@ |
||
| 43 | 43 | public static function fromTaggedType(TaggedType $el) |
| 44 | 44 | { |
| 45 | 45 | switch ($el->tag()) { |
| 46 | - case self::TAG_FULL_NAME: |
|
| 47 | - return new FullName( |
|
| 48 | - GeneralNames::fromASN1( |
|
| 49 | - $el->asImplicit(Element::TYPE_SEQUENCE)->asSequence())); |
|
| 50 | - case self::TAG_RDN: |
|
| 51 | - return new RelativeName( |
|
| 52 | - RDN::fromASN1($el->asImplicit(Element::TYPE_SET)->asSet())); |
|
| 53 | - default: |
|
| 54 | - throw new \UnexpectedValueException( |
|
| 55 | - "DistributionPointName tag " . $el->tag() . " not supported."); |
|
| 46 | + case self::TAG_FULL_NAME: |
|
| 47 | + return new FullName( |
|
| 48 | + GeneralNames::fromASN1( |
|
| 49 | + $el->asImplicit(Element::TYPE_SEQUENCE)->asSequence())); |
|
| 50 | + case self::TAG_RDN: |
|
| 51 | + return new RelativeName( |
|
| 52 | + RDN::fromASN1($el->asImplicit(Element::TYPE_SET)->asSet())); |
|
| 53 | + default: |
|
| 54 | + throw new \UnexpectedValueException( |
|
| 55 | + "DistributionPointName tag " . $el->tag() . " not supported."); |
|
| 56 | 56 | } |
| 57 | 57 | } |
| 58 | 58 | |
@@ -18,64 +18,64 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | abstract class DistributionPointName |
| 20 | 20 | { |
| 21 | - const TAG_FULL_NAME = 0; |
|
| 22 | - const TAG_RDN = 1; |
|
| 21 | + const TAG_FULL_NAME = 0; |
|
| 22 | + const TAG_RDN = 1; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Type. |
|
| 26 | - * |
|
| 27 | - * @var int $_tag |
|
| 28 | - */ |
|
| 29 | - protected $_tag; |
|
| 24 | + /** |
|
| 25 | + * Type. |
|
| 26 | + * |
|
| 27 | + * @var int $_tag |
|
| 28 | + */ |
|
| 29 | + protected $_tag; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Generate ASN.1 element. |
|
| 33 | - * |
|
| 34 | - * @return Element |
|
| 35 | - */ |
|
| 36 | - abstract protected function _valueASN1(); |
|
| 31 | + /** |
|
| 32 | + * Generate ASN.1 element. |
|
| 33 | + * |
|
| 34 | + * @return Element |
|
| 35 | + */ |
|
| 36 | + abstract protected function _valueASN1(); |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Initialize from TaggedType. |
|
| 40 | - * |
|
| 41 | - * @param TaggedType $el |
|
| 42 | - * @throws \UnexpectedValueException |
|
| 43 | - * @return self |
|
| 44 | - */ |
|
| 45 | - public static function fromTaggedType(TaggedType $el) |
|
| 46 | - { |
|
| 47 | - switch ($el->tag()) { |
|
| 48 | - case self::TAG_FULL_NAME: |
|
| 49 | - return new FullName( |
|
| 50 | - GeneralNames::fromASN1( |
|
| 51 | - $el->asImplicit(Element::TYPE_SEQUENCE)->asSequence())); |
|
| 52 | - case self::TAG_RDN: |
|
| 53 | - return new RelativeName( |
|
| 54 | - RDN::fromASN1($el->asImplicit(Element::TYPE_SET)->asSet())); |
|
| 55 | - default: |
|
| 56 | - throw new \UnexpectedValueException( |
|
| 57 | - "DistributionPointName tag " . $el->tag() . " not supported."); |
|
| 58 | - } |
|
| 59 | - } |
|
| 38 | + /** |
|
| 39 | + * Initialize from TaggedType. |
|
| 40 | + * |
|
| 41 | + * @param TaggedType $el |
|
| 42 | + * @throws \UnexpectedValueException |
|
| 43 | + * @return self |
|
| 44 | + */ |
|
| 45 | + public static function fromTaggedType(TaggedType $el) |
|
| 46 | + { |
|
| 47 | + switch ($el->tag()) { |
|
| 48 | + case self::TAG_FULL_NAME: |
|
| 49 | + return new FullName( |
|
| 50 | + GeneralNames::fromASN1( |
|
| 51 | + $el->asImplicit(Element::TYPE_SEQUENCE)->asSequence())); |
|
| 52 | + case self::TAG_RDN: |
|
| 53 | + return new RelativeName( |
|
| 54 | + RDN::fromASN1($el->asImplicit(Element::TYPE_SET)->asSet())); |
|
| 55 | + default: |
|
| 56 | + throw new \UnexpectedValueException( |
|
| 57 | + "DistributionPointName tag " . $el->tag() . " not supported."); |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Get type tag. |
|
| 63 | - * |
|
| 64 | - * @return int |
|
| 65 | - */ |
|
| 66 | - public function tag() |
|
| 67 | - { |
|
| 68 | - return $this->_tag; |
|
| 69 | - } |
|
| 61 | + /** |
|
| 62 | + * Get type tag. |
|
| 63 | + * |
|
| 64 | + * @return int |
|
| 65 | + */ |
|
| 66 | + public function tag() |
|
| 67 | + { |
|
| 68 | + return $this->_tag; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Generate ASN.1 structure. |
|
| 73 | - * |
|
| 74 | - * @return ImplicitlyTaggedType |
|
| 75 | - */ |
|
| 76 | - public function toASN1(): ImplicitlyTaggedType |
|
| 77 | - { |
|
| 78 | - $element = $this->_valueASN1(); |
|
| 79 | - return new ImplicitlyTaggedType($this->_tag, $element); |
|
| 80 | - } |
|
| 71 | + /** |
|
| 72 | + * Generate ASN.1 structure. |
|
| 73 | + * |
|
| 74 | + * @return ImplicitlyTaggedType |
|
| 75 | + */ |
|
| 76 | + public function toASN1(): ImplicitlyTaggedType |
|
| 77 | + { |
|
| 78 | + $element = $this->_valueASN1(); |
|
| 79 | + return new ImplicitlyTaggedType($this->_tag, $element); |
|
| 80 | + } |
|
| 81 | 81 | } |
@@ -14,114 +14,114 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class UserNoticeQualifier extends PolicyQualifierInfo |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * Explicit notice text. |
|
| 19 | - * |
|
| 20 | - * @var DisplayText $_text |
|
| 21 | - */ |
|
| 22 | - protected $_text; |
|
| 17 | + /** |
|
| 18 | + * Explicit notice text. |
|
| 19 | + * |
|
| 20 | + * @var DisplayText $_text |
|
| 21 | + */ |
|
| 22 | + protected $_text; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Notice reference. |
|
| 26 | - * |
|
| 27 | - * @var NoticeReference $_ref |
|
| 28 | - */ |
|
| 29 | - protected $_ref; |
|
| 24 | + /** |
|
| 25 | + * Notice reference. |
|
| 26 | + * |
|
| 27 | + * @var NoticeReference $_ref |
|
| 28 | + */ |
|
| 29 | + protected $_ref; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Constructor. |
|
| 33 | - * |
|
| 34 | - * @param DisplayText|null $text |
|
| 35 | - * @param NoticeReference|null $ref |
|
| 36 | - */ |
|
| 37 | - public function __construct(DisplayText $text = null, NoticeReference $ref = null) |
|
| 38 | - { |
|
| 39 | - $this->_oid = self::OID_UNOTICE; |
|
| 40 | - $this->_text = $text; |
|
| 41 | - $this->_ref = $ref; |
|
| 42 | - } |
|
| 31 | + /** |
|
| 32 | + * Constructor. |
|
| 33 | + * |
|
| 34 | + * @param DisplayText|null $text |
|
| 35 | + * @param NoticeReference|null $ref |
|
| 36 | + */ |
|
| 37 | + public function __construct(DisplayText $text = null, NoticeReference $ref = null) |
|
| 38 | + { |
|
| 39 | + $this->_oid = self::OID_UNOTICE; |
|
| 40 | + $this->_text = $text; |
|
| 41 | + $this->_ref = $ref; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * |
|
| 46 | - * @param UnspecifiedType $el |
|
| 47 | - * @return self |
|
| 48 | - */ |
|
| 49 | - public static function fromQualifierASN1(UnspecifiedType $el) |
|
| 50 | - { |
|
| 51 | - $seq = $el->asSequence(); |
|
| 52 | - $ref = null; |
|
| 53 | - $text = null; |
|
| 54 | - $idx = 0; |
|
| 55 | - if ($seq->has($idx, Element::TYPE_SEQUENCE)) { |
|
| 56 | - $ref = NoticeReference::fromASN1($seq->at($idx++)->asSequence()); |
|
| 57 | - } |
|
| 58 | - if ($seq->has($idx, Element::TYPE_STRING)) { |
|
| 59 | - $text = DisplayText::fromASN1($seq->at($idx)->asString()); |
|
| 60 | - } |
|
| 61 | - return new self($text, $ref); |
|
| 62 | - } |
|
| 44 | + /** |
|
| 45 | + * |
|
| 46 | + * @param UnspecifiedType $el |
|
| 47 | + * @return self |
|
| 48 | + */ |
|
| 49 | + public static function fromQualifierASN1(UnspecifiedType $el) |
|
| 50 | + { |
|
| 51 | + $seq = $el->asSequence(); |
|
| 52 | + $ref = null; |
|
| 53 | + $text = null; |
|
| 54 | + $idx = 0; |
|
| 55 | + if ($seq->has($idx, Element::TYPE_SEQUENCE)) { |
|
| 56 | + $ref = NoticeReference::fromASN1($seq->at($idx++)->asSequence()); |
|
| 57 | + } |
|
| 58 | + if ($seq->has($idx, Element::TYPE_STRING)) { |
|
| 59 | + $text = DisplayText::fromASN1($seq->at($idx)->asString()); |
|
| 60 | + } |
|
| 61 | + return new self($text, $ref); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * Whether explicit text is present. |
|
| 66 | - * |
|
| 67 | - * @return bool |
|
| 68 | - */ |
|
| 69 | - public function hasExplicitText() |
|
| 70 | - { |
|
| 71 | - return isset($this->_text); |
|
| 72 | - } |
|
| 64 | + /** |
|
| 65 | + * Whether explicit text is present. |
|
| 66 | + * |
|
| 67 | + * @return bool |
|
| 68 | + */ |
|
| 69 | + public function hasExplicitText() |
|
| 70 | + { |
|
| 71 | + return isset($this->_text); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * Get explicit text. |
|
| 76 | - * |
|
| 77 | - * @return DisplayText |
|
| 78 | - */ |
|
| 79 | - public function explicitText() |
|
| 80 | - { |
|
| 81 | - if (!$this->hasExplicitText()) { |
|
| 82 | - throw new \LogicException("explicitText not set."); |
|
| 83 | - } |
|
| 84 | - return $this->_text; |
|
| 85 | - } |
|
| 74 | + /** |
|
| 75 | + * Get explicit text. |
|
| 76 | + * |
|
| 77 | + * @return DisplayText |
|
| 78 | + */ |
|
| 79 | + public function explicitText() |
|
| 80 | + { |
|
| 81 | + if (!$this->hasExplicitText()) { |
|
| 82 | + throw new \LogicException("explicitText not set."); |
|
| 83 | + } |
|
| 84 | + return $this->_text; |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * Whether notice reference is present. |
|
| 89 | - * |
|
| 90 | - * @return bool |
|
| 91 | - */ |
|
| 92 | - public function hasNoticeRef() |
|
| 93 | - { |
|
| 94 | - return isset($this->_ref); |
|
| 95 | - } |
|
| 87 | + /** |
|
| 88 | + * Whether notice reference is present. |
|
| 89 | + * |
|
| 90 | + * @return bool |
|
| 91 | + */ |
|
| 92 | + public function hasNoticeRef() |
|
| 93 | + { |
|
| 94 | + return isset($this->_ref); |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * Get notice reference. |
|
| 99 | - * |
|
| 100 | - * @throws \RuntimeException |
|
| 101 | - * @return NoticeReference |
|
| 102 | - */ |
|
| 103 | - public function noticeRef() |
|
| 104 | - { |
|
| 105 | - if (!$this->hasNoticeRef()) { |
|
| 106 | - throw new \LogicException("noticeRef not set."); |
|
| 107 | - } |
|
| 108 | - return $this->_ref; |
|
| 109 | - } |
|
| 97 | + /** |
|
| 98 | + * Get notice reference. |
|
| 99 | + * |
|
| 100 | + * @throws \RuntimeException |
|
| 101 | + * @return NoticeReference |
|
| 102 | + */ |
|
| 103 | + public function noticeRef() |
|
| 104 | + { |
|
| 105 | + if (!$this->hasNoticeRef()) { |
|
| 106 | + throw new \LogicException("noticeRef not set."); |
|
| 107 | + } |
|
| 108 | + return $this->_ref; |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * |
|
| 113 | - * {@inheritdoc} |
|
| 114 | - * @return Sequence |
|
| 115 | - */ |
|
| 116 | - protected function _qualifierASN1() |
|
| 117 | - { |
|
| 118 | - $elements = array(); |
|
| 119 | - if (isset($this->_ref)) { |
|
| 120 | - $elements[] = $this->_ref->toASN1(); |
|
| 121 | - } |
|
| 122 | - if (isset($this->_text)) { |
|
| 123 | - $elements[] = $this->_text->toASN1(); |
|
| 124 | - } |
|
| 125 | - return new Sequence(...$elements); |
|
| 126 | - } |
|
| 111 | + /** |
|
| 112 | + * |
|
| 113 | + * {@inheritdoc} |
|
| 114 | + * @return Sequence |
|
| 115 | + */ |
|
| 116 | + protected function _qualifierASN1() |
|
| 117 | + { |
|
| 118 | + $elements = array(); |
|
| 119 | + if (isset($this->_ref)) { |
|
| 120 | + $elements[] = $this->_ref->toASN1(); |
|
| 121 | + } |
|
| 122 | + if (isset($this->_text)) { |
|
| 123 | + $elements[] = $this->_text->toASN1(); |
|
| 124 | + } |
|
| 125 | + return new Sequence(...$elements); |
|
| 126 | + } |
|
| 127 | 127 | } |
@@ -17,93 +17,93 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class DisplayText |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * Text. |
|
| 22 | - * |
|
| 23 | - * @var string $_text |
|
| 24 | - */ |
|
| 25 | - protected $_text; |
|
| 20 | + /** |
|
| 21 | + * Text. |
|
| 22 | + * |
|
| 23 | + * @var string $_text |
|
| 24 | + */ |
|
| 25 | + protected $_text; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Element tag. |
|
| 29 | - * |
|
| 30 | - * @var int $_tag |
|
| 31 | - */ |
|
| 32 | - protected $_tag; |
|
| 27 | + /** |
|
| 28 | + * Element tag. |
|
| 29 | + * |
|
| 30 | + * @var int $_tag |
|
| 31 | + */ |
|
| 32 | + protected $_tag; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Constructor. |
|
| 36 | - * |
|
| 37 | - * @param string $text |
|
| 38 | - * @param int $tag |
|
| 39 | - */ |
|
| 40 | - public function __construct($text, $tag) |
|
| 41 | - { |
|
| 42 | - $this->_text = $text; |
|
| 43 | - $this->_tag = $tag; |
|
| 44 | - } |
|
| 34 | + /** |
|
| 35 | + * Constructor. |
|
| 36 | + * |
|
| 37 | + * @param string $text |
|
| 38 | + * @param int $tag |
|
| 39 | + */ |
|
| 40 | + public function __construct($text, $tag) |
|
| 41 | + { |
|
| 42 | + $this->_text = $text; |
|
| 43 | + $this->_tag = $tag; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Initialize from ASN.1. |
|
| 48 | - * |
|
| 49 | - * @param StringType $el |
|
| 50 | - * @return self |
|
| 51 | - */ |
|
| 52 | - public static function fromASN1(StringType $el) |
|
| 53 | - { |
|
| 54 | - return new self($el->string(), $el->tag()); |
|
| 55 | - } |
|
| 46 | + /** |
|
| 47 | + * Initialize from ASN.1. |
|
| 48 | + * |
|
| 49 | + * @param StringType $el |
|
| 50 | + * @return self |
|
| 51 | + */ |
|
| 52 | + public static function fromASN1(StringType $el) |
|
| 53 | + { |
|
| 54 | + return new self($el->string(), $el->tag()); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Initialize from a UTF-8 string. |
|
| 59 | - * |
|
| 60 | - * @param string $str |
|
| 61 | - * @return self |
|
| 62 | - */ |
|
| 63 | - public static function fromString($str) |
|
| 64 | - { |
|
| 65 | - return new self($str, Element::TYPE_UTF8_STRING); |
|
| 66 | - } |
|
| 57 | + /** |
|
| 58 | + * Initialize from a UTF-8 string. |
|
| 59 | + * |
|
| 60 | + * @param string $str |
|
| 61 | + * @return self |
|
| 62 | + */ |
|
| 63 | + public static function fromString($str) |
|
| 64 | + { |
|
| 65 | + return new self($str, Element::TYPE_UTF8_STRING); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * Get the text. |
|
| 70 | - * |
|
| 71 | - * @return string |
|
| 72 | - */ |
|
| 73 | - public function string() |
|
| 74 | - { |
|
| 75 | - return $this->_text; |
|
| 76 | - } |
|
| 68 | + /** |
|
| 69 | + * Get the text. |
|
| 70 | + * |
|
| 71 | + * @return string |
|
| 72 | + */ |
|
| 73 | + public function string() |
|
| 74 | + { |
|
| 75 | + return $this->_text; |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Generate ASN.1 element. |
|
| 80 | - * |
|
| 81 | - * @throws \UnexpectedValueException |
|
| 82 | - * @return StringType |
|
| 83 | - */ |
|
| 84 | - public function toASN1() |
|
| 85 | - { |
|
| 86 | - switch ($this->_tag) { |
|
| 87 | - case Element::TYPE_IA5_STRING: |
|
| 88 | - return new IA5String($this->_text); |
|
| 89 | - case Element::TYPE_VISIBLE_STRING: |
|
| 90 | - return new VisibleString($this->_text); |
|
| 91 | - case Element::TYPE_BMP_STRING: |
|
| 92 | - return new BMPString($this->_text); |
|
| 93 | - case Element::TYPE_UTF8_STRING: |
|
| 94 | - return new UTF8String($this->_text); |
|
| 95 | - default: |
|
| 96 | - throw new \UnexpectedValueException( |
|
| 97 | - "Type " . Element::tagToName($this->_tag) . " not supported."); |
|
| 98 | - } |
|
| 99 | - } |
|
| 78 | + /** |
|
| 79 | + * Generate ASN.1 element. |
|
| 80 | + * |
|
| 81 | + * @throws \UnexpectedValueException |
|
| 82 | + * @return StringType |
|
| 83 | + */ |
|
| 84 | + public function toASN1() |
|
| 85 | + { |
|
| 86 | + switch ($this->_tag) { |
|
| 87 | + case Element::TYPE_IA5_STRING: |
|
| 88 | + return new IA5String($this->_text); |
|
| 89 | + case Element::TYPE_VISIBLE_STRING: |
|
| 90 | + return new VisibleString($this->_text); |
|
| 91 | + case Element::TYPE_BMP_STRING: |
|
| 92 | + return new BMPString($this->_text); |
|
| 93 | + case Element::TYPE_UTF8_STRING: |
|
| 94 | + return new UTF8String($this->_text); |
|
| 95 | + default: |
|
| 96 | + throw new \UnexpectedValueException( |
|
| 97 | + "Type " . Element::tagToName($this->_tag) . " not supported."); |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * |
|
| 103 | - * @return string |
|
| 104 | - */ |
|
| 105 | - public function __toString() |
|
| 106 | - { |
|
| 107 | - return $this->string(); |
|
| 108 | - } |
|
| 101 | + /** |
|
| 102 | + * |
|
| 103 | + * @return string |
|
| 104 | + */ |
|
| 105 | + public function __toString() |
|
| 106 | + { |
|
| 107 | + return $this->string(); |
|
| 108 | + } |
|
| 109 | 109 | } |
@@ -84,17 +84,17 @@ |
||
| 84 | 84 | public function toASN1() |
| 85 | 85 | { |
| 86 | 86 | switch ($this->_tag) { |
| 87 | - case Element::TYPE_IA5_STRING: |
|
| 88 | - return new IA5String($this->_text); |
|
| 89 | - case Element::TYPE_VISIBLE_STRING: |
|
| 90 | - return new VisibleString($this->_text); |
|
| 91 | - case Element::TYPE_BMP_STRING: |
|
| 92 | - return new BMPString($this->_text); |
|
| 93 | - case Element::TYPE_UTF8_STRING: |
|
| 94 | - return new UTF8String($this->_text); |
|
| 95 | - default: |
|
| 96 | - throw new \UnexpectedValueException( |
|
| 97 | - "Type " . Element::tagToName($this->_tag) . " not supported."); |
|
| 87 | + case Element::TYPE_IA5_STRING: |
|
| 88 | + return new IA5String($this->_text); |
|
| 89 | + case Element::TYPE_VISIBLE_STRING: |
|
| 90 | + return new VisibleString($this->_text); |
|
| 91 | + case Element::TYPE_BMP_STRING: |
|
| 92 | + return new BMPString($this->_text); |
|
| 93 | + case Element::TYPE_UTF8_STRING: |
|
| 94 | + return new UTF8String($this->_text); |
|
| 95 | + default: |
|
| 96 | + throw new \UnexpectedValueException( |
|
| 97 | + "Type " . Element::tagToName($this->_tag) . " not supported."); |
|
| 98 | 98 | } |
| 99 | 99 | } |
| 100 | 100 | |
@@ -67,10 +67,10 @@ |
||
| 67 | 67 | ->asObjectIdentifier() |
| 68 | 68 | ->oid(); |
| 69 | 69 | switch ($oid) { |
| 70 | - case self::OID_CPS: |
|
| 71 | - return CPSQualifier::fromQualifierASN1($seq->at(1)); |
|
| 72 | - case self::OID_UNOTICE: |
|
| 73 | - return UserNoticeQualifier::fromQualifierASN1($seq->at(1)); |
|
| 70 | + case self::OID_CPS: |
|
| 71 | + return CPSQualifier::fromQualifierASN1($seq->at(1)); |
|
| 72 | + case self::OID_UNOTICE: |
|
| 73 | + return UserNoticeQualifier::fromQualifierASN1($seq->at(1)); |
|
| 74 | 74 | } |
| 75 | 75 | throw new \UnexpectedValueException("Qualifier $oid not supported."); |
| 76 | 76 | } |
@@ -16,85 +16,85 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | abstract class PolicyQualifierInfo |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * OID for the CPS Pointer qualifier. |
|
| 21 | - * |
|
| 22 | - * @var string |
|
| 23 | - */ |
|
| 24 | - const OID_CPS = "1.3.6.1.5.5.7.2.1"; |
|
| 19 | + /** |
|
| 20 | + * OID for the CPS Pointer qualifier. |
|
| 21 | + * |
|
| 22 | + * @var string |
|
| 23 | + */ |
|
| 24 | + const OID_CPS = "1.3.6.1.5.5.7.2.1"; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * OID for the user notice qualifier. |
|
| 28 | - * |
|
| 29 | - * @var string |
|
| 30 | - */ |
|
| 31 | - const OID_UNOTICE = "1.3.6.1.5.5.7.2.2"; |
|
| 26 | + /** |
|
| 27 | + * OID for the user notice qualifier. |
|
| 28 | + * |
|
| 29 | + * @var string |
|
| 30 | + */ |
|
| 31 | + const OID_UNOTICE = "1.3.6.1.5.5.7.2.2"; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Qualifier identifier. |
|
| 35 | - * |
|
| 36 | - * @var string $_oid |
|
| 37 | - */ |
|
| 38 | - protected $_oid; |
|
| 33 | + /** |
|
| 34 | + * Qualifier identifier. |
|
| 35 | + * |
|
| 36 | + * @var string $_oid |
|
| 37 | + */ |
|
| 38 | + protected $_oid; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Generate ASN.1 for the 'qualifier' field. |
|
| 42 | - * |
|
| 43 | - * @return \ASN1\Element |
|
| 44 | - */ |
|
| 45 | - abstract protected function _qualifierASN1(); |
|
| 40 | + /** |
|
| 41 | + * Generate ASN.1 for the 'qualifier' field. |
|
| 42 | + * |
|
| 43 | + * @return \ASN1\Element |
|
| 44 | + */ |
|
| 45 | + abstract protected function _qualifierASN1(); |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Initialize from qualifier ASN.1 element. |
|
| 49 | - * |
|
| 50 | - * @param UnspecifiedType $el |
|
| 51 | - * @return self |
|
| 52 | - */ |
|
| 53 | - public static function fromQualifierASN1(UnspecifiedType $el) |
|
| 54 | - { |
|
| 55 | - throw new \BadMethodCallException( |
|
| 56 | - __FUNCTION__ . " must be implemented in the derived class."); |
|
| 57 | - } |
|
| 47 | + /** |
|
| 48 | + * Initialize from qualifier ASN.1 element. |
|
| 49 | + * |
|
| 50 | + * @param UnspecifiedType $el |
|
| 51 | + * @return self |
|
| 52 | + */ |
|
| 53 | + public static function fromQualifierASN1(UnspecifiedType $el) |
|
| 54 | + { |
|
| 55 | + throw new \BadMethodCallException( |
|
| 56 | + __FUNCTION__ . " must be implemented in the derived class."); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Initialize from ASN.1. |
|
| 61 | - * |
|
| 62 | - * @param Sequence $seq |
|
| 63 | - * @throws \UnexpectedValueException |
|
| 64 | - * @return self |
|
| 65 | - */ |
|
| 66 | - public static function fromASN1(Sequence $seq) |
|
| 67 | - { |
|
| 68 | - $oid = $seq->at(0) |
|
| 69 | - ->asObjectIdentifier() |
|
| 70 | - ->oid(); |
|
| 71 | - switch ($oid) { |
|
| 72 | - case self::OID_CPS: |
|
| 73 | - return CPSQualifier::fromQualifierASN1($seq->at(1)); |
|
| 74 | - case self::OID_UNOTICE: |
|
| 75 | - return UserNoticeQualifier::fromQualifierASN1($seq->at(1)); |
|
| 76 | - } |
|
| 77 | - throw new \UnexpectedValueException("Qualifier $oid not supported."); |
|
| 78 | - } |
|
| 59 | + /** |
|
| 60 | + * Initialize from ASN.1. |
|
| 61 | + * |
|
| 62 | + * @param Sequence $seq |
|
| 63 | + * @throws \UnexpectedValueException |
|
| 64 | + * @return self |
|
| 65 | + */ |
|
| 66 | + public static function fromASN1(Sequence $seq) |
|
| 67 | + { |
|
| 68 | + $oid = $seq->at(0) |
|
| 69 | + ->asObjectIdentifier() |
|
| 70 | + ->oid(); |
|
| 71 | + switch ($oid) { |
|
| 72 | + case self::OID_CPS: |
|
| 73 | + return CPSQualifier::fromQualifierASN1($seq->at(1)); |
|
| 74 | + case self::OID_UNOTICE: |
|
| 75 | + return UserNoticeQualifier::fromQualifierASN1($seq->at(1)); |
|
| 76 | + } |
|
| 77 | + throw new \UnexpectedValueException("Qualifier $oid not supported."); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * Get qualifier identifier. |
|
| 82 | - * |
|
| 83 | - * @return string |
|
| 84 | - */ |
|
| 85 | - public function oid(): string |
|
| 86 | - { |
|
| 87 | - return $this->_oid; |
|
| 88 | - } |
|
| 80 | + /** |
|
| 81 | + * Get qualifier identifier. |
|
| 82 | + * |
|
| 83 | + * @return string |
|
| 84 | + */ |
|
| 85 | + public function oid(): string |
|
| 86 | + { |
|
| 87 | + return $this->_oid; |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * Generate ASN.1 structure. |
|
| 92 | - * |
|
| 93 | - * @return Sequence |
|
| 94 | - */ |
|
| 95 | - public function toASN1(): Sequence |
|
| 96 | - { |
|
| 97 | - return new Sequence(new ObjectIdentifier($this->_oid), |
|
| 98 | - $this->_qualifierASN1()); |
|
| 99 | - } |
|
| 90 | + /** |
|
| 91 | + * Generate ASN.1 structure. |
|
| 92 | + * |
|
| 93 | + * @return Sequence |
|
| 94 | + */ |
|
| 95 | + public function toASN1(): Sequence |
|
| 96 | + { |
|
| 97 | + return new Sequence(new ObjectIdentifier($this->_oid), |
|
| 98 | + $this->_qualifierASN1()); |
|
| 99 | + } |
|
| 100 | 100 | } |