@@ -14,82 +14,82 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class DERData extends Element |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * DER encoded data. |
|
| 19 | - * |
|
| 20 | - * @var string $_der |
|
| 21 | - */ |
|
| 22 | - protected $_der; |
|
| 17 | + /** |
|
| 18 | + * DER encoded data. |
|
| 19 | + * |
|
| 20 | + * @var string $_der |
|
| 21 | + */ |
|
| 22 | + protected $_der; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Identifier of the underlying type. |
|
| 26 | - * |
|
| 27 | - * @var Identifier $_identifier |
|
| 28 | - */ |
|
| 29 | - protected $_identifier; |
|
| 24 | + /** |
|
| 25 | + * Identifier of the underlying type. |
|
| 26 | + * |
|
| 27 | + * @var Identifier $_identifier |
|
| 28 | + */ |
|
| 29 | + protected $_identifier; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Offset to the content in DER data. |
|
| 33 | - * |
|
| 34 | - * @var int $_contentOffset |
|
| 35 | - */ |
|
| 36 | - protected $_contentOffset = 0; |
|
| 31 | + /** |
|
| 32 | + * Offset to the content in DER data. |
|
| 33 | + * |
|
| 34 | + * @var int $_contentOffset |
|
| 35 | + */ |
|
| 36 | + protected $_contentOffset = 0; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Constructor. |
|
| 40 | - * |
|
| 41 | - * @param string $data DER encoded data |
|
| 42 | - * @throws \ASN1\Exception\DecodeException If data does not adhere to DER |
|
| 43 | - */ |
|
| 44 | - public function __construct(string $data) |
|
| 45 | - { |
|
| 46 | - $this->_identifier = Identifier::fromDER($data, $this->_contentOffset); |
|
| 47 | - Length::expectFromDER($data, $this->_contentOffset); |
|
| 48 | - $this->_der = $data; |
|
| 49 | - $this->_typeTag = $this->_identifier->intTag(); |
|
| 50 | - } |
|
| 38 | + /** |
|
| 39 | + * Constructor. |
|
| 40 | + * |
|
| 41 | + * @param string $data DER encoded data |
|
| 42 | + * @throws \ASN1\Exception\DecodeException If data does not adhere to DER |
|
| 43 | + */ |
|
| 44 | + public function __construct(string $data) |
|
| 45 | + { |
|
| 46 | + $this->_identifier = Identifier::fromDER($data, $this->_contentOffset); |
|
| 47 | + Length::expectFromDER($data, $this->_contentOffset); |
|
| 48 | + $this->_der = $data; |
|
| 49 | + $this->_typeTag = $this->_identifier->intTag(); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * |
|
| 54 | - * @see \ASN1\Element::typeClass() |
|
| 55 | - * @return int |
|
| 56 | - */ |
|
| 57 | - public function typeClass(): int |
|
| 58 | - { |
|
| 59 | - return $this->_identifier->typeClass(); |
|
| 60 | - } |
|
| 52 | + /** |
|
| 53 | + * |
|
| 54 | + * @see \ASN1\Element::typeClass() |
|
| 55 | + * @return int |
|
| 56 | + */ |
|
| 57 | + public function typeClass(): int |
|
| 58 | + { |
|
| 59 | + return $this->_identifier->typeClass(); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * |
|
| 64 | - * @see \ASN1\Element::isConstructed() |
|
| 65 | - * @return bool |
|
| 66 | - */ |
|
| 67 | - public function isConstructed(): bool |
|
| 68 | - { |
|
| 69 | - return $this->_identifier->isConstructed(); |
|
| 70 | - } |
|
| 62 | + /** |
|
| 63 | + * |
|
| 64 | + * @see \ASN1\Element::isConstructed() |
|
| 65 | + * @return bool |
|
| 66 | + */ |
|
| 67 | + public function isConstructed(): bool |
|
| 68 | + { |
|
| 69 | + return $this->_identifier->isConstructed(); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * |
|
| 74 | - * @see \ASN1\Element::_encodedContentDER() |
|
| 75 | - * @return string |
|
| 76 | - */ |
|
| 77 | - protected function _encodedContentDER(): string |
|
| 78 | - { |
|
| 79 | - // if there's no content payload |
|
| 80 | - if (strlen($this->_der) == $this->_contentOffset) { |
|
| 81 | - return ""; |
|
| 82 | - } |
|
| 83 | - return substr($this->_der, $this->_contentOffset); |
|
| 84 | - } |
|
| 72 | + /** |
|
| 73 | + * |
|
| 74 | + * @see \ASN1\Element::_encodedContentDER() |
|
| 75 | + * @return string |
|
| 76 | + */ |
|
| 77 | + protected function _encodedContentDER(): string |
|
| 78 | + { |
|
| 79 | + // if there's no content payload |
|
| 80 | + if (strlen($this->_der) == $this->_contentOffset) { |
|
| 81 | + return ""; |
|
| 82 | + } |
|
| 83 | + return substr($this->_der, $this->_contentOffset); |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * |
|
| 88 | - * @see \ASN1\Element::toDER() |
|
| 89 | - * @return string |
|
| 90 | - */ |
|
| 91 | - public function toDER(): string |
|
| 92 | - { |
|
| 93 | - return $this->_der; |
|
| 94 | - } |
|
| 86 | + /** |
|
| 87 | + * |
|
| 88 | + * @see \ASN1\Element::toDER() |
|
| 89 | + * @return string |
|
| 90 | + */ |
|
| 91 | + public function toDER(): string |
|
| 92 | + { |
|
| 93 | + return $this->_der; |
|
| 94 | + } |
|
| 95 | 95 | } |
@@ -17,194 +17,194 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class BitString extends StringType |
| 19 | 19 | { |
| 20 | - use UniversalClass; |
|
| 21 | - use PrimitiveType; |
|
| 20 | + use UniversalClass; |
|
| 21 | + use PrimitiveType; |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Number of unused bits in the last octet. |
|
| 25 | - * |
|
| 26 | - * @var int $_unusedBits |
|
| 27 | - */ |
|
| 28 | - protected $_unusedBits; |
|
| 23 | + /** |
|
| 24 | + * Number of unused bits in the last octet. |
|
| 25 | + * |
|
| 26 | + * @var int $_unusedBits |
|
| 27 | + */ |
|
| 28 | + protected $_unusedBits; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Constructor. |
|
| 32 | - * |
|
| 33 | - * @param string $string Content octets |
|
| 34 | - * @param int $unused_bits Number of unused bits in the last octet |
|
| 35 | - */ |
|
| 36 | - public function __construct(string $string, int $unused_bits = 0) |
|
| 37 | - { |
|
| 38 | - $this->_typeTag = self::TYPE_BIT_STRING; |
|
| 39 | - parent::__construct($string); |
|
| 40 | - $this->_unusedBits = $unused_bits; |
|
| 41 | - } |
|
| 30 | + /** |
|
| 31 | + * Constructor. |
|
| 32 | + * |
|
| 33 | + * @param string $string Content octets |
|
| 34 | + * @param int $unused_bits Number of unused bits in the last octet |
|
| 35 | + */ |
|
| 36 | + public function __construct(string $string, int $unused_bits = 0) |
|
| 37 | + { |
|
| 38 | + $this->_typeTag = self::TYPE_BIT_STRING; |
|
| 39 | + parent::__construct($string); |
|
| 40 | + $this->_unusedBits = $unused_bits; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Get the number of bits in the string. |
|
| 45 | - * |
|
| 46 | - * @return int |
|
| 47 | - */ |
|
| 48 | - public function numBits(): int |
|
| 49 | - { |
|
| 50 | - return strlen($this->_string) * 8 - $this->_unusedBits; |
|
| 51 | - } |
|
| 43 | + /** |
|
| 44 | + * Get the number of bits in the string. |
|
| 45 | + * |
|
| 46 | + * @return int |
|
| 47 | + */ |
|
| 48 | + public function numBits(): int |
|
| 49 | + { |
|
| 50 | + return strlen($this->_string) * 8 - $this->_unusedBits; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Get the number of unused bits in the last octet of the string. |
|
| 55 | - * |
|
| 56 | - * @return int |
|
| 57 | - */ |
|
| 58 | - public function unusedBits(): int |
|
| 59 | - { |
|
| 60 | - return $this->_unusedBits; |
|
| 61 | - } |
|
| 53 | + /** |
|
| 54 | + * Get the number of unused bits in the last octet of the string. |
|
| 55 | + * |
|
| 56 | + * @return int |
|
| 57 | + */ |
|
| 58 | + public function unusedBits(): int |
|
| 59 | + { |
|
| 60 | + return $this->_unusedBits; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * Test whether bit is set. |
|
| 65 | - * |
|
| 66 | - * @param int $idx Bit index. |
|
| 67 | - * Most significant bit of the first octet is index 0. |
|
| 68 | - * @return boolean |
|
| 69 | - */ |
|
| 70 | - public function testBit(int $idx): bool |
|
| 71 | - { |
|
| 72 | - // octet index |
|
| 73 | - $oi = (int) floor($idx / 8); |
|
| 74 | - // if octet is outside range |
|
| 75 | - if ($oi < 0 || $oi >= strlen($this->_string)) { |
|
| 76 | - throw new \OutOfBoundsException("Index is out of bounds."); |
|
| 77 | - } |
|
| 78 | - // bit index |
|
| 79 | - $bi = $idx % 8; |
|
| 80 | - // if tested bit is last octet's unused bit |
|
| 81 | - if ($oi == strlen($this->_string) - 1) { |
|
| 82 | - if ($bi >= 8 - $this->_unusedBits) { |
|
| 83 | - throw new \OutOfBoundsException("Index refers to an unused bit."); |
|
| 84 | - } |
|
| 85 | - } |
|
| 86 | - $byte = $this->_string[$oi]; |
|
| 87 | - // index 0 is the most significant bit in byte |
|
| 88 | - $mask = 0x01 << (7 - $bi); |
|
| 89 | - return (ord($byte) & $mask) > 0; |
|
| 90 | - } |
|
| 63 | + /** |
|
| 64 | + * Test whether bit is set. |
|
| 65 | + * |
|
| 66 | + * @param int $idx Bit index. |
|
| 67 | + * Most significant bit of the first octet is index 0. |
|
| 68 | + * @return boolean |
|
| 69 | + */ |
|
| 70 | + public function testBit(int $idx): bool |
|
| 71 | + { |
|
| 72 | + // octet index |
|
| 73 | + $oi = (int) floor($idx / 8); |
|
| 74 | + // if octet is outside range |
|
| 75 | + if ($oi < 0 || $oi >= strlen($this->_string)) { |
|
| 76 | + throw new \OutOfBoundsException("Index is out of bounds."); |
|
| 77 | + } |
|
| 78 | + // bit index |
|
| 79 | + $bi = $idx % 8; |
|
| 80 | + // if tested bit is last octet's unused bit |
|
| 81 | + if ($oi == strlen($this->_string) - 1) { |
|
| 82 | + if ($bi >= 8 - $this->_unusedBits) { |
|
| 83 | + throw new \OutOfBoundsException("Index refers to an unused bit."); |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | + $byte = $this->_string[$oi]; |
|
| 87 | + // index 0 is the most significant bit in byte |
|
| 88 | + $mask = 0x01 << (7 - $bi); |
|
| 89 | + return (ord($byte) & $mask) > 0; |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * Get range of bits. |
|
| 94 | - * |
|
| 95 | - * @param int $start Index of first bit |
|
| 96 | - * @param int $length Number of bits in range |
|
| 97 | - * @throws \OutOfBoundsException |
|
| 98 | - * @return string Integer of $length bits |
|
| 99 | - */ |
|
| 100 | - public function range(int $start, int $length): string |
|
| 101 | - { |
|
| 102 | - if (!$length) { |
|
| 103 | - return "0"; |
|
| 104 | - } |
|
| 105 | - if ($start + $length > $this->numBits()) { |
|
| 106 | - throw new \OutOfBoundsException("Not enough bits."); |
|
| 107 | - } |
|
| 108 | - $bits = gmp_init(0); |
|
| 109 | - $idx = $start; |
|
| 110 | - $end = $start + $length; |
|
| 111 | - while (true) { |
|
| 112 | - $bit = $this->testBit($idx) ? 1 : 0; |
|
| 113 | - $bits |= $bit; |
|
| 114 | - if (++$idx >= $end) { |
|
| 115 | - break; |
|
| 116 | - } |
|
| 117 | - $bits <<= 1; |
|
| 118 | - } |
|
| 119 | - return gmp_strval($bits, 10); |
|
| 120 | - } |
|
| 92 | + /** |
|
| 93 | + * Get range of bits. |
|
| 94 | + * |
|
| 95 | + * @param int $start Index of first bit |
|
| 96 | + * @param int $length Number of bits in range |
|
| 97 | + * @throws \OutOfBoundsException |
|
| 98 | + * @return string Integer of $length bits |
|
| 99 | + */ |
|
| 100 | + public function range(int $start, int $length): string |
|
| 101 | + { |
|
| 102 | + if (!$length) { |
|
| 103 | + return "0"; |
|
| 104 | + } |
|
| 105 | + if ($start + $length > $this->numBits()) { |
|
| 106 | + throw new \OutOfBoundsException("Not enough bits."); |
|
| 107 | + } |
|
| 108 | + $bits = gmp_init(0); |
|
| 109 | + $idx = $start; |
|
| 110 | + $end = $start + $length; |
|
| 111 | + while (true) { |
|
| 112 | + $bit = $this->testBit($idx) ? 1 : 0; |
|
| 113 | + $bits |= $bit; |
|
| 114 | + if (++$idx >= $end) { |
|
| 115 | + break; |
|
| 116 | + } |
|
| 117 | + $bits <<= 1; |
|
| 118 | + } |
|
| 119 | + return gmp_strval($bits, 10); |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * Get a copy of the bit string with trailing zeroes removed. |
|
| 124 | - * |
|
| 125 | - * @return self |
|
| 126 | - */ |
|
| 127 | - public function withoutTrailingZeroes(): self |
|
| 128 | - { |
|
| 129 | - // if bit string was empty |
|
| 130 | - if (!strlen($this->_string)) { |
|
| 131 | - return new self(""); |
|
| 132 | - } |
|
| 133 | - $bits = $this->_string; |
|
| 134 | - // count number of empty trailing octets |
|
| 135 | - $unused_octets = 0; |
|
| 136 | - for ($idx = strlen($bits) - 1; $idx >= 0; --$idx, ++$unused_octets) { |
|
| 137 | - if ($bits[$idx] != "\x0") { |
|
| 138 | - break; |
|
| 139 | - } |
|
| 140 | - } |
|
| 141 | - // strip trailing octets |
|
| 142 | - if ($unused_octets) { |
|
| 143 | - $bits = substr($bits, 0, -$unused_octets); |
|
| 144 | - } |
|
| 145 | - // if bit string was full of zeroes |
|
| 146 | - if (!strlen($bits)) { |
|
| 147 | - return new self(""); |
|
| 148 | - } |
|
| 149 | - // count number of trailing zeroes in the last octet |
|
| 150 | - $unused_bits = 0; |
|
| 151 | - $byte = ord($bits[strlen($bits) - 1]); |
|
| 152 | - while (!($byte & 0x01)) { |
|
| 153 | - $unused_bits++; |
|
| 154 | - $byte >>= 1; |
|
| 155 | - } |
|
| 156 | - return new self($bits, $unused_bits); |
|
| 157 | - } |
|
| 122 | + /** |
|
| 123 | + * Get a copy of the bit string with trailing zeroes removed. |
|
| 124 | + * |
|
| 125 | + * @return self |
|
| 126 | + */ |
|
| 127 | + public function withoutTrailingZeroes(): self |
|
| 128 | + { |
|
| 129 | + // if bit string was empty |
|
| 130 | + if (!strlen($this->_string)) { |
|
| 131 | + return new self(""); |
|
| 132 | + } |
|
| 133 | + $bits = $this->_string; |
|
| 134 | + // count number of empty trailing octets |
|
| 135 | + $unused_octets = 0; |
|
| 136 | + for ($idx = strlen($bits) - 1; $idx >= 0; --$idx, ++$unused_octets) { |
|
| 137 | + if ($bits[$idx] != "\x0") { |
|
| 138 | + break; |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | + // strip trailing octets |
|
| 142 | + if ($unused_octets) { |
|
| 143 | + $bits = substr($bits, 0, -$unused_octets); |
|
| 144 | + } |
|
| 145 | + // if bit string was full of zeroes |
|
| 146 | + if (!strlen($bits)) { |
|
| 147 | + return new self(""); |
|
| 148 | + } |
|
| 149 | + // count number of trailing zeroes in the last octet |
|
| 150 | + $unused_bits = 0; |
|
| 151 | + $byte = ord($bits[strlen($bits) - 1]); |
|
| 152 | + while (!($byte & 0x01)) { |
|
| 153 | + $unused_bits++; |
|
| 154 | + $byte >>= 1; |
|
| 155 | + } |
|
| 156 | + return new self($bits, $unused_bits); |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | - /** |
|
| 160 | - * |
|
| 161 | - * {@inheritdoc} |
|
| 162 | - */ |
|
| 163 | - protected function _encodedContentDER(): string |
|
| 164 | - { |
|
| 165 | - $der = chr($this->_unusedBits); |
|
| 166 | - $der .= $this->_string; |
|
| 167 | - if ($this->_unusedBits) { |
|
| 168 | - $octet = $der[strlen($der) - 1]; |
|
| 169 | - // set unused bits to zero |
|
| 170 | - $octet &= chr(0xff & ~((1 << $this->_unusedBits) - 1)); |
|
| 171 | - $der[strlen($der) - 1] = $octet; |
|
| 172 | - } |
|
| 173 | - return $der; |
|
| 174 | - } |
|
| 159 | + /** |
|
| 160 | + * |
|
| 161 | + * {@inheritdoc} |
|
| 162 | + */ |
|
| 163 | + protected function _encodedContentDER(): string |
|
| 164 | + { |
|
| 165 | + $der = chr($this->_unusedBits); |
|
| 166 | + $der .= $this->_string; |
|
| 167 | + if ($this->_unusedBits) { |
|
| 168 | + $octet = $der[strlen($der) - 1]; |
|
| 169 | + // set unused bits to zero |
|
| 170 | + $octet &= chr(0xff & ~((1 << $this->_unusedBits) - 1)); |
|
| 171 | + $der[strlen($der) - 1] = $octet; |
|
| 172 | + } |
|
| 173 | + return $der; |
|
| 174 | + } |
|
| 175 | 175 | |
| 176 | - /** |
|
| 177 | - * |
|
| 178 | - * {@inheritdoc} |
|
| 179 | - * @return self |
|
| 180 | - */ |
|
| 181 | - protected static function _decodeFromDER(Identifier $identifier, string $data, |
|
| 182 | - int &$offset): ElementBase |
|
| 183 | - { |
|
| 184 | - $idx = $offset; |
|
| 185 | - $length = Length::expectFromDER($data, $idx); |
|
| 186 | - if ($length->intLength() < 1) { |
|
| 187 | - throw new DecodeException("Bit string length must be at least 1."); |
|
| 188 | - } |
|
| 189 | - $unused_bits = ord($data[$idx++]); |
|
| 190 | - if ($unused_bits > 7) { |
|
| 191 | - throw new DecodeException( |
|
| 192 | - "Unused bits in a bit string must be less than 8."); |
|
| 193 | - } |
|
| 194 | - $str_len = $length->intLength() - 1; |
|
| 195 | - if ($str_len) { |
|
| 196 | - $str = substr($data, $idx, $str_len); |
|
| 197 | - if ($unused_bits) { |
|
| 198 | - $mask = (1 << $unused_bits) - 1; |
|
| 199 | - if (ord($str[strlen($str) - 1]) & $mask) { |
|
| 200 | - throw new DecodeException( |
|
| 201 | - "DER encoded bit string must have zero padding."); |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - } else { |
|
| 205 | - $str = ""; |
|
| 206 | - } |
|
| 207 | - $offset = $idx + $str_len; |
|
| 208 | - return new self($str, $unused_bits); |
|
| 209 | - } |
|
| 176 | + /** |
|
| 177 | + * |
|
| 178 | + * {@inheritdoc} |
|
| 179 | + * @return self |
|
| 180 | + */ |
|
| 181 | + protected static function _decodeFromDER(Identifier $identifier, string $data, |
|
| 182 | + int &$offset): ElementBase |
|
| 183 | + { |
|
| 184 | + $idx = $offset; |
|
| 185 | + $length = Length::expectFromDER($data, $idx); |
|
| 186 | + if ($length->intLength() < 1) { |
|
| 187 | + throw new DecodeException("Bit string length must be at least 1."); |
|
| 188 | + } |
|
| 189 | + $unused_bits = ord($data[$idx++]); |
|
| 190 | + if ($unused_bits > 7) { |
|
| 191 | + throw new DecodeException( |
|
| 192 | + "Unused bits in a bit string must be less than 8."); |
|
| 193 | + } |
|
| 194 | + $str_len = $length->intLength() - 1; |
|
| 195 | + if ($str_len) { |
|
| 196 | + $str = substr($data, $idx, $str_len); |
|
| 197 | + if ($unused_bits) { |
|
| 198 | + $mask = (1 << $unused_bits) - 1; |
|
| 199 | + if (ord($str[strlen($str) - 1]) & $mask) { |
|
| 200 | + throw new DecodeException( |
|
| 201 | + "DER encoded bit string must have zero padding."); |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + } else { |
|
| 205 | + $str = ""; |
|
| 206 | + } |
|
| 207 | + $offset = $idx + $str_len; |
|
| 208 | + return new self($str, $unused_bits); |
|
| 209 | + } |
|
| 210 | 210 | } |
@@ -17,160 +17,160 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class ObjectIdentifier extends Element |
| 19 | 19 | { |
| 20 | - use UniversalClass; |
|
| 21 | - use PrimitiveType; |
|
| 20 | + use UniversalClass; |
|
| 21 | + use PrimitiveType; |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Object identifier in dotted format. |
|
| 25 | - * |
|
| 26 | - * @var string |
|
| 27 | - */ |
|
| 28 | - protected $_oid; |
|
| 23 | + /** |
|
| 24 | + * Object identifier in dotted format. |
|
| 25 | + * |
|
| 26 | + * @var string |
|
| 27 | + */ |
|
| 28 | + protected $_oid; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Constructor. |
|
| 32 | - * |
|
| 33 | - * @param string $oid OID in dotted format |
|
| 34 | - */ |
|
| 35 | - public function __construct(string $oid) |
|
| 36 | - { |
|
| 37 | - $this->_oid = $oid; |
|
| 38 | - $this->_typeTag = self::TYPE_OBJECT_IDENTIFIER; |
|
| 39 | - } |
|
| 30 | + /** |
|
| 31 | + * Constructor. |
|
| 32 | + * |
|
| 33 | + * @param string $oid OID in dotted format |
|
| 34 | + */ |
|
| 35 | + public function __construct(string $oid) |
|
| 36 | + { |
|
| 37 | + $this->_oid = $oid; |
|
| 38 | + $this->_typeTag = self::TYPE_OBJECT_IDENTIFIER; |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Get OID in dotted format. |
|
| 43 | - * |
|
| 44 | - * @return string |
|
| 45 | - */ |
|
| 46 | - public function oid(): string |
|
| 47 | - { |
|
| 48 | - return $this->_oid; |
|
| 49 | - } |
|
| 41 | + /** |
|
| 42 | + * Get OID in dotted format. |
|
| 43 | + * |
|
| 44 | + * @return string |
|
| 45 | + */ |
|
| 46 | + public function oid(): string |
|
| 47 | + { |
|
| 48 | + return $this->_oid; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * |
|
| 53 | - * {@inheritdoc} |
|
| 54 | - */ |
|
| 55 | - protected function _encodedContentDER(): string |
|
| 56 | - { |
|
| 57 | - $subids = self::_explodeDottedOID($this->_oid); |
|
| 58 | - // encode first two subids to one according to spec section 8.19.4 |
|
| 59 | - if (count($subids) >= 2) { |
|
| 60 | - $num = ($subids[0] * 40) + $subids[1]; |
|
| 61 | - array_splice($subids, 0, 2, array($num)); |
|
| 62 | - } |
|
| 63 | - return self::_encodeSubIDs(...$subids); |
|
| 64 | - } |
|
| 51 | + /** |
|
| 52 | + * |
|
| 53 | + * {@inheritdoc} |
|
| 54 | + */ |
|
| 55 | + protected function _encodedContentDER(): string |
|
| 56 | + { |
|
| 57 | + $subids = self::_explodeDottedOID($this->_oid); |
|
| 58 | + // encode first two subids to one according to spec section 8.19.4 |
|
| 59 | + if (count($subids) >= 2) { |
|
| 60 | + $num = ($subids[0] * 40) + $subids[1]; |
|
| 61 | + array_splice($subids, 0, 2, array($num)); |
|
| 62 | + } |
|
| 63 | + return self::_encodeSubIDs(...$subids); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * |
|
| 68 | - * {@inheritdoc} |
|
| 69 | - * @return self |
|
| 70 | - */ |
|
| 71 | - protected static function _decodeFromDER(Identifier $identifier, string $data, |
|
| 72 | - int &$offset): ElementBase |
|
| 73 | - { |
|
| 74 | - $idx = $offset; |
|
| 75 | - $len = Length::expectFromDER($data, $idx)->intLength(); |
|
| 76 | - $subids = self::_decodeSubIDs(substr($data, $idx, $len)); |
|
| 77 | - $idx += $len; |
|
| 78 | - // decode first subidentifier according to spec section 8.19.4 |
|
| 79 | - if (isset($subids[0])) { |
|
| 80 | - list($x, $y) = gmp_div_qr($subids[0], "40"); |
|
| 81 | - array_splice($subids, 0, 1, array($x, $y)); |
|
| 82 | - } |
|
| 83 | - $offset = $idx; |
|
| 84 | - return new self(self::_implodeSubIDs(...$subids)); |
|
| 85 | - } |
|
| 66 | + /** |
|
| 67 | + * |
|
| 68 | + * {@inheritdoc} |
|
| 69 | + * @return self |
|
| 70 | + */ |
|
| 71 | + protected static function _decodeFromDER(Identifier $identifier, string $data, |
|
| 72 | + int &$offset): ElementBase |
|
| 73 | + { |
|
| 74 | + $idx = $offset; |
|
| 75 | + $len = Length::expectFromDER($data, $idx)->intLength(); |
|
| 76 | + $subids = self::_decodeSubIDs(substr($data, $idx, $len)); |
|
| 77 | + $idx += $len; |
|
| 78 | + // decode first subidentifier according to spec section 8.19.4 |
|
| 79 | + if (isset($subids[0])) { |
|
| 80 | + list($x, $y) = gmp_div_qr($subids[0], "40"); |
|
| 81 | + array_splice($subids, 0, 1, array($x, $y)); |
|
| 82 | + } |
|
| 83 | + $offset = $idx; |
|
| 84 | + return new self(self::_implodeSubIDs(...$subids)); |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * Explode dotted OID to an array of sub ID's. |
|
| 89 | - * |
|
| 90 | - * @param string $oid OID in dotted format |
|
| 91 | - * @return \GMP[] Array of GMP numbers |
|
| 92 | - */ |
|
| 93 | - protected static function _explodeDottedOID(string $oid): array |
|
| 94 | - { |
|
| 95 | - $subids = []; |
|
| 96 | - foreach (explode(".", $oid) as $subid) { |
|
| 97 | - $subids[] = gmp_init($subid, 10); |
|
| 98 | - } |
|
| 99 | - return $subids; |
|
| 100 | - } |
|
| 87 | + /** |
|
| 88 | + * Explode dotted OID to an array of sub ID's. |
|
| 89 | + * |
|
| 90 | + * @param string $oid OID in dotted format |
|
| 91 | + * @return \GMP[] Array of GMP numbers |
|
| 92 | + */ |
|
| 93 | + protected static function _explodeDottedOID(string $oid): array |
|
| 94 | + { |
|
| 95 | + $subids = []; |
|
| 96 | + foreach (explode(".", $oid) as $subid) { |
|
| 97 | + $subids[] = gmp_init($subid, 10); |
|
| 98 | + } |
|
| 99 | + return $subids; |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - /** |
|
| 103 | - * Implode an array of sub IDs to dotted OID format. |
|
| 104 | - * |
|
| 105 | - * @param \GMP[] $subids |
|
| 106 | - * @return string |
|
| 107 | - */ |
|
| 108 | - protected static function _implodeSubIDs(\GMP ...$subids): string |
|
| 109 | - { |
|
| 110 | - return implode(".", |
|
| 111 | - array_map( |
|
| 112 | - function ($num) { |
|
| 113 | - return gmp_strval($num, 10); |
|
| 114 | - }, $subids)); |
|
| 115 | - } |
|
| 102 | + /** |
|
| 103 | + * Implode an array of sub IDs to dotted OID format. |
|
| 104 | + * |
|
| 105 | + * @param \GMP[] $subids |
|
| 106 | + * @return string |
|
| 107 | + */ |
|
| 108 | + protected static function _implodeSubIDs(\GMP ...$subids): string |
|
| 109 | + { |
|
| 110 | + return implode(".", |
|
| 111 | + array_map( |
|
| 112 | + function ($num) { |
|
| 113 | + return gmp_strval($num, 10); |
|
| 114 | + }, $subids)); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * Encode sub ID's to DER. |
|
| 119 | - * |
|
| 120 | - * @param \GMP[] $subids |
|
| 121 | - * @return string |
|
| 122 | - */ |
|
| 123 | - protected static function _encodeSubIDs(\GMP ...$subids): string |
|
| 124 | - { |
|
| 125 | - $data = ""; |
|
| 126 | - foreach ($subids as $subid) { |
|
| 127 | - // if number fits to one base 128 byte |
|
| 128 | - if ($subid < 128) { |
|
| 129 | - $data .= chr(intval($subid)); |
|
| 130 | - } else { // encode to multiple bytes |
|
| 131 | - $bytes = []; |
|
| 132 | - do { |
|
| 133 | - array_unshift($bytes, 0x7f & gmp_intval($subid)); |
|
| 134 | - $subid >>= 7; |
|
| 135 | - } while ($subid > 0); |
|
| 136 | - // all bytes except last must have bit 8 set to one |
|
| 137 | - foreach (array_splice($bytes, 0, -1) as $byte) { |
|
| 138 | - $data .= chr(0x80 | $byte); |
|
| 139 | - } |
|
| 140 | - $data .= chr(reset($bytes)); |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - return $data; |
|
| 144 | - } |
|
| 117 | + /** |
|
| 118 | + * Encode sub ID's to DER. |
|
| 119 | + * |
|
| 120 | + * @param \GMP[] $subids |
|
| 121 | + * @return string |
|
| 122 | + */ |
|
| 123 | + protected static function _encodeSubIDs(\GMP ...$subids): string |
|
| 124 | + { |
|
| 125 | + $data = ""; |
|
| 126 | + foreach ($subids as $subid) { |
|
| 127 | + // if number fits to one base 128 byte |
|
| 128 | + if ($subid < 128) { |
|
| 129 | + $data .= chr(intval($subid)); |
|
| 130 | + } else { // encode to multiple bytes |
|
| 131 | + $bytes = []; |
|
| 132 | + do { |
|
| 133 | + array_unshift($bytes, 0x7f & gmp_intval($subid)); |
|
| 134 | + $subid >>= 7; |
|
| 135 | + } while ($subid > 0); |
|
| 136 | + // all bytes except last must have bit 8 set to one |
|
| 137 | + foreach (array_splice($bytes, 0, -1) as $byte) { |
|
| 138 | + $data .= chr(0x80 | $byte); |
|
| 139 | + } |
|
| 140 | + $data .= chr(reset($bytes)); |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + return $data; |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | - /** |
|
| 147 | - * Decode sub ID's from DER data. |
|
| 148 | - * |
|
| 149 | - * @param string $data |
|
| 150 | - * @throws DecodeException |
|
| 151 | - * @return \GMP[] Array of GMP numbers |
|
| 152 | - */ |
|
| 153 | - protected static function _decodeSubIDs(string $data): array |
|
| 154 | - { |
|
| 155 | - $subids = []; |
|
| 156 | - $idx = 0; |
|
| 157 | - $end = strlen($data); |
|
| 158 | - while ($idx < $end) { |
|
| 159 | - $num = gmp_init("0", 10); |
|
| 160 | - while (true) { |
|
| 161 | - if ($idx >= $end) { |
|
| 162 | - throw new DecodeException("Unexpected end of data."); |
|
| 163 | - } |
|
| 164 | - $byte = ord($data[$idx++]); |
|
| 165 | - $num |= $byte & 0x7f; |
|
| 166 | - // bit 8 of the last octet is zero |
|
| 167 | - if (!($byte & 0x80)) { |
|
| 168 | - break; |
|
| 169 | - } |
|
| 170 | - $num <<= 7; |
|
| 171 | - } |
|
| 172 | - $subids[] = $num; |
|
| 173 | - } |
|
| 174 | - return $subids; |
|
| 175 | - } |
|
| 146 | + /** |
|
| 147 | + * Decode sub ID's from DER data. |
|
| 148 | + * |
|
| 149 | + * @param string $data |
|
| 150 | + * @throws DecodeException |
|
| 151 | + * @return \GMP[] Array of GMP numbers |
|
| 152 | + */ |
|
| 153 | + protected static function _decodeSubIDs(string $data): array |
|
| 154 | + { |
|
| 155 | + $subids = []; |
|
| 156 | + $idx = 0; |
|
| 157 | + $end = strlen($data); |
|
| 158 | + while ($idx < $end) { |
|
| 159 | + $num = gmp_init("0", 10); |
|
| 160 | + while (true) { |
|
| 161 | + if ($idx >= $end) { |
|
| 162 | + throw new DecodeException("Unexpected end of data."); |
|
| 163 | + } |
|
| 164 | + $byte = ord($data[$idx++]); |
|
| 165 | + $num |= $byte & 0x7f; |
|
| 166 | + // bit 8 of the last octet is zero |
|
| 167 | + if (!($byte & 0x80)) { |
|
| 168 | + break; |
|
| 169 | + } |
|
| 170 | + $num <<= 7; |
|
| 171 | + } |
|
| 172 | + $subids[] = $num; |
|
| 173 | + } |
|
| 174 | + return $subids; |
|
| 175 | + } |
|
| 176 | 176 | } |
@@ -17,613 +17,613 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class UnspecifiedType implements ElementBase |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * The wrapped element. |
|
| 22 | - * |
|
| 23 | - * @var Element |
|
| 24 | - */ |
|
| 25 | - private $_element; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * Constructor. |
|
| 29 | - * |
|
| 30 | - * @param Element $el |
|
| 31 | - */ |
|
| 32 | - public function __construct(Element $el) |
|
| 33 | - { |
|
| 34 | - $this->_element = $el; |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Initialize from ElementBase interface. |
|
| 39 | - * |
|
| 40 | - * @param ElementBase $el |
|
| 41 | - * @return self |
|
| 42 | - */ |
|
| 43 | - public static function fromElementBase(ElementBase $el): self |
|
| 44 | - { |
|
| 45 | - // if element is already wrapped |
|
| 46 | - if ($el instanceof self) { |
|
| 47 | - return $el; |
|
| 48 | - } |
|
| 49 | - return new self($el->asElement()); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * Compatibility method to dispatch calls to the wrapped element. |
|
| 54 | - * |
|
| 55 | - * @deprecated Use <code>as*</code> accessor methods to ensure strict type |
|
| 56 | - * @param string $mtd Method name |
|
| 57 | - * @param array $args Arguments |
|
| 58 | - * @return mixed |
|
| 59 | - */ |
|
| 60 | - public function __call($mtd, array $args) |
|
| 61 | - { |
|
| 62 | - return call_user_func_array([$this->_element, $mtd], $args); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Get the wrapped element as a context specific tagged type. |
|
| 67 | - * |
|
| 68 | - * @throws \UnexpectedValueException If the element is not tagged |
|
| 69 | - * @return TaggedType |
|
| 70 | - */ |
|
| 71 | - public function asTagged(): TaggedType |
|
| 72 | - { |
|
| 73 | - if (!$this->_element instanceof TaggedType) { |
|
| 74 | - throw new \UnexpectedValueException( |
|
| 75 | - "Tagged element expected, got " . $this->_typeDescriptorString()); |
|
| 76 | - } |
|
| 77 | - return $this->_element; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Get the wrapped element as a boolean type. |
|
| 82 | - * |
|
| 83 | - * @throws \UnexpectedValueException If the element is not a boolean |
|
| 84 | - * @return Primitive\Boolean |
|
| 85 | - */ |
|
| 86 | - public function asBoolean(): Primitive\Boolean |
|
| 87 | - { |
|
| 88 | - if (!$this->_element instanceof Primitive\Boolean) { |
|
| 89 | - throw new \UnexpectedValueException( |
|
| 90 | - $this->_generateExceptionMessage(Element::TYPE_BOOLEAN)); |
|
| 91 | - } |
|
| 92 | - return $this->_element; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Get the wrapped element as an integer type. |
|
| 97 | - * |
|
| 98 | - * @throws \UnexpectedValueException If the element is not an integer |
|
| 99 | - * @return Primitive\Integer |
|
| 100 | - */ |
|
| 101 | - public function asInteger(): Primitive\Integer |
|
| 102 | - { |
|
| 103 | - if (!$this->_element instanceof Primitive\Integer) { |
|
| 104 | - throw new \UnexpectedValueException( |
|
| 105 | - $this->_generateExceptionMessage(Element::TYPE_INTEGER)); |
|
| 106 | - } |
|
| 107 | - return $this->_element; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Get the wrapped element as a bit string type. |
|
| 112 | - * |
|
| 113 | - * @throws \UnexpectedValueException If the element is not a bit string |
|
| 114 | - * @return Primitive\BitString |
|
| 115 | - */ |
|
| 116 | - public function asBitString(): Primitive\BitString |
|
| 117 | - { |
|
| 118 | - if (!$this->_element instanceof Primitive\BitString) { |
|
| 119 | - throw new \UnexpectedValueException( |
|
| 120 | - $this->_generateExceptionMessage(Element::TYPE_BIT_STRING)); |
|
| 121 | - } |
|
| 122 | - return $this->_element; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * Get the wrapped element as an octet string type. |
|
| 127 | - * |
|
| 128 | - * @throws \UnexpectedValueException If the element is not an octet string |
|
| 129 | - * @return Primitive\OctetString |
|
| 130 | - */ |
|
| 131 | - public function asOctetString(): Primitive\OctetString |
|
| 132 | - { |
|
| 133 | - if (!$this->_element instanceof Primitive\OctetString) { |
|
| 134 | - throw new \UnexpectedValueException( |
|
| 135 | - $this->_generateExceptionMessage(Element::TYPE_OCTET_STRING)); |
|
| 136 | - } |
|
| 137 | - return $this->_element; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Get the wrapped element as a null type. |
|
| 142 | - * |
|
| 143 | - * @throws \UnexpectedValueException If the element is not a null |
|
| 144 | - * @return Primitive\NullType |
|
| 145 | - */ |
|
| 146 | - public function asNull(): Primitive\NullType |
|
| 147 | - { |
|
| 148 | - if (!$this->_element instanceof Primitive\NullType) { |
|
| 149 | - throw new \UnexpectedValueException( |
|
| 150 | - $this->_generateExceptionMessage(Element::TYPE_NULL)); |
|
| 151 | - } |
|
| 152 | - return $this->_element; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Get the wrapped element as an object identifier type. |
|
| 157 | - * |
|
| 158 | - * @throws \UnexpectedValueException If the element is not an object |
|
| 159 | - * identifier |
|
| 160 | - * @return Primitive\ObjectIdentifier |
|
| 161 | - */ |
|
| 162 | - public function asObjectIdentifier(): Primitive\ObjectIdentifier |
|
| 163 | - { |
|
| 164 | - if (!$this->_element instanceof Primitive\ObjectIdentifier) { |
|
| 165 | - throw new \UnexpectedValueException( |
|
| 166 | - $this->_generateExceptionMessage( |
|
| 167 | - Element::TYPE_OBJECT_IDENTIFIER)); |
|
| 168 | - } |
|
| 169 | - return $this->_element; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * Get the wrapped element as an object descriptor type. |
|
| 174 | - * |
|
| 175 | - * @throws \UnexpectedValueException If the element is not an object |
|
| 176 | - * descriptor |
|
| 177 | - * @return Primitive\ObjectDescriptor |
|
| 178 | - */ |
|
| 179 | - public function asObjectDescriptor(): Primitive\ObjectDescriptor |
|
| 180 | - { |
|
| 181 | - if (!$this->_element instanceof Primitive\ObjectDescriptor) { |
|
| 182 | - throw new \UnexpectedValueException( |
|
| 183 | - $this->_generateExceptionMessage( |
|
| 184 | - Element::TYPE_OBJECT_DESCRIPTOR)); |
|
| 185 | - } |
|
| 186 | - return $this->_element; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Get the wrapped element as a real type. |
|
| 191 | - * |
|
| 192 | - * @throws \UnexpectedValueException If the element is not a real |
|
| 193 | - * @return Primitive\Real |
|
| 194 | - */ |
|
| 195 | - public function asReal(): Primitive\Real |
|
| 196 | - { |
|
| 197 | - if (!$this->_element instanceof Primitive\Real) { |
|
| 198 | - throw new \UnexpectedValueException( |
|
| 199 | - $this->_generateExceptionMessage(Element::TYPE_REAL)); |
|
| 200 | - } |
|
| 201 | - return $this->_element; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * Get the wrapped element as an enumerated type. |
|
| 206 | - * |
|
| 207 | - * @throws \UnexpectedValueException If the element is not an enumerated |
|
| 208 | - * @return Primitive\Enumerated |
|
| 209 | - */ |
|
| 210 | - public function asEnumerated(): Primitive\Enumerated |
|
| 211 | - { |
|
| 212 | - if (!$this->_element instanceof Primitive\Enumerated) { |
|
| 213 | - throw new \UnexpectedValueException( |
|
| 214 | - $this->_generateExceptionMessage(Element::TYPE_ENUMERATED)); |
|
| 215 | - } |
|
| 216 | - return $this->_element; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * Get the wrapped element as a UTF8 string type. |
|
| 221 | - * |
|
| 222 | - * @throws \UnexpectedValueException If the element is not a UTF8 string |
|
| 223 | - * @return Primitive\UTF8String |
|
| 224 | - */ |
|
| 225 | - public function asUTF8String(): Primitive\UTF8String |
|
| 226 | - { |
|
| 227 | - if (!$this->_element instanceof Primitive\UTF8String) { |
|
| 228 | - throw new \UnexpectedValueException( |
|
| 229 | - $this->_generateExceptionMessage(Element::TYPE_UTF8_STRING)); |
|
| 230 | - } |
|
| 231 | - return $this->_element; |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - /** |
|
| 235 | - * Get the wrapped element as a relative OID type. |
|
| 236 | - * |
|
| 237 | - * @throws \UnexpectedValueException If the element is not a relative OID |
|
| 238 | - * @return Primitive\RelativeOID |
|
| 239 | - */ |
|
| 240 | - public function asRelativeOID(): Primitive\RelativeOID |
|
| 241 | - { |
|
| 242 | - if (!$this->_element instanceof Primitive\RelativeOID) { |
|
| 243 | - throw new \UnexpectedValueException( |
|
| 244 | - $this->_generateExceptionMessage(Element::TYPE_RELATIVE_OID)); |
|
| 245 | - } |
|
| 246 | - return $this->_element; |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * Get the wrapped element as a sequence type. |
|
| 251 | - * |
|
| 252 | - * @throws \UnexpectedValueException If the element is not a sequence |
|
| 253 | - * @return Constructed\Sequence |
|
| 254 | - */ |
|
| 255 | - public function asSequence(): Constructed\Sequence |
|
| 256 | - { |
|
| 257 | - if (!$this->_element instanceof Constructed\Sequence) { |
|
| 258 | - throw new \UnexpectedValueException( |
|
| 259 | - $this->_generateExceptionMessage(Element::TYPE_SEQUENCE)); |
|
| 260 | - } |
|
| 261 | - return $this->_element; |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - /** |
|
| 265 | - * Get the wrapped element as a set type. |
|
| 266 | - * |
|
| 267 | - * @throws \UnexpectedValueException If the element is not a set |
|
| 268 | - * @return Constructed\Set |
|
| 269 | - */ |
|
| 270 | - public function asSet(): Constructed\Set |
|
| 271 | - { |
|
| 272 | - if (!$this->_element instanceof Constructed\Set) { |
|
| 273 | - throw new \UnexpectedValueException( |
|
| 274 | - $this->_generateExceptionMessage(Element::TYPE_SET)); |
|
| 275 | - } |
|
| 276 | - return $this->_element; |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * Get the wrapped element as a numeric string type. |
|
| 281 | - * |
|
| 282 | - * @throws \UnexpectedValueException If the element is not a numeric string |
|
| 283 | - * @return Primitive\NumericString |
|
| 284 | - */ |
|
| 285 | - public function asNumericString(): Primitive\NumericString |
|
| 286 | - { |
|
| 287 | - if (!$this->_element instanceof Primitive\NumericString) { |
|
| 288 | - throw new \UnexpectedValueException( |
|
| 289 | - $this->_generateExceptionMessage(Element::TYPE_NUMERIC_STRING)); |
|
| 290 | - } |
|
| 291 | - return $this->_element; |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - /** |
|
| 295 | - * Get the wrapped element as a printable string type. |
|
| 296 | - * |
|
| 297 | - * @throws \UnexpectedValueException If the element is not a printable |
|
| 298 | - * string |
|
| 299 | - * @return Primitive\PrintableString |
|
| 300 | - */ |
|
| 301 | - public function asPrintableString(): Primitive\PrintableString |
|
| 302 | - { |
|
| 303 | - if (!$this->_element instanceof Primitive\PrintableString) { |
|
| 304 | - throw new \UnexpectedValueException( |
|
| 305 | - $this->_generateExceptionMessage(Element::TYPE_PRINTABLE_STRING)); |
|
| 306 | - } |
|
| 307 | - return $this->_element; |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * Get the wrapped element as a T61 string type. |
|
| 312 | - * |
|
| 313 | - * @throws \UnexpectedValueException If the element is not a T61 string |
|
| 314 | - * @return Primitive\T61String |
|
| 315 | - */ |
|
| 316 | - public function asT61String(): Primitive\T61String |
|
| 317 | - { |
|
| 318 | - if (!$this->_element instanceof Primitive\T61String) { |
|
| 319 | - throw new \UnexpectedValueException( |
|
| 320 | - $this->_generateExceptionMessage(Element::TYPE_T61_STRING)); |
|
| 321 | - } |
|
| 322 | - return $this->_element; |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - /** |
|
| 326 | - * Get the wrapped element as a videotex string type. |
|
| 327 | - * |
|
| 328 | - * @throws \UnexpectedValueException If the element is not a videotex string |
|
| 329 | - * @return Primitive\VideotexString |
|
| 330 | - */ |
|
| 331 | - public function asVideotexString(): Primitive\VideotexString |
|
| 332 | - { |
|
| 333 | - if (!$this->_element instanceof Primitive\VideotexString) { |
|
| 334 | - throw new \UnexpectedValueException( |
|
| 335 | - $this->_generateExceptionMessage(Element::TYPE_VIDEOTEX_STRING)); |
|
| 336 | - } |
|
| 337 | - return $this->_element; |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - /** |
|
| 341 | - * Get the wrapped element as a IA5 string type. |
|
| 342 | - * |
|
| 343 | - * @throws \UnexpectedValueException If the element is not a IA5 string |
|
| 344 | - * @return Primitive\IA5String |
|
| 345 | - */ |
|
| 346 | - public function asIA5String(): Primitive\IA5String |
|
| 347 | - { |
|
| 348 | - if (!$this->_element instanceof Primitive\IA5String) { |
|
| 349 | - throw new \UnexpectedValueException( |
|
| 350 | - $this->_generateExceptionMessage(Element::TYPE_IA5_STRING)); |
|
| 351 | - } |
|
| 352 | - return $this->_element; |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - /** |
|
| 356 | - * Get the wrapped element as an UTC time type. |
|
| 357 | - * |
|
| 358 | - * @throws \UnexpectedValueException If the element is not a UTC time |
|
| 359 | - * @return Primitive\UTCTime |
|
| 360 | - */ |
|
| 361 | - public function asUTCTime(): Primitive\UTCTime |
|
| 362 | - { |
|
| 363 | - if (!$this->_element instanceof Primitive\UTCTime) { |
|
| 364 | - throw new \UnexpectedValueException( |
|
| 365 | - $this->_generateExceptionMessage(Element::TYPE_UTC_TIME)); |
|
| 366 | - } |
|
| 367 | - return $this->_element; |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - /** |
|
| 371 | - * Get the wrapped element as a generalized time type. |
|
| 372 | - * |
|
| 373 | - * @throws \UnexpectedValueException If the element is not a generalized |
|
| 374 | - * time |
|
| 375 | - * @return Primitive\GeneralizedTime |
|
| 376 | - */ |
|
| 377 | - public function asGeneralizedTime(): Primitive\GeneralizedTime |
|
| 378 | - { |
|
| 379 | - if (!$this->_element instanceof Primitive\GeneralizedTime) { |
|
| 380 | - throw new \UnexpectedValueException( |
|
| 381 | - $this->_generateExceptionMessage(Element::TYPE_GENERALIZED_TIME)); |
|
| 382 | - } |
|
| 383 | - return $this->_element; |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - /** |
|
| 387 | - * Get the wrapped element as a graphic string type. |
|
| 388 | - * |
|
| 389 | - * @throws \UnexpectedValueException If the element is not a graphic string |
|
| 390 | - * @return Primitive\GraphicString |
|
| 391 | - */ |
|
| 392 | - public function asGraphicString(): Primitive\GraphicString |
|
| 393 | - { |
|
| 394 | - if (!$this->_element instanceof Primitive\GraphicString) { |
|
| 395 | - throw new \UnexpectedValueException( |
|
| 396 | - $this->_generateExceptionMessage(Element::TYPE_GRAPHIC_STRING)); |
|
| 397 | - } |
|
| 398 | - return $this->_element; |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - /** |
|
| 402 | - * Get the wrapped element as a visible string type. |
|
| 403 | - * |
|
| 404 | - * @throws \UnexpectedValueException If the element is not a visible string |
|
| 405 | - * @return Primitive\VisibleString |
|
| 406 | - */ |
|
| 407 | - public function asVisibleString(): Primitive\VisibleString |
|
| 408 | - { |
|
| 409 | - if (!$this->_element instanceof Primitive\VisibleString) { |
|
| 410 | - throw new \UnexpectedValueException( |
|
| 411 | - $this->_generateExceptionMessage(Element::TYPE_VISIBLE_STRING)); |
|
| 412 | - } |
|
| 413 | - return $this->_element; |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - /** |
|
| 417 | - * Get the wrapped element as a general string type. |
|
| 418 | - * |
|
| 419 | - * @throws \UnexpectedValueException If the element is not general string |
|
| 420 | - * @return Primitive\GeneralString |
|
| 421 | - */ |
|
| 422 | - public function asGeneralString(): Primitive\GeneralString |
|
| 423 | - { |
|
| 424 | - if (!$this->_element instanceof Primitive\GeneralString) { |
|
| 425 | - throw new \UnexpectedValueException( |
|
| 426 | - $this->_generateExceptionMessage(Element::TYPE_GENERAL_STRING)); |
|
| 427 | - } |
|
| 428 | - return $this->_element; |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - /** |
|
| 432 | - * Get the wrapped element as a universal string type. |
|
| 433 | - * |
|
| 434 | - * @throws \UnexpectedValueException If the element is not a universal |
|
| 435 | - * string |
|
| 436 | - * @return Primitive\UniversalString |
|
| 437 | - */ |
|
| 438 | - public function asUniversalString(): Primitive\UniversalString |
|
| 439 | - { |
|
| 440 | - if (!$this->_element instanceof Primitive\UniversalString) { |
|
| 441 | - throw new \UnexpectedValueException( |
|
| 442 | - $this->_generateExceptionMessage(Element::TYPE_UNIVERSAL_STRING)); |
|
| 443 | - } |
|
| 444 | - return $this->_element; |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - /** |
|
| 448 | - * Get the wrapped element as a character string type. |
|
| 449 | - * |
|
| 450 | - * @throws \UnexpectedValueException If the element is not a character |
|
| 451 | - * string |
|
| 452 | - * @return Primitive\CharacterString |
|
| 453 | - */ |
|
| 454 | - public function asCharacterString(): Primitive\CharacterString |
|
| 455 | - { |
|
| 456 | - if (!$this->_element instanceof Primitive\CharacterString) { |
|
| 457 | - throw new \UnexpectedValueException( |
|
| 458 | - $this->_generateExceptionMessage(Element::TYPE_CHARACTER_STRING)); |
|
| 459 | - } |
|
| 460 | - return $this->_element; |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - /** |
|
| 464 | - * Get the wrapped element as a BMP string type. |
|
| 465 | - * |
|
| 466 | - * @throws \UnexpectedValueException If the element is not a bmp string |
|
| 467 | - * @return Primitive\BMPString |
|
| 468 | - */ |
|
| 469 | - public function asBMPString(): Primitive\BMPString |
|
| 470 | - { |
|
| 471 | - if (!$this->_element instanceof Primitive\BMPString) { |
|
| 472 | - throw new \UnexpectedValueException( |
|
| 473 | - $this->_generateExceptionMessage(Element::TYPE_BMP_STRING)); |
|
| 474 | - } |
|
| 475 | - return $this->_element; |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - /** |
|
| 479 | - * Get the wrapped element as any string type. |
|
| 480 | - * |
|
| 481 | - * @throws \UnexpectedValueException If the element is not a string |
|
| 482 | - * @return StringType |
|
| 483 | - */ |
|
| 484 | - public function asString(): StringType |
|
| 485 | - { |
|
| 486 | - if (!$this->_element instanceof StringType) { |
|
| 487 | - throw new \UnexpectedValueException( |
|
| 488 | - $this->_generateExceptionMessage(Element::TYPE_STRING)); |
|
| 489 | - } |
|
| 490 | - return $this->_element; |
|
| 491 | - } |
|
| 492 | - |
|
| 493 | - /** |
|
| 494 | - * Get the wrapped element as any time type. |
|
| 495 | - * |
|
| 496 | - * @throws \UnexpectedValueException If the element is not a time |
|
| 497 | - * @return TimeType |
|
| 498 | - */ |
|
| 499 | - public function asTime(): TimeType |
|
| 500 | - { |
|
| 501 | - if (!$this->_element instanceof TimeType) { |
|
| 502 | - throw new \UnexpectedValueException( |
|
| 503 | - $this->_generateExceptionMessage(Element::TYPE_TIME)); |
|
| 504 | - } |
|
| 505 | - return $this->_element; |
|
| 506 | - } |
|
| 507 | - |
|
| 508 | - /** |
|
| 509 | - * Generate message for exceptions thrown by <code>as*</code> methods. |
|
| 510 | - * |
|
| 511 | - * @param int $tag Type tag of the expected element |
|
| 512 | - * @return string |
|
| 513 | - */ |
|
| 514 | - private function _generateExceptionMessage(int $tag): string |
|
| 515 | - { |
|
| 516 | - return sprintf("%s expected, got %s.", Element::tagToName($tag), |
|
| 517 | - $this->_typeDescriptorString()); |
|
| 518 | - } |
|
| 519 | - |
|
| 520 | - /** |
|
| 521 | - * Get textual description of the wrapped element for debugging purposes. |
|
| 522 | - * |
|
| 523 | - * @return string |
|
| 524 | - */ |
|
| 525 | - private function _typeDescriptorString(): string |
|
| 526 | - { |
|
| 527 | - $type_cls = $this->_element->typeClass(); |
|
| 528 | - $tag = $this->_element->tag(); |
|
| 529 | - if ($type_cls == Identifier::CLASS_UNIVERSAL) { |
|
| 530 | - return Element::tagToName($tag); |
|
| 531 | - } |
|
| 532 | - return Identifier::classToName($type_cls) . " TAG $tag"; |
|
| 533 | - } |
|
| 534 | - |
|
| 535 | - /** |
|
| 536 | - * |
|
| 537 | - * @see \ASN1\Feature\Encodable::toDER() |
|
| 538 | - * @return string |
|
| 539 | - */ |
|
| 540 | - public function toDER(): string |
|
| 541 | - { |
|
| 542 | - return $this->_element->toDER(); |
|
| 543 | - } |
|
| 544 | - |
|
| 545 | - /** |
|
| 546 | - * |
|
| 547 | - * @see \ASN1\Feature\ElementBase::typeClass() |
|
| 548 | - * @return int |
|
| 549 | - */ |
|
| 550 | - public function typeClass(): int |
|
| 551 | - { |
|
| 552 | - return $this->_element->typeClass(); |
|
| 553 | - } |
|
| 554 | - |
|
| 555 | - /** |
|
| 556 | - * |
|
| 557 | - * @see \ASN1\Feature\ElementBase::isConstructed() |
|
| 558 | - * @return bool |
|
| 559 | - */ |
|
| 560 | - public function isConstructed(): bool |
|
| 561 | - { |
|
| 562 | - return $this->_element->isConstructed(); |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - /** |
|
| 566 | - * |
|
| 567 | - * @see \ASN1\Feature\ElementBase::tag() |
|
| 568 | - * @return int |
|
| 569 | - */ |
|
| 570 | - public function tag(): int |
|
| 571 | - { |
|
| 572 | - return $this->_element->tag(); |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - /** |
|
| 576 | - * |
|
| 577 | - * {@inheritdoc} |
|
| 578 | - * @see \ASN1\Feature\ElementBase::isType() |
|
| 579 | - * @return bool |
|
| 580 | - */ |
|
| 581 | - public function isType(int $tag): bool |
|
| 582 | - { |
|
| 583 | - return $this->_element->isType($tag); |
|
| 584 | - } |
|
| 585 | - |
|
| 586 | - /** |
|
| 587 | - * |
|
| 588 | - * @deprecated Use any <code>as*</code> accessor method first to ensure |
|
| 589 | - * type strictness. |
|
| 590 | - * @see \ASN1\Feature\ElementBase::expectType() |
|
| 591 | - * @return ElementBase |
|
| 592 | - */ |
|
| 593 | - public function expectType(int $tag): ElementBase |
|
| 594 | - { |
|
| 595 | - return $this->_element->expectType($tag); |
|
| 596 | - } |
|
| 597 | - |
|
| 598 | - /** |
|
| 599 | - * |
|
| 600 | - * @see \ASN1\Feature\ElementBase::isTagged() |
|
| 601 | - * @return bool |
|
| 602 | - */ |
|
| 603 | - public function isTagged(): bool |
|
| 604 | - { |
|
| 605 | - return $this->_element->isTagged(); |
|
| 606 | - } |
|
| 607 | - |
|
| 608 | - /** |
|
| 609 | - * |
|
| 610 | - * @deprecated Use any <code>as*</code> accessor method first to ensure |
|
| 611 | - * type strictness. |
|
| 612 | - * @see \ASN1\Feature\ElementBase::expectTagged() |
|
| 613 | - * @return TaggedType |
|
| 614 | - */ |
|
| 615 | - public function expectTagged($tag = null): TaggedType |
|
| 616 | - { |
|
| 617 | - return $this->_element->expectTagged($tag); |
|
| 618 | - } |
|
| 619 | - |
|
| 620 | - /** |
|
| 621 | - * |
|
| 622 | - * @see \ASN1\Feature\ElementBase::asElement() |
|
| 623 | - * @return Element |
|
| 624 | - */ |
|
| 625 | - public function asElement(): Element |
|
| 626 | - { |
|
| 627 | - return $this->_element; |
|
| 628 | - } |
|
| 20 | + /** |
|
| 21 | + * The wrapped element. |
|
| 22 | + * |
|
| 23 | + * @var Element |
|
| 24 | + */ |
|
| 25 | + private $_element; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * Constructor. |
|
| 29 | + * |
|
| 30 | + * @param Element $el |
|
| 31 | + */ |
|
| 32 | + public function __construct(Element $el) |
|
| 33 | + { |
|
| 34 | + $this->_element = $el; |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Initialize from ElementBase interface. |
|
| 39 | + * |
|
| 40 | + * @param ElementBase $el |
|
| 41 | + * @return self |
|
| 42 | + */ |
|
| 43 | + public static function fromElementBase(ElementBase $el): self |
|
| 44 | + { |
|
| 45 | + // if element is already wrapped |
|
| 46 | + if ($el instanceof self) { |
|
| 47 | + return $el; |
|
| 48 | + } |
|
| 49 | + return new self($el->asElement()); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * Compatibility method to dispatch calls to the wrapped element. |
|
| 54 | + * |
|
| 55 | + * @deprecated Use <code>as*</code> accessor methods to ensure strict type |
|
| 56 | + * @param string $mtd Method name |
|
| 57 | + * @param array $args Arguments |
|
| 58 | + * @return mixed |
|
| 59 | + */ |
|
| 60 | + public function __call($mtd, array $args) |
|
| 61 | + { |
|
| 62 | + return call_user_func_array([$this->_element, $mtd], $args); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Get the wrapped element as a context specific tagged type. |
|
| 67 | + * |
|
| 68 | + * @throws \UnexpectedValueException If the element is not tagged |
|
| 69 | + * @return TaggedType |
|
| 70 | + */ |
|
| 71 | + public function asTagged(): TaggedType |
|
| 72 | + { |
|
| 73 | + if (!$this->_element instanceof TaggedType) { |
|
| 74 | + throw new \UnexpectedValueException( |
|
| 75 | + "Tagged element expected, got " . $this->_typeDescriptorString()); |
|
| 76 | + } |
|
| 77 | + return $this->_element; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Get the wrapped element as a boolean type. |
|
| 82 | + * |
|
| 83 | + * @throws \UnexpectedValueException If the element is not a boolean |
|
| 84 | + * @return Primitive\Boolean |
|
| 85 | + */ |
|
| 86 | + public function asBoolean(): Primitive\Boolean |
|
| 87 | + { |
|
| 88 | + if (!$this->_element instanceof Primitive\Boolean) { |
|
| 89 | + throw new \UnexpectedValueException( |
|
| 90 | + $this->_generateExceptionMessage(Element::TYPE_BOOLEAN)); |
|
| 91 | + } |
|
| 92 | + return $this->_element; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Get the wrapped element as an integer type. |
|
| 97 | + * |
|
| 98 | + * @throws \UnexpectedValueException If the element is not an integer |
|
| 99 | + * @return Primitive\Integer |
|
| 100 | + */ |
|
| 101 | + public function asInteger(): Primitive\Integer |
|
| 102 | + { |
|
| 103 | + if (!$this->_element instanceof Primitive\Integer) { |
|
| 104 | + throw new \UnexpectedValueException( |
|
| 105 | + $this->_generateExceptionMessage(Element::TYPE_INTEGER)); |
|
| 106 | + } |
|
| 107 | + return $this->_element; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Get the wrapped element as a bit string type. |
|
| 112 | + * |
|
| 113 | + * @throws \UnexpectedValueException If the element is not a bit string |
|
| 114 | + * @return Primitive\BitString |
|
| 115 | + */ |
|
| 116 | + public function asBitString(): Primitive\BitString |
|
| 117 | + { |
|
| 118 | + if (!$this->_element instanceof Primitive\BitString) { |
|
| 119 | + throw new \UnexpectedValueException( |
|
| 120 | + $this->_generateExceptionMessage(Element::TYPE_BIT_STRING)); |
|
| 121 | + } |
|
| 122 | + return $this->_element; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * Get the wrapped element as an octet string type. |
|
| 127 | + * |
|
| 128 | + * @throws \UnexpectedValueException If the element is not an octet string |
|
| 129 | + * @return Primitive\OctetString |
|
| 130 | + */ |
|
| 131 | + public function asOctetString(): Primitive\OctetString |
|
| 132 | + { |
|
| 133 | + if (!$this->_element instanceof Primitive\OctetString) { |
|
| 134 | + throw new \UnexpectedValueException( |
|
| 135 | + $this->_generateExceptionMessage(Element::TYPE_OCTET_STRING)); |
|
| 136 | + } |
|
| 137 | + return $this->_element; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Get the wrapped element as a null type. |
|
| 142 | + * |
|
| 143 | + * @throws \UnexpectedValueException If the element is not a null |
|
| 144 | + * @return Primitive\NullType |
|
| 145 | + */ |
|
| 146 | + public function asNull(): Primitive\NullType |
|
| 147 | + { |
|
| 148 | + if (!$this->_element instanceof Primitive\NullType) { |
|
| 149 | + throw new \UnexpectedValueException( |
|
| 150 | + $this->_generateExceptionMessage(Element::TYPE_NULL)); |
|
| 151 | + } |
|
| 152 | + return $this->_element; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Get the wrapped element as an object identifier type. |
|
| 157 | + * |
|
| 158 | + * @throws \UnexpectedValueException If the element is not an object |
|
| 159 | + * identifier |
|
| 160 | + * @return Primitive\ObjectIdentifier |
|
| 161 | + */ |
|
| 162 | + public function asObjectIdentifier(): Primitive\ObjectIdentifier |
|
| 163 | + { |
|
| 164 | + if (!$this->_element instanceof Primitive\ObjectIdentifier) { |
|
| 165 | + throw new \UnexpectedValueException( |
|
| 166 | + $this->_generateExceptionMessage( |
|
| 167 | + Element::TYPE_OBJECT_IDENTIFIER)); |
|
| 168 | + } |
|
| 169 | + return $this->_element; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * Get the wrapped element as an object descriptor type. |
|
| 174 | + * |
|
| 175 | + * @throws \UnexpectedValueException If the element is not an object |
|
| 176 | + * descriptor |
|
| 177 | + * @return Primitive\ObjectDescriptor |
|
| 178 | + */ |
|
| 179 | + public function asObjectDescriptor(): Primitive\ObjectDescriptor |
|
| 180 | + { |
|
| 181 | + if (!$this->_element instanceof Primitive\ObjectDescriptor) { |
|
| 182 | + throw new \UnexpectedValueException( |
|
| 183 | + $this->_generateExceptionMessage( |
|
| 184 | + Element::TYPE_OBJECT_DESCRIPTOR)); |
|
| 185 | + } |
|
| 186 | + return $this->_element; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * Get the wrapped element as a real type. |
|
| 191 | + * |
|
| 192 | + * @throws \UnexpectedValueException If the element is not a real |
|
| 193 | + * @return Primitive\Real |
|
| 194 | + */ |
|
| 195 | + public function asReal(): Primitive\Real |
|
| 196 | + { |
|
| 197 | + if (!$this->_element instanceof Primitive\Real) { |
|
| 198 | + throw new \UnexpectedValueException( |
|
| 199 | + $this->_generateExceptionMessage(Element::TYPE_REAL)); |
|
| 200 | + } |
|
| 201 | + return $this->_element; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * Get the wrapped element as an enumerated type. |
|
| 206 | + * |
|
| 207 | + * @throws \UnexpectedValueException If the element is not an enumerated |
|
| 208 | + * @return Primitive\Enumerated |
|
| 209 | + */ |
|
| 210 | + public function asEnumerated(): Primitive\Enumerated |
|
| 211 | + { |
|
| 212 | + if (!$this->_element instanceof Primitive\Enumerated) { |
|
| 213 | + throw new \UnexpectedValueException( |
|
| 214 | + $this->_generateExceptionMessage(Element::TYPE_ENUMERATED)); |
|
| 215 | + } |
|
| 216 | + return $this->_element; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * Get the wrapped element as a UTF8 string type. |
|
| 221 | + * |
|
| 222 | + * @throws \UnexpectedValueException If the element is not a UTF8 string |
|
| 223 | + * @return Primitive\UTF8String |
|
| 224 | + */ |
|
| 225 | + public function asUTF8String(): Primitive\UTF8String |
|
| 226 | + { |
|
| 227 | + if (!$this->_element instanceof Primitive\UTF8String) { |
|
| 228 | + throw new \UnexpectedValueException( |
|
| 229 | + $this->_generateExceptionMessage(Element::TYPE_UTF8_STRING)); |
|
| 230 | + } |
|
| 231 | + return $this->_element; |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + /** |
|
| 235 | + * Get the wrapped element as a relative OID type. |
|
| 236 | + * |
|
| 237 | + * @throws \UnexpectedValueException If the element is not a relative OID |
|
| 238 | + * @return Primitive\RelativeOID |
|
| 239 | + */ |
|
| 240 | + public function asRelativeOID(): Primitive\RelativeOID |
|
| 241 | + { |
|
| 242 | + if (!$this->_element instanceof Primitive\RelativeOID) { |
|
| 243 | + throw new \UnexpectedValueException( |
|
| 244 | + $this->_generateExceptionMessage(Element::TYPE_RELATIVE_OID)); |
|
| 245 | + } |
|
| 246 | + return $this->_element; |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * Get the wrapped element as a sequence type. |
|
| 251 | + * |
|
| 252 | + * @throws \UnexpectedValueException If the element is not a sequence |
|
| 253 | + * @return Constructed\Sequence |
|
| 254 | + */ |
|
| 255 | + public function asSequence(): Constructed\Sequence |
|
| 256 | + { |
|
| 257 | + if (!$this->_element instanceof Constructed\Sequence) { |
|
| 258 | + throw new \UnexpectedValueException( |
|
| 259 | + $this->_generateExceptionMessage(Element::TYPE_SEQUENCE)); |
|
| 260 | + } |
|
| 261 | + return $this->_element; |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + /** |
|
| 265 | + * Get the wrapped element as a set type. |
|
| 266 | + * |
|
| 267 | + * @throws \UnexpectedValueException If the element is not a set |
|
| 268 | + * @return Constructed\Set |
|
| 269 | + */ |
|
| 270 | + public function asSet(): Constructed\Set |
|
| 271 | + { |
|
| 272 | + if (!$this->_element instanceof Constructed\Set) { |
|
| 273 | + throw new \UnexpectedValueException( |
|
| 274 | + $this->_generateExceptionMessage(Element::TYPE_SET)); |
|
| 275 | + } |
|
| 276 | + return $this->_element; |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * Get the wrapped element as a numeric string type. |
|
| 281 | + * |
|
| 282 | + * @throws \UnexpectedValueException If the element is not a numeric string |
|
| 283 | + * @return Primitive\NumericString |
|
| 284 | + */ |
|
| 285 | + public function asNumericString(): Primitive\NumericString |
|
| 286 | + { |
|
| 287 | + if (!$this->_element instanceof Primitive\NumericString) { |
|
| 288 | + throw new \UnexpectedValueException( |
|
| 289 | + $this->_generateExceptionMessage(Element::TYPE_NUMERIC_STRING)); |
|
| 290 | + } |
|
| 291 | + return $this->_element; |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + /** |
|
| 295 | + * Get the wrapped element as a printable string type. |
|
| 296 | + * |
|
| 297 | + * @throws \UnexpectedValueException If the element is not a printable |
|
| 298 | + * string |
|
| 299 | + * @return Primitive\PrintableString |
|
| 300 | + */ |
|
| 301 | + public function asPrintableString(): Primitive\PrintableString |
|
| 302 | + { |
|
| 303 | + if (!$this->_element instanceof Primitive\PrintableString) { |
|
| 304 | + throw new \UnexpectedValueException( |
|
| 305 | + $this->_generateExceptionMessage(Element::TYPE_PRINTABLE_STRING)); |
|
| 306 | + } |
|
| 307 | + return $this->_element; |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * Get the wrapped element as a T61 string type. |
|
| 312 | + * |
|
| 313 | + * @throws \UnexpectedValueException If the element is not a T61 string |
|
| 314 | + * @return Primitive\T61String |
|
| 315 | + */ |
|
| 316 | + public function asT61String(): Primitive\T61String |
|
| 317 | + { |
|
| 318 | + if (!$this->_element instanceof Primitive\T61String) { |
|
| 319 | + throw new \UnexpectedValueException( |
|
| 320 | + $this->_generateExceptionMessage(Element::TYPE_T61_STRING)); |
|
| 321 | + } |
|
| 322 | + return $this->_element; |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + /** |
|
| 326 | + * Get the wrapped element as a videotex string type. |
|
| 327 | + * |
|
| 328 | + * @throws \UnexpectedValueException If the element is not a videotex string |
|
| 329 | + * @return Primitive\VideotexString |
|
| 330 | + */ |
|
| 331 | + public function asVideotexString(): Primitive\VideotexString |
|
| 332 | + { |
|
| 333 | + if (!$this->_element instanceof Primitive\VideotexString) { |
|
| 334 | + throw new \UnexpectedValueException( |
|
| 335 | + $this->_generateExceptionMessage(Element::TYPE_VIDEOTEX_STRING)); |
|
| 336 | + } |
|
| 337 | + return $this->_element; |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + /** |
|
| 341 | + * Get the wrapped element as a IA5 string type. |
|
| 342 | + * |
|
| 343 | + * @throws \UnexpectedValueException If the element is not a IA5 string |
|
| 344 | + * @return Primitive\IA5String |
|
| 345 | + */ |
|
| 346 | + public function asIA5String(): Primitive\IA5String |
|
| 347 | + { |
|
| 348 | + if (!$this->_element instanceof Primitive\IA5String) { |
|
| 349 | + throw new \UnexpectedValueException( |
|
| 350 | + $this->_generateExceptionMessage(Element::TYPE_IA5_STRING)); |
|
| 351 | + } |
|
| 352 | + return $this->_element; |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + /** |
|
| 356 | + * Get the wrapped element as an UTC time type. |
|
| 357 | + * |
|
| 358 | + * @throws \UnexpectedValueException If the element is not a UTC time |
|
| 359 | + * @return Primitive\UTCTime |
|
| 360 | + */ |
|
| 361 | + public function asUTCTime(): Primitive\UTCTime |
|
| 362 | + { |
|
| 363 | + if (!$this->_element instanceof Primitive\UTCTime) { |
|
| 364 | + throw new \UnexpectedValueException( |
|
| 365 | + $this->_generateExceptionMessage(Element::TYPE_UTC_TIME)); |
|
| 366 | + } |
|
| 367 | + return $this->_element; |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + /** |
|
| 371 | + * Get the wrapped element as a generalized time type. |
|
| 372 | + * |
|
| 373 | + * @throws \UnexpectedValueException If the element is not a generalized |
|
| 374 | + * time |
|
| 375 | + * @return Primitive\GeneralizedTime |
|
| 376 | + */ |
|
| 377 | + public function asGeneralizedTime(): Primitive\GeneralizedTime |
|
| 378 | + { |
|
| 379 | + if (!$this->_element instanceof Primitive\GeneralizedTime) { |
|
| 380 | + throw new \UnexpectedValueException( |
|
| 381 | + $this->_generateExceptionMessage(Element::TYPE_GENERALIZED_TIME)); |
|
| 382 | + } |
|
| 383 | + return $this->_element; |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + /** |
|
| 387 | + * Get the wrapped element as a graphic string type. |
|
| 388 | + * |
|
| 389 | + * @throws \UnexpectedValueException If the element is not a graphic string |
|
| 390 | + * @return Primitive\GraphicString |
|
| 391 | + */ |
|
| 392 | + public function asGraphicString(): Primitive\GraphicString |
|
| 393 | + { |
|
| 394 | + if (!$this->_element instanceof Primitive\GraphicString) { |
|
| 395 | + throw new \UnexpectedValueException( |
|
| 396 | + $this->_generateExceptionMessage(Element::TYPE_GRAPHIC_STRING)); |
|
| 397 | + } |
|
| 398 | + return $this->_element; |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + /** |
|
| 402 | + * Get the wrapped element as a visible string type. |
|
| 403 | + * |
|
| 404 | + * @throws \UnexpectedValueException If the element is not a visible string |
|
| 405 | + * @return Primitive\VisibleString |
|
| 406 | + */ |
|
| 407 | + public function asVisibleString(): Primitive\VisibleString |
|
| 408 | + { |
|
| 409 | + if (!$this->_element instanceof Primitive\VisibleString) { |
|
| 410 | + throw new \UnexpectedValueException( |
|
| 411 | + $this->_generateExceptionMessage(Element::TYPE_VISIBLE_STRING)); |
|
| 412 | + } |
|
| 413 | + return $this->_element; |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + /** |
|
| 417 | + * Get the wrapped element as a general string type. |
|
| 418 | + * |
|
| 419 | + * @throws \UnexpectedValueException If the element is not general string |
|
| 420 | + * @return Primitive\GeneralString |
|
| 421 | + */ |
|
| 422 | + public function asGeneralString(): Primitive\GeneralString |
|
| 423 | + { |
|
| 424 | + if (!$this->_element instanceof Primitive\GeneralString) { |
|
| 425 | + throw new \UnexpectedValueException( |
|
| 426 | + $this->_generateExceptionMessage(Element::TYPE_GENERAL_STRING)); |
|
| 427 | + } |
|
| 428 | + return $this->_element; |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + /** |
|
| 432 | + * Get the wrapped element as a universal string type. |
|
| 433 | + * |
|
| 434 | + * @throws \UnexpectedValueException If the element is not a universal |
|
| 435 | + * string |
|
| 436 | + * @return Primitive\UniversalString |
|
| 437 | + */ |
|
| 438 | + public function asUniversalString(): Primitive\UniversalString |
|
| 439 | + { |
|
| 440 | + if (!$this->_element instanceof Primitive\UniversalString) { |
|
| 441 | + throw new \UnexpectedValueException( |
|
| 442 | + $this->_generateExceptionMessage(Element::TYPE_UNIVERSAL_STRING)); |
|
| 443 | + } |
|
| 444 | + return $this->_element; |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + /** |
|
| 448 | + * Get the wrapped element as a character string type. |
|
| 449 | + * |
|
| 450 | + * @throws \UnexpectedValueException If the element is not a character |
|
| 451 | + * string |
|
| 452 | + * @return Primitive\CharacterString |
|
| 453 | + */ |
|
| 454 | + public function asCharacterString(): Primitive\CharacterString |
|
| 455 | + { |
|
| 456 | + if (!$this->_element instanceof Primitive\CharacterString) { |
|
| 457 | + throw new \UnexpectedValueException( |
|
| 458 | + $this->_generateExceptionMessage(Element::TYPE_CHARACTER_STRING)); |
|
| 459 | + } |
|
| 460 | + return $this->_element; |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + /** |
|
| 464 | + * Get the wrapped element as a BMP string type. |
|
| 465 | + * |
|
| 466 | + * @throws \UnexpectedValueException If the element is not a bmp string |
|
| 467 | + * @return Primitive\BMPString |
|
| 468 | + */ |
|
| 469 | + public function asBMPString(): Primitive\BMPString |
|
| 470 | + { |
|
| 471 | + if (!$this->_element instanceof Primitive\BMPString) { |
|
| 472 | + throw new \UnexpectedValueException( |
|
| 473 | + $this->_generateExceptionMessage(Element::TYPE_BMP_STRING)); |
|
| 474 | + } |
|
| 475 | + return $this->_element; |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + /** |
|
| 479 | + * Get the wrapped element as any string type. |
|
| 480 | + * |
|
| 481 | + * @throws \UnexpectedValueException If the element is not a string |
|
| 482 | + * @return StringType |
|
| 483 | + */ |
|
| 484 | + public function asString(): StringType |
|
| 485 | + { |
|
| 486 | + if (!$this->_element instanceof StringType) { |
|
| 487 | + throw new \UnexpectedValueException( |
|
| 488 | + $this->_generateExceptionMessage(Element::TYPE_STRING)); |
|
| 489 | + } |
|
| 490 | + return $this->_element; |
|
| 491 | + } |
|
| 492 | + |
|
| 493 | + /** |
|
| 494 | + * Get the wrapped element as any time type. |
|
| 495 | + * |
|
| 496 | + * @throws \UnexpectedValueException If the element is not a time |
|
| 497 | + * @return TimeType |
|
| 498 | + */ |
|
| 499 | + public function asTime(): TimeType |
|
| 500 | + { |
|
| 501 | + if (!$this->_element instanceof TimeType) { |
|
| 502 | + throw new \UnexpectedValueException( |
|
| 503 | + $this->_generateExceptionMessage(Element::TYPE_TIME)); |
|
| 504 | + } |
|
| 505 | + return $this->_element; |
|
| 506 | + } |
|
| 507 | + |
|
| 508 | + /** |
|
| 509 | + * Generate message for exceptions thrown by <code>as*</code> methods. |
|
| 510 | + * |
|
| 511 | + * @param int $tag Type tag of the expected element |
|
| 512 | + * @return string |
|
| 513 | + */ |
|
| 514 | + private function _generateExceptionMessage(int $tag): string |
|
| 515 | + { |
|
| 516 | + return sprintf("%s expected, got %s.", Element::tagToName($tag), |
|
| 517 | + $this->_typeDescriptorString()); |
|
| 518 | + } |
|
| 519 | + |
|
| 520 | + /** |
|
| 521 | + * Get textual description of the wrapped element for debugging purposes. |
|
| 522 | + * |
|
| 523 | + * @return string |
|
| 524 | + */ |
|
| 525 | + private function _typeDescriptorString(): string |
|
| 526 | + { |
|
| 527 | + $type_cls = $this->_element->typeClass(); |
|
| 528 | + $tag = $this->_element->tag(); |
|
| 529 | + if ($type_cls == Identifier::CLASS_UNIVERSAL) { |
|
| 530 | + return Element::tagToName($tag); |
|
| 531 | + } |
|
| 532 | + return Identifier::classToName($type_cls) . " TAG $tag"; |
|
| 533 | + } |
|
| 534 | + |
|
| 535 | + /** |
|
| 536 | + * |
|
| 537 | + * @see \ASN1\Feature\Encodable::toDER() |
|
| 538 | + * @return string |
|
| 539 | + */ |
|
| 540 | + public function toDER(): string |
|
| 541 | + { |
|
| 542 | + return $this->_element->toDER(); |
|
| 543 | + } |
|
| 544 | + |
|
| 545 | + /** |
|
| 546 | + * |
|
| 547 | + * @see \ASN1\Feature\ElementBase::typeClass() |
|
| 548 | + * @return int |
|
| 549 | + */ |
|
| 550 | + public function typeClass(): int |
|
| 551 | + { |
|
| 552 | + return $this->_element->typeClass(); |
|
| 553 | + } |
|
| 554 | + |
|
| 555 | + /** |
|
| 556 | + * |
|
| 557 | + * @see \ASN1\Feature\ElementBase::isConstructed() |
|
| 558 | + * @return bool |
|
| 559 | + */ |
|
| 560 | + public function isConstructed(): bool |
|
| 561 | + { |
|
| 562 | + return $this->_element->isConstructed(); |
|
| 563 | + } |
|
| 564 | + |
|
| 565 | + /** |
|
| 566 | + * |
|
| 567 | + * @see \ASN1\Feature\ElementBase::tag() |
|
| 568 | + * @return int |
|
| 569 | + */ |
|
| 570 | + public function tag(): int |
|
| 571 | + { |
|
| 572 | + return $this->_element->tag(); |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + /** |
|
| 576 | + * |
|
| 577 | + * {@inheritdoc} |
|
| 578 | + * @see \ASN1\Feature\ElementBase::isType() |
|
| 579 | + * @return bool |
|
| 580 | + */ |
|
| 581 | + public function isType(int $tag): bool |
|
| 582 | + { |
|
| 583 | + return $this->_element->isType($tag); |
|
| 584 | + } |
|
| 585 | + |
|
| 586 | + /** |
|
| 587 | + * |
|
| 588 | + * @deprecated Use any <code>as*</code> accessor method first to ensure |
|
| 589 | + * type strictness. |
|
| 590 | + * @see \ASN1\Feature\ElementBase::expectType() |
|
| 591 | + * @return ElementBase |
|
| 592 | + */ |
|
| 593 | + public function expectType(int $tag): ElementBase |
|
| 594 | + { |
|
| 595 | + return $this->_element->expectType($tag); |
|
| 596 | + } |
|
| 597 | + |
|
| 598 | + /** |
|
| 599 | + * |
|
| 600 | + * @see \ASN1\Feature\ElementBase::isTagged() |
|
| 601 | + * @return bool |
|
| 602 | + */ |
|
| 603 | + public function isTagged(): bool |
|
| 604 | + { |
|
| 605 | + return $this->_element->isTagged(); |
|
| 606 | + } |
|
| 607 | + |
|
| 608 | + /** |
|
| 609 | + * |
|
| 610 | + * @deprecated Use any <code>as*</code> accessor method first to ensure |
|
| 611 | + * type strictness. |
|
| 612 | + * @see \ASN1\Feature\ElementBase::expectTagged() |
|
| 613 | + * @return TaggedType |
|
| 614 | + */ |
|
| 615 | + public function expectTagged($tag = null): TaggedType |
|
| 616 | + { |
|
| 617 | + return $this->_element->expectTagged($tag); |
|
| 618 | + } |
|
| 619 | + |
|
| 620 | + /** |
|
| 621 | + * |
|
| 622 | + * @see \ASN1\Feature\ElementBase::asElement() |
|
| 623 | + * @return Element |
|
| 624 | + */ |
|
| 625 | + public function asElement(): Element |
|
| 626 | + { |
|
| 627 | + return $this->_element; |
|
| 628 | + } |
|
| 629 | 629 | } |
@@ -17,85 +17,85 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | abstract class TaggedType extends Element |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * |
|
| 22 | - * {@inheritdoc} |
|
| 23 | - */ |
|
| 24 | - protected static function _decodeFromDER(Identifier $identifier, string $data, |
|
| 25 | - int &$offset): ElementBase |
|
| 26 | - { |
|
| 27 | - $idx = $offset; |
|
| 28 | - $type = new DERTaggedType($identifier, $data, $idx); |
|
| 29 | - $length = Length::expectFromDER($data, $idx)->intLength(); |
|
| 30 | - $offset = $idx + $length; |
|
| 31 | - return $type; |
|
| 32 | - } |
|
| 20 | + /** |
|
| 21 | + * |
|
| 22 | + * {@inheritdoc} |
|
| 23 | + */ |
|
| 24 | + protected static function _decodeFromDER(Identifier $identifier, string $data, |
|
| 25 | + int &$offset): ElementBase |
|
| 26 | + { |
|
| 27 | + $idx = $offset; |
|
| 28 | + $type = new DERTaggedType($identifier, $data, $idx); |
|
| 29 | + $length = Length::expectFromDER($data, $idx)->intLength(); |
|
| 30 | + $offset = $idx + $length; |
|
| 31 | + return $type; |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Check whether element supports explicit tagging. |
|
| 36 | - * |
|
| 37 | - * @param int|null $expectedTag Optional outer tag expectation |
|
| 38 | - * @throws \UnexpectedValueException If expectation fails |
|
| 39 | - * @return ExplicitTagging |
|
| 40 | - */ |
|
| 41 | - public function expectExplicit($expectedTag = null): ExplicitTagging |
|
| 42 | - { |
|
| 43 | - $el = $this; |
|
| 44 | - if (!$el instanceof ExplicitTagging) { |
|
| 45 | - throw new \UnexpectedValueException( |
|
| 46 | - "Element doesn't implement explicit tagging."); |
|
| 47 | - } |
|
| 48 | - if (isset($expectedTag)) { |
|
| 49 | - $el->expectTagged($expectedTag); |
|
| 50 | - } |
|
| 51 | - return $el; |
|
| 52 | - } |
|
| 34 | + /** |
|
| 35 | + * Check whether element supports explicit tagging. |
|
| 36 | + * |
|
| 37 | + * @param int|null $expectedTag Optional outer tag expectation |
|
| 38 | + * @throws \UnexpectedValueException If expectation fails |
|
| 39 | + * @return ExplicitTagging |
|
| 40 | + */ |
|
| 41 | + public function expectExplicit($expectedTag = null): ExplicitTagging |
|
| 42 | + { |
|
| 43 | + $el = $this; |
|
| 44 | + if (!$el instanceof ExplicitTagging) { |
|
| 45 | + throw new \UnexpectedValueException( |
|
| 46 | + "Element doesn't implement explicit tagging."); |
|
| 47 | + } |
|
| 48 | + if (isset($expectedTag)) { |
|
| 49 | + $el->expectTagged($expectedTag); |
|
| 50 | + } |
|
| 51 | + return $el; |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Get the wrapped inner element employing explicit tagging. |
|
| 56 | - * |
|
| 57 | - * @param int|null $expectedTag Optional outer tag expectation |
|
| 58 | - * @throws \UnexpectedValueException If expectation fails |
|
| 59 | - * @return UnspecifiedType |
|
| 60 | - */ |
|
| 61 | - public function asExplicit($expectedTag = null): UnspecifiedType |
|
| 62 | - { |
|
| 63 | - return $this->expectExplicit($expectedTag)->explicit(); |
|
| 64 | - } |
|
| 54 | + /** |
|
| 55 | + * Get the wrapped inner element employing explicit tagging. |
|
| 56 | + * |
|
| 57 | + * @param int|null $expectedTag Optional outer tag expectation |
|
| 58 | + * @throws \UnexpectedValueException If expectation fails |
|
| 59 | + * @return UnspecifiedType |
|
| 60 | + */ |
|
| 61 | + public function asExplicit($expectedTag = null): UnspecifiedType |
|
| 62 | + { |
|
| 63 | + return $this->expectExplicit($expectedTag)->explicit(); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * Check whether element supports implicit tagging. |
|
| 68 | - * |
|
| 69 | - * @param int|null $expectedTag Optional outer tag expectation |
|
| 70 | - * @throws \UnexpectedValueException If expectation fails |
|
| 71 | - * @return ImplicitTagging |
|
| 72 | - */ |
|
| 73 | - public function expectImplicit($expectedTag = null): ImplicitTagging |
|
| 74 | - { |
|
| 75 | - $el = $this; |
|
| 76 | - if (!$el instanceof ImplicitTagging) { |
|
| 77 | - throw new \UnexpectedValueException( |
|
| 78 | - "Element doesn't implement implicit tagging."); |
|
| 79 | - } |
|
| 80 | - if (isset($expectedTag)) { |
|
| 81 | - $el->expectTagged($expectedTag); |
|
| 82 | - } |
|
| 83 | - return $el; |
|
| 84 | - } |
|
| 66 | + /** |
|
| 67 | + * Check whether element supports implicit tagging. |
|
| 68 | + * |
|
| 69 | + * @param int|null $expectedTag Optional outer tag expectation |
|
| 70 | + * @throws \UnexpectedValueException If expectation fails |
|
| 71 | + * @return ImplicitTagging |
|
| 72 | + */ |
|
| 73 | + public function expectImplicit($expectedTag = null): ImplicitTagging |
|
| 74 | + { |
|
| 75 | + $el = $this; |
|
| 76 | + if (!$el instanceof ImplicitTagging) { |
|
| 77 | + throw new \UnexpectedValueException( |
|
| 78 | + "Element doesn't implement implicit tagging."); |
|
| 79 | + } |
|
| 80 | + if (isset($expectedTag)) { |
|
| 81 | + $el->expectTagged($expectedTag); |
|
| 82 | + } |
|
| 83 | + return $el; |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * Get the wrapped inner element employing implicit tagging. |
|
| 88 | - * |
|
| 89 | - * @param int $tag Type tag of the inner element |
|
| 90 | - * @param int|null $expectedTag Optional outer tag expectation |
|
| 91 | - * @param int $expectedClass Optional inner type class expectation |
|
| 92 | - * @throws \UnexpectedValueException If expectation fails |
|
| 93 | - * @return UnspecifiedType |
|
| 94 | - */ |
|
| 95 | - public function asImplicit(int $tag, $expectedTag = null, |
|
| 96 | - int $expectedClass = Identifier::CLASS_UNIVERSAL): UnspecifiedType |
|
| 97 | - { |
|
| 98 | - return $this->expectImplicit($expectedTag)->implicit($tag, |
|
| 99 | - $expectedClass); |
|
| 100 | - } |
|
| 86 | + /** |
|
| 87 | + * Get the wrapped inner element employing implicit tagging. |
|
| 88 | + * |
|
| 89 | + * @param int $tag Type tag of the inner element |
|
| 90 | + * @param int|null $expectedTag Optional outer tag expectation |
|
| 91 | + * @param int $expectedClass Optional inner type class expectation |
|
| 92 | + * @throws \UnexpectedValueException If expectation fails |
|
| 93 | + * @return UnspecifiedType |
|
| 94 | + */ |
|
| 95 | + public function asImplicit(int $tag, $expectedTag = null, |
|
| 96 | + int $expectedClass = Identifier::CLASS_UNIVERSAL): UnspecifiedType |
|
| 97 | + { |
|
| 98 | + return $this->expectImplicit($expectedTag)->implicit($tag, |
|
| 99 | + $expectedClass); |
|
| 100 | + } |
|
| 101 | 101 | } |
@@ -11,87 +11,87 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | abstract class TimeType extends Element |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * UTC timezone. |
|
| 16 | - * |
|
| 17 | - * @var string |
|
| 18 | - */ |
|
| 19 | - const TZ_UTC = "UTC"; |
|
| 14 | + /** |
|
| 15 | + * UTC timezone. |
|
| 16 | + * |
|
| 17 | + * @var string |
|
| 18 | + */ |
|
| 19 | + const TZ_UTC = "UTC"; |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Date and time. |
|
| 23 | - * |
|
| 24 | - * @var \DateTimeImmutable $_dateTime |
|
| 25 | - */ |
|
| 26 | - protected $_dateTime; |
|
| 21 | + /** |
|
| 22 | + * Date and time. |
|
| 23 | + * |
|
| 24 | + * @var \DateTimeImmutable $_dateTime |
|
| 25 | + */ |
|
| 26 | + protected $_dateTime; |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * Constructor. |
|
| 30 | - * |
|
| 31 | - * @param \DateTimeImmutable $dt |
|
| 32 | - */ |
|
| 33 | - public function __construct(\DateTimeImmutable $dt) |
|
| 34 | - { |
|
| 35 | - $this->_dateTime = $dt; |
|
| 36 | - } |
|
| 28 | + /** |
|
| 29 | + * Constructor. |
|
| 30 | + * |
|
| 31 | + * @param \DateTimeImmutable $dt |
|
| 32 | + */ |
|
| 33 | + public function __construct(\DateTimeImmutable $dt) |
|
| 34 | + { |
|
| 35 | + $this->_dateTime = $dt; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Initialize from datetime string. |
|
| 40 | - * |
|
| 41 | - * @param string $time Time string |
|
| 42 | - * @param string|null $tz Timezone, if null use default. |
|
| 43 | - * @throws \RuntimeException |
|
| 44 | - * @return self |
|
| 45 | - */ |
|
| 46 | - public static function fromString(string $time, string $tz = null): self |
|
| 47 | - { |
|
| 48 | - try { |
|
| 49 | - if (!isset($tz)) { |
|
| 50 | - $tz = date_default_timezone_get(); |
|
| 51 | - } |
|
| 52 | - return new static( |
|
| 53 | - new \DateTimeImmutable($time, self::_createTimeZone($tz))); |
|
| 54 | - } catch (\Exception $e) { |
|
| 55 | - throw new \RuntimeException( |
|
| 56 | - "Failed to create DateTime: " . |
|
| 57 | - self::_getLastDateTimeImmutableErrorsStr(), 0, $e); |
|
| 58 | - } |
|
| 59 | - } |
|
| 38 | + /** |
|
| 39 | + * Initialize from datetime string. |
|
| 40 | + * |
|
| 41 | + * @param string $time Time string |
|
| 42 | + * @param string|null $tz Timezone, if null use default. |
|
| 43 | + * @throws \RuntimeException |
|
| 44 | + * @return self |
|
| 45 | + */ |
|
| 46 | + public static function fromString(string $time, string $tz = null): self |
|
| 47 | + { |
|
| 48 | + try { |
|
| 49 | + if (!isset($tz)) { |
|
| 50 | + $tz = date_default_timezone_get(); |
|
| 51 | + } |
|
| 52 | + return new static( |
|
| 53 | + new \DateTimeImmutable($time, self::_createTimeZone($tz))); |
|
| 54 | + } catch (\Exception $e) { |
|
| 55 | + throw new \RuntimeException( |
|
| 56 | + "Failed to create DateTime: " . |
|
| 57 | + self::_getLastDateTimeImmutableErrorsStr(), 0, $e); |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Get the date and time. |
|
| 63 | - * |
|
| 64 | - * @return \DateTimeImmutable |
|
| 65 | - */ |
|
| 66 | - public function dateTime(): \DateTimeImmutable |
|
| 67 | - { |
|
| 68 | - return $this->_dateTime; |
|
| 69 | - } |
|
| 61 | + /** |
|
| 62 | + * Get the date and time. |
|
| 63 | + * |
|
| 64 | + * @return \DateTimeImmutable |
|
| 65 | + */ |
|
| 66 | + public function dateTime(): \DateTimeImmutable |
|
| 67 | + { |
|
| 68 | + return $this->_dateTime; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Create DateTimeZone object from string. |
|
| 73 | - * |
|
| 74 | - * @param string $tz |
|
| 75 | - * @throws \UnexpectedValueException If timezone is invalid |
|
| 76 | - * @return \DateTimeZone |
|
| 77 | - */ |
|
| 78 | - protected static function _createTimeZone(string $tz): \DateTimeZone |
|
| 79 | - { |
|
| 80 | - try { |
|
| 81 | - return new \DateTimeZone($tz); |
|
| 82 | - } catch (\Exception $e) { |
|
| 83 | - throw new \UnexpectedValueException("Invalid timezone.", 0, $e); |
|
| 84 | - } |
|
| 85 | - } |
|
| 71 | + /** |
|
| 72 | + * Create DateTimeZone object from string. |
|
| 73 | + * |
|
| 74 | + * @param string $tz |
|
| 75 | + * @throws \UnexpectedValueException If timezone is invalid |
|
| 76 | + * @return \DateTimeZone |
|
| 77 | + */ |
|
| 78 | + protected static function _createTimeZone(string $tz): \DateTimeZone |
|
| 79 | + { |
|
| 80 | + try { |
|
| 81 | + return new \DateTimeZone($tz); |
|
| 82 | + } catch (\Exception $e) { |
|
| 83 | + throw new \UnexpectedValueException("Invalid timezone.", 0, $e); |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * Get last error caused by DateTimeImmutable. |
|
| 89 | - * |
|
| 90 | - * @return string |
|
| 91 | - */ |
|
| 92 | - protected static function _getLastDateTimeImmutableErrorsStr(): string |
|
| 93 | - { |
|
| 94 | - $errors = \DateTimeImmutable::getLastErrors()["errors"]; |
|
| 95 | - return implode(", ", $errors); |
|
| 96 | - } |
|
| 87 | + /** |
|
| 88 | + * Get last error caused by DateTimeImmutable. |
|
| 89 | + * |
|
| 90 | + * @return string |
|
| 91 | + */ |
|
| 92 | + protected static function _getLastDateTimeImmutableErrorsStr(): string |
|
| 93 | + { |
|
| 94 | + $errors = \DateTimeImmutable::getLastErrors()["errors"]; |
|
| 95 | + return implode(", ", $errors); |
|
| 96 | + } |
|
| 97 | 97 | } |
@@ -20,105 +20,105 @@ |
||
| 20 | 20 | * May be encoded back to complete DER encoding. |
| 21 | 21 | */ |
| 22 | 22 | class DERTaggedType extends TaggedType implements |
| 23 | - ExplicitTagging, |
|
| 24 | - ImplicitTagging |
|
| 23 | + ExplicitTagging, |
|
| 24 | + ImplicitTagging |
|
| 25 | 25 | { |
| 26 | - /** |
|
| 27 | - * Identifier. |
|
| 28 | - * |
|
| 29 | - * @var Identifier |
|
| 30 | - */ |
|
| 31 | - private $_identifier; |
|
| 26 | + /** |
|
| 27 | + * Identifier. |
|
| 28 | + * |
|
| 29 | + * @var Identifier |
|
| 30 | + */ |
|
| 31 | + private $_identifier; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * DER data. |
|
| 35 | - * |
|
| 36 | - * @var string |
|
| 37 | - */ |
|
| 38 | - private $_data; |
|
| 33 | + /** |
|
| 34 | + * DER data. |
|
| 35 | + * |
|
| 36 | + * @var string |
|
| 37 | + */ |
|
| 38 | + private $_data; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Offset to data. |
|
| 42 | - * |
|
| 43 | - * @var int |
|
| 44 | - */ |
|
| 45 | - private $_offset; |
|
| 40 | + /** |
|
| 41 | + * Offset to data. |
|
| 42 | + * |
|
| 43 | + * @var int |
|
| 44 | + */ |
|
| 45 | + private $_offset; |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Constructor. |
|
| 49 | - * |
|
| 50 | - * @param Identifier $identifier |
|
| 51 | - * @param string $data |
|
| 52 | - * @param int $offset Offset to next byte after identifier |
|
| 53 | - */ |
|
| 54 | - public function __construct(Identifier $identifier, string $data, int $offset) |
|
| 55 | - { |
|
| 56 | - $this->_identifier = $identifier; |
|
| 57 | - $this->_data = $data; |
|
| 58 | - $this->_offset = $offset; |
|
| 59 | - $this->_typeTag = $identifier->intTag(); |
|
| 60 | - } |
|
| 47 | + /** |
|
| 48 | + * Constructor. |
|
| 49 | + * |
|
| 50 | + * @param Identifier $identifier |
|
| 51 | + * @param string $data |
|
| 52 | + * @param int $offset Offset to next byte after identifier |
|
| 53 | + */ |
|
| 54 | + public function __construct(Identifier $identifier, string $data, int $offset) |
|
| 55 | + { |
|
| 56 | + $this->_identifier = $identifier; |
|
| 57 | + $this->_data = $data; |
|
| 58 | + $this->_offset = $offset; |
|
| 59 | + $this->_typeTag = $identifier->intTag(); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * |
|
| 64 | - * @see \ASN1\Element::typeClass() |
|
| 65 | - * @return int |
|
| 66 | - */ |
|
| 67 | - public function typeClass(): int |
|
| 68 | - { |
|
| 69 | - return $this->_identifier->typeClass(); |
|
| 70 | - } |
|
| 62 | + /** |
|
| 63 | + * |
|
| 64 | + * @see \ASN1\Element::typeClass() |
|
| 65 | + * @return int |
|
| 66 | + */ |
|
| 67 | + public function typeClass(): int |
|
| 68 | + { |
|
| 69 | + return $this->_identifier->typeClass(); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * |
|
| 74 | - * @see \ASN1\Element::isConstructed() |
|
| 75 | - * @return bool |
|
| 76 | - */ |
|
| 77 | - public function isConstructed(): bool |
|
| 78 | - { |
|
| 79 | - return $this->_identifier->isConstructed(); |
|
| 80 | - } |
|
| 72 | + /** |
|
| 73 | + * |
|
| 74 | + * @see \ASN1\Element::isConstructed() |
|
| 75 | + * @return bool |
|
| 76 | + */ |
|
| 77 | + public function isConstructed(): bool |
|
| 78 | + { |
|
| 79 | + return $this->_identifier->isConstructed(); |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * |
|
| 84 | - * @see \ASN1\Element::_encodedContentDER() |
|
| 85 | - * @return string |
|
| 86 | - */ |
|
| 87 | - protected function _encodedContentDER(): string |
|
| 88 | - { |
|
| 89 | - $idx = $this->_offset; |
|
| 90 | - $length = Length::expectFromDER($this->_data, $idx)->intLength(); |
|
| 91 | - return substr($this->_data, $idx, $length); |
|
| 92 | - } |
|
| 82 | + /** |
|
| 83 | + * |
|
| 84 | + * @see \ASN1\Element::_encodedContentDER() |
|
| 85 | + * @return string |
|
| 86 | + */ |
|
| 87 | + protected function _encodedContentDER(): string |
|
| 88 | + { |
|
| 89 | + $idx = $this->_offset; |
|
| 90 | + $length = Length::expectFromDER($this->_data, $idx)->intLength(); |
|
| 91 | + return substr($this->_data, $idx, $length); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * |
|
| 96 | - * {@inheritdoc} |
|
| 97 | - * @see \ASN1\Type\Tagged\ImplicitTagging::implicit() |
|
| 98 | - * @return UnspecifiedType |
|
| 99 | - */ |
|
| 100 | - public function implicit(int $tag, int $class = Identifier::CLASS_UNIVERSAL): UnspecifiedType |
|
| 101 | - { |
|
| 102 | - $identifier = $this->_identifier->withClass($class)->withTag($tag); |
|
| 103 | - $cls = self::_determineImplClass($identifier); |
|
| 104 | - $idx = $this->_offset; |
|
| 105 | - $element = $cls::_decodeFromDER($identifier, $this->_data, $idx); |
|
| 106 | - return new UnspecifiedType($element); |
|
| 107 | - } |
|
| 94 | + /** |
|
| 95 | + * |
|
| 96 | + * {@inheritdoc} |
|
| 97 | + * @see \ASN1\Type\Tagged\ImplicitTagging::implicit() |
|
| 98 | + * @return UnspecifiedType |
|
| 99 | + */ |
|
| 100 | + public function implicit(int $tag, int $class = Identifier::CLASS_UNIVERSAL): UnspecifiedType |
|
| 101 | + { |
|
| 102 | + $identifier = $this->_identifier->withClass($class)->withTag($tag); |
|
| 103 | + $cls = self::_determineImplClass($identifier); |
|
| 104 | + $idx = $this->_offset; |
|
| 105 | + $element = $cls::_decodeFromDER($identifier, $this->_data, $idx); |
|
| 106 | + return new UnspecifiedType($element); |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * |
|
| 111 | - * @see \ASN1\Type\Tagged\ExplicitTagging::explicit() |
|
| 112 | - * @return UnspecifiedType |
|
| 113 | - */ |
|
| 114 | - public function explicit($expectedTag = null): UnspecifiedType |
|
| 115 | - { |
|
| 116 | - $idx = $this->_offset; |
|
| 117 | - Length::expectFromDER($this->_data, $idx); |
|
| 118 | - $element = Element::fromDER($this->_data, $idx); |
|
| 119 | - if (isset($expectedTag)) { |
|
| 120 | - $element->expectType($expectedTag); |
|
| 121 | - } |
|
| 122 | - return new UnspecifiedType($element); |
|
| 123 | - } |
|
| 109 | + /** |
|
| 110 | + * |
|
| 111 | + * @see \ASN1\Type\Tagged\ExplicitTagging::explicit() |
|
| 112 | + * @return UnspecifiedType |
|
| 113 | + */ |
|
| 114 | + public function explicit($expectedTag = null): UnspecifiedType |
|
| 115 | + { |
|
| 116 | + $idx = $this->_offset; |
|
| 117 | + Length::expectFromDER($this->_data, $idx); |
|
| 118 | + $element = Element::fromDER($this->_data, $idx); |
|
| 119 | + if (isset($expectedTag)) { |
|
| 120 | + $element->expectType($expectedTag); |
|
| 121 | + } |
|
| 122 | + return new UnspecifiedType($element); |
|
| 123 | + } |
|
| 124 | 124 | } |
@@ -16,56 +16,56 @@ |
||
| 16 | 16 | * decoding the data. |
| 17 | 17 | */ |
| 18 | 18 | class ImplicitlyTaggedType extends ContextSpecificTaggedType implements |
| 19 | - ImplicitTagging |
|
| 19 | + ImplicitTagging |
|
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * Constructor. |
|
| 23 | - * |
|
| 24 | - * @param int $tag |
|
| 25 | - * @param Element $element |
|
| 26 | - */ |
|
| 27 | - public function __construct(int $tag, Element $element) |
|
| 28 | - { |
|
| 29 | - $this->_typeTag = $tag; |
|
| 30 | - $this->_element = $element; |
|
| 31 | - } |
|
| 21 | + /** |
|
| 22 | + * Constructor. |
|
| 23 | + * |
|
| 24 | + * @param int $tag |
|
| 25 | + * @param Element $element |
|
| 26 | + */ |
|
| 27 | + public function __construct(int $tag, Element $element) |
|
| 28 | + { |
|
| 29 | + $this->_typeTag = $tag; |
|
| 30 | + $this->_element = $element; |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * |
|
| 35 | - * @see \ASN1\Element::isConstructed() |
|
| 36 | - * @return bool |
|
| 37 | - */ |
|
| 38 | - public function isConstructed(): bool |
|
| 39 | - { |
|
| 40 | - // depends on the underlying type |
|
| 41 | - return $this->_element->isConstructed(); |
|
| 42 | - } |
|
| 33 | + /** |
|
| 34 | + * |
|
| 35 | + * @see \ASN1\Element::isConstructed() |
|
| 36 | + * @return bool |
|
| 37 | + */ |
|
| 38 | + public function isConstructed(): bool |
|
| 39 | + { |
|
| 40 | + // depends on the underlying type |
|
| 41 | + return $this->_element->isConstructed(); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * |
|
| 46 | - * @see \ASN1\Element::_encodedContentDER() |
|
| 47 | - * @return string |
|
| 48 | - */ |
|
| 49 | - protected function _encodedContentDER(): string |
|
| 50 | - { |
|
| 51 | - return $this->_element->_encodedContentDER(); |
|
| 52 | - } |
|
| 44 | + /** |
|
| 45 | + * |
|
| 46 | + * @see \ASN1\Element::_encodedContentDER() |
|
| 47 | + * @return string |
|
| 48 | + */ |
|
| 49 | + protected function _encodedContentDER(): string |
|
| 50 | + { |
|
| 51 | + return $this->_element->_encodedContentDER(); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * |
|
| 56 | - * {@inheritdoc} |
|
| 57 | - * @see \ASN1\Type\Tagged\ImplicitTagging::implicit() |
|
| 58 | - * @return UnspecifiedType |
|
| 59 | - */ |
|
| 60 | - public function implicit(int $tag, int $class = Identifier::CLASS_UNIVERSAL): UnspecifiedType |
|
| 61 | - { |
|
| 62 | - $this->_element->expectType($tag); |
|
| 63 | - if ($this->_element->typeClass() != $class) { |
|
| 64 | - throw new \UnexpectedValueException( |
|
| 65 | - sprintf("Type class %s expected, got %s.", |
|
| 66 | - Identifier::classToName($class), |
|
| 67 | - Identifier::classToName($this->_element->typeClass()))); |
|
| 68 | - } |
|
| 69 | - return new UnspecifiedType($this->_element); |
|
| 70 | - } |
|
| 54 | + /** |
|
| 55 | + * |
|
| 56 | + * {@inheritdoc} |
|
| 57 | + * @see \ASN1\Type\Tagged\ImplicitTagging::implicit() |
|
| 58 | + * @return UnspecifiedType |
|
| 59 | + */ |
|
| 60 | + public function implicit(int $tag, int $class = Identifier::CLASS_UNIVERSAL): UnspecifiedType |
|
| 61 | + { |
|
| 62 | + $this->_element->expectType($tag); |
|
| 63 | + if ($this->_element->typeClass() != $class) { |
|
| 64 | + throw new \UnexpectedValueException( |
|
| 65 | + sprintf("Type class %s expected, got %s.", |
|
| 66 | + Identifier::classToName($class), |
|
| 67 | + Identifier::classToName($this->_element->typeClass()))); |
|
| 68 | + } |
|
| 69 | + return new UnspecifiedType($this->_element); |
|
| 70 | + } |
|
| 71 | 71 | } |
@@ -14,51 +14,51 @@ |
||
| 14 | 14 | * is not changed. |
| 15 | 15 | */ |
| 16 | 16 | class ExplicitlyTaggedType extends ContextSpecificTaggedType implements |
| 17 | - ExplicitTagging |
|
| 17 | + ExplicitTagging |
|
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * Constructor. |
|
| 21 | - * |
|
| 22 | - * @param int $tag Tag number |
|
| 23 | - * @param Element $element Wrapped element |
|
| 24 | - */ |
|
| 25 | - public function __construct(int $tag, Element $element) |
|
| 26 | - { |
|
| 27 | - $this->_typeTag = $tag; |
|
| 28 | - $this->_element = $element; |
|
| 29 | - } |
|
| 19 | + /** |
|
| 20 | + * Constructor. |
|
| 21 | + * |
|
| 22 | + * @param int $tag Tag number |
|
| 23 | + * @param Element $element Wrapped element |
|
| 24 | + */ |
|
| 25 | + public function __construct(int $tag, Element $element) |
|
| 26 | + { |
|
| 27 | + $this->_typeTag = $tag; |
|
| 28 | + $this->_element = $element; |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * |
|
| 33 | - * @see \ASN1\Element::isConstructed() |
|
| 34 | - * @return bool |
|
| 35 | - */ |
|
| 36 | - public function isConstructed(): bool |
|
| 37 | - { |
|
| 38 | - return true; |
|
| 39 | - } |
|
| 31 | + /** |
|
| 32 | + * |
|
| 33 | + * @see \ASN1\Element::isConstructed() |
|
| 34 | + * @return bool |
|
| 35 | + */ |
|
| 36 | + public function isConstructed(): bool |
|
| 37 | + { |
|
| 38 | + return true; |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * |
|
| 43 | - * @see \ASN1\Element::_encodedContentDER() |
|
| 44 | - * @return string |
|
| 45 | - */ |
|
| 46 | - protected function _encodedContentDER(): string |
|
| 47 | - { |
|
| 48 | - return $this->_element->toDER(); |
|
| 49 | - } |
|
| 41 | + /** |
|
| 42 | + * |
|
| 43 | + * @see \ASN1\Element::_encodedContentDER() |
|
| 44 | + * @return string |
|
| 45 | + */ |
|
| 46 | + protected function _encodedContentDER(): string |
|
| 47 | + { |
|
| 48 | + return $this->_element->toDER(); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * |
|
| 53 | - * {@inheritdoc} |
|
| 54 | - * @see \ASN1\Type\Tagged\ExplicitTagging::explicit() |
|
| 55 | - * @return UnspecifiedType |
|
| 56 | - */ |
|
| 57 | - public function explicit($expectedTag = null): UnspecifiedType |
|
| 58 | - { |
|
| 59 | - if (isset($expectedTag)) { |
|
| 60 | - $this->_element->expectType($expectedTag); |
|
| 61 | - } |
|
| 62 | - return new UnspecifiedType($this->_element); |
|
| 63 | - } |
|
| 51 | + /** |
|
| 52 | + * |
|
| 53 | + * {@inheritdoc} |
|
| 54 | + * @see \ASN1\Type\Tagged\ExplicitTagging::explicit() |
|
| 55 | + * @return UnspecifiedType |
|
| 56 | + */ |
|
| 57 | + public function explicit($expectedTag = null): UnspecifiedType |
|
| 58 | + { |
|
| 59 | + if (isset($expectedTag)) { |
|
| 60 | + $this->_element->expectType($expectedTag); |
|
| 61 | + } |
|
| 62 | + return new UnspecifiedType($this->_element); |
|
| 63 | + } |
|
| 64 | 64 | } |