@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace ASN1\Type\Primitive; |
6 | 6 |
@@ -16,64 +16,64 @@ |
||
16 | 16 | */ |
17 | 17 | class Boolean extends Element |
18 | 18 | { |
19 | - use UniversalClass; |
|
20 | - use PrimitiveType; |
|
19 | + use UniversalClass; |
|
20 | + use PrimitiveType; |
|
21 | 21 | |
22 | - /** |
|
23 | - * Value. |
|
24 | - * |
|
25 | - * @var bool |
|
26 | - */ |
|
27 | - private $_bool; |
|
22 | + /** |
|
23 | + * Value. |
|
24 | + * |
|
25 | + * @var bool |
|
26 | + */ |
|
27 | + private $_bool; |
|
28 | 28 | |
29 | - /** |
|
30 | - * Constructor. |
|
31 | - * |
|
32 | - * @param bool $bool |
|
33 | - */ |
|
34 | - public function __construct(bool $bool) |
|
35 | - { |
|
36 | - $this->_typeTag = self::TYPE_BOOLEAN; |
|
37 | - $this->_bool = $bool; |
|
38 | - } |
|
29 | + /** |
|
30 | + * Constructor. |
|
31 | + * |
|
32 | + * @param bool $bool |
|
33 | + */ |
|
34 | + public function __construct(bool $bool) |
|
35 | + { |
|
36 | + $this->_typeTag = self::TYPE_BOOLEAN; |
|
37 | + $this->_bool = $bool; |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * Get the value. |
|
42 | - * |
|
43 | - * @return bool |
|
44 | - */ |
|
45 | - public function value(): bool |
|
46 | - { |
|
47 | - return $this->_bool; |
|
48 | - } |
|
40 | + /** |
|
41 | + * Get the value. |
|
42 | + * |
|
43 | + * @return bool |
|
44 | + */ |
|
45 | + public function value(): bool |
|
46 | + { |
|
47 | + return $this->_bool; |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * |
|
52 | - * {@inheritdoc} |
|
53 | - */ |
|
54 | - protected function _encodedContentDER(): string |
|
55 | - { |
|
56 | - return $this->_bool ? chr(0xff) : chr(0); |
|
57 | - } |
|
50 | + /** |
|
51 | + * |
|
52 | + * {@inheritdoc} |
|
53 | + */ |
|
54 | + protected function _encodedContentDER(): string |
|
55 | + { |
|
56 | + return $this->_bool ? chr(0xff) : chr(0); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * |
|
61 | - * {@inheritdoc} |
|
62 | - * @return self |
|
63 | - */ |
|
64 | - protected static function _decodeFromDER(Identifier $identifier, |
|
65 | - string $data, int &$offset): ElementBase |
|
66 | - { |
|
67 | - $idx = $offset; |
|
68 | - Length::expectFromDER($data, $idx, 1); |
|
69 | - $byte = ord($data[$idx++]); |
|
70 | - if ($byte !== 0) { |
|
71 | - if ($byte != 0xff) { |
|
72 | - throw new DecodeException( |
|
73 | - "DER encoded boolean true must have all bits set to 1."); |
|
74 | - } |
|
75 | - } |
|
76 | - $offset = $idx; |
|
77 | - return new self($byte !== 0); |
|
78 | - } |
|
59 | + /** |
|
60 | + * |
|
61 | + * {@inheritdoc} |
|
62 | + * @return self |
|
63 | + */ |
|
64 | + protected static function _decodeFromDER(Identifier $identifier, |
|
65 | + string $data, int &$offset): ElementBase |
|
66 | + { |
|
67 | + $idx = $offset; |
|
68 | + Length::expectFromDER($data, $idx, 1); |
|
69 | + $byte = ord($data[$idx++]); |
|
70 | + if ($byte !== 0) { |
|
71 | + if ($byte != 0xff) { |
|
72 | + throw new DecodeException( |
|
73 | + "DER encoded boolean true must have all bits set to 1."); |
|
74 | + } |
|
75 | + } |
|
76 | + $offset = $idx; |
|
77 | + return new self($byte !== 0); |
|
78 | + } |
|
79 | 79 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace ASN1\Type\Primitive; |
6 | 6 |
@@ -16,195 +16,195 @@ |
||
16 | 16 | */ |
17 | 17 | class BitString extends StringType |
18 | 18 | { |
19 | - use UniversalClass; |
|
20 | - use PrimitiveType; |
|
19 | + use UniversalClass; |
|
20 | + use PrimitiveType; |
|
21 | 21 | |
22 | - /** |
|
23 | - * Number of unused bits in the last octet. |
|
24 | - * |
|
25 | - * @var int $_unusedBits |
|
26 | - */ |
|
27 | - protected $_unusedBits; |
|
22 | + /** |
|
23 | + * Number of unused bits in the last octet. |
|
24 | + * |
|
25 | + * @var int $_unusedBits |
|
26 | + */ |
|
27 | + protected $_unusedBits; |
|
28 | 28 | |
29 | - /** |
|
30 | - * Constructor. |
|
31 | - * |
|
32 | - * @param string $string Content octets |
|
33 | - * @param int $unused_bits Number of unused bits in the last octet |
|
34 | - */ |
|
35 | - public function __construct(string $string, int $unused_bits = 0) |
|
36 | - { |
|
37 | - $this->_typeTag = self::TYPE_BIT_STRING; |
|
38 | - parent::__construct($string); |
|
39 | - $this->_unusedBits = $unused_bits; |
|
40 | - } |
|
29 | + /** |
|
30 | + * Constructor. |
|
31 | + * |
|
32 | + * @param string $string Content octets |
|
33 | + * @param int $unused_bits Number of unused bits in the last octet |
|
34 | + */ |
|
35 | + public function __construct(string $string, int $unused_bits = 0) |
|
36 | + { |
|
37 | + $this->_typeTag = self::TYPE_BIT_STRING; |
|
38 | + parent::__construct($string); |
|
39 | + $this->_unusedBits = $unused_bits; |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * Get the number of bits in the string. |
|
44 | - * |
|
45 | - * @return int |
|
46 | - */ |
|
47 | - public function numBits(): int |
|
48 | - { |
|
49 | - return strlen($this->_string) * 8 - $this->_unusedBits; |
|
50 | - } |
|
42 | + /** |
|
43 | + * Get the number of bits in the string. |
|
44 | + * |
|
45 | + * @return int |
|
46 | + */ |
|
47 | + public function numBits(): int |
|
48 | + { |
|
49 | + return strlen($this->_string) * 8 - $this->_unusedBits; |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Get the number of unused bits in the last octet of the string. |
|
54 | - * |
|
55 | - * @return int |
|
56 | - */ |
|
57 | - public function unusedBits(): int |
|
58 | - { |
|
59 | - return $this->_unusedBits; |
|
60 | - } |
|
52 | + /** |
|
53 | + * Get the number of unused bits in the last octet of the string. |
|
54 | + * |
|
55 | + * @return int |
|
56 | + */ |
|
57 | + public function unusedBits(): int |
|
58 | + { |
|
59 | + return $this->_unusedBits; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Test whether bit is set. |
|
64 | - * |
|
65 | - * @param int $idx Bit index. |
|
66 | - * Most significant bit of the first octet is index 0. |
|
67 | - * @return bool |
|
68 | - */ |
|
69 | - public function testBit(int $idx): bool |
|
70 | - { |
|
71 | - // octet index |
|
72 | - $oi = (int) floor($idx / 8); |
|
73 | - // if octet is outside range |
|
74 | - if ($oi < 0 || $oi >= strlen($this->_string)) { |
|
75 | - throw new \OutOfBoundsException("Index is out of bounds."); |
|
76 | - } |
|
77 | - // bit index |
|
78 | - $bi = $idx % 8; |
|
79 | - // if tested bit is last octet's unused bit |
|
80 | - if ($oi == strlen($this->_string) - 1) { |
|
81 | - if ($bi >= 8 - $this->_unusedBits) { |
|
82 | - throw new \OutOfBoundsException( |
|
83 | - "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 | - } |
|
62 | + /** |
|
63 | + * Test whether bit is set. |
|
64 | + * |
|
65 | + * @param int $idx Bit index. |
|
66 | + * Most significant bit of the first octet is index 0. |
|
67 | + * @return bool |
|
68 | + */ |
|
69 | + public function testBit(int $idx): bool |
|
70 | + { |
|
71 | + // octet index |
|
72 | + $oi = (int) floor($idx / 8); |
|
73 | + // if octet is outside range |
|
74 | + if ($oi < 0 || $oi >= strlen($this->_string)) { |
|
75 | + throw new \OutOfBoundsException("Index is out of bounds."); |
|
76 | + } |
|
77 | + // bit index |
|
78 | + $bi = $idx % 8; |
|
79 | + // if tested bit is last octet's unused bit |
|
80 | + if ($oi == strlen($this->_string) - 1) { |
|
81 | + if ($bi >= 8 - $this->_unusedBits) { |
|
82 | + throw new \OutOfBoundsException( |
|
83 | + "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, |
|
182 | - string $data, 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, |
|
182 | + string $data, 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 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace ASN1\Type\Primitive; |
6 | 6 |
@@ -16,73 +16,73 @@ |
||
16 | 16 | */ |
17 | 17 | class UTCTime extends TimeType |
18 | 18 | { |
19 | - use UniversalClass; |
|
20 | - use PrimitiveType; |
|
19 | + use UniversalClass; |
|
20 | + use PrimitiveType; |
|
21 | 21 | |
22 | - /** |
|
23 | - * Regular expression to parse date. |
|
24 | - * |
|
25 | - * DER restricts format to UTC timezone (Z suffix). |
|
26 | - * |
|
27 | - * @var string |
|
28 | - */ |
|
29 | - const REGEX = /* @formatter:off */ '#^' . |
|
30 | - '(\d\d)' . /* YY */ |
|
31 | - '(\d\d)' . /* MM */ |
|
32 | - '(\d\d)' . /* DD */ |
|
33 | - '(\d\d)' . /* hh */ |
|
34 | - '(\d\d)' . /* mm */ |
|
35 | - '(\d\d)' . /* ss */ |
|
36 | - 'Z' . /* TZ */ |
|
37 | - '$#' /* @formatter:on */; |
|
22 | + /** |
|
23 | + * Regular expression to parse date. |
|
24 | + * |
|
25 | + * DER restricts format to UTC timezone (Z suffix). |
|
26 | + * |
|
27 | + * @var string |
|
28 | + */ |
|
29 | + const REGEX = /* @formatter:off */ '#^' . |
|
30 | + '(\d\d)' . /* YY */ |
|
31 | + '(\d\d)' . /* MM */ |
|
32 | + '(\d\d)' . /* DD */ |
|
33 | + '(\d\d)' . /* hh */ |
|
34 | + '(\d\d)' . /* mm */ |
|
35 | + '(\d\d)' . /* ss */ |
|
36 | + 'Z' . /* TZ */ |
|
37 | + '$#' /* @formatter:on */; |
|
38 | 38 | |
39 | - /** |
|
40 | - * Constructor. |
|
41 | - * |
|
42 | - * @param \DateTimeImmutable $dt |
|
43 | - */ |
|
44 | - public function __construct(\DateTimeImmutable $dt) |
|
45 | - { |
|
46 | - $this->_typeTag = self::TYPE_UTC_TIME; |
|
47 | - parent::__construct($dt); |
|
48 | - } |
|
39 | + /** |
|
40 | + * Constructor. |
|
41 | + * |
|
42 | + * @param \DateTimeImmutable $dt |
|
43 | + */ |
|
44 | + public function __construct(\DateTimeImmutable $dt) |
|
45 | + { |
|
46 | + $this->_typeTag = self::TYPE_UTC_TIME; |
|
47 | + parent::__construct($dt); |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * |
|
52 | - * {@inheritdoc} |
|
53 | - */ |
|
54 | - protected function _encodedContentDER(): string |
|
55 | - { |
|
56 | - $dt = $this->_dateTime->setTimezone(self::_createTimeZone(self::TZ_UTC)); |
|
57 | - return $dt->format("ymdHis\Z"); |
|
58 | - } |
|
50 | + /** |
|
51 | + * |
|
52 | + * {@inheritdoc} |
|
53 | + */ |
|
54 | + protected function _encodedContentDER(): string |
|
55 | + { |
|
56 | + $dt = $this->_dateTime->setTimezone(self::_createTimeZone(self::TZ_UTC)); |
|
57 | + return $dt->format("ymdHis\Z"); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * |
|
62 | - * {@inheritdoc} |
|
63 | - * @return self |
|
64 | - */ |
|
65 | - protected static function _decodeFromDER(Identifier $identifier, |
|
66 | - string $data, int &$offset): ElementBase |
|
67 | - { |
|
68 | - $idx = $offset; |
|
69 | - $length = Length::expectFromDER($data, $idx)->intLength(); |
|
70 | - $str = substr($data, $idx, $length); |
|
71 | - $idx += $length; |
|
72 | - /** @var $match string[] */ |
|
73 | - if (!preg_match(self::REGEX, $str, $match)) { |
|
74 | - throw new DecodeException("Invalid UTCTime format."); |
|
75 | - } |
|
76 | - list(, $year, $month, $day, $hour, $minute, $second) = $match; |
|
77 | - $time = $year . $month . $day . $hour . $minute . $second . self::TZ_UTC; |
|
78 | - $dt = \DateTimeImmutable::createFromFormat("!ymdHisT", $time, |
|
79 | - self::_createTimeZone(self::TZ_UTC)); |
|
80 | - if (!$dt) { |
|
81 | - throw new DecodeException( |
|
82 | - "Failed to decode UTCTime: " . |
|
83 | - self::_getLastDateTimeImmutableErrorsStr()); |
|
84 | - } |
|
85 | - $offset = $idx; |
|
86 | - return new self($dt); |
|
87 | - } |
|
60 | + /** |
|
61 | + * |
|
62 | + * {@inheritdoc} |
|
63 | + * @return self |
|
64 | + */ |
|
65 | + protected static function _decodeFromDER(Identifier $identifier, |
|
66 | + string $data, int &$offset): ElementBase |
|
67 | + { |
|
68 | + $idx = $offset; |
|
69 | + $length = Length::expectFromDER($data, $idx)->intLength(); |
|
70 | + $str = substr($data, $idx, $length); |
|
71 | + $idx += $length; |
|
72 | + /** @var $match string[] */ |
|
73 | + if (!preg_match(self::REGEX, $str, $match)) { |
|
74 | + throw new DecodeException("Invalid UTCTime format."); |
|
75 | + } |
|
76 | + list(, $year, $month, $day, $hour, $minute, $second) = $match; |
|
77 | + $time = $year . $month . $day . $hour . $minute . $second . self::TZ_UTC; |
|
78 | + $dt = \DateTimeImmutable::createFromFormat("!ymdHisT", $time, |
|
79 | + self::_createTimeZone(self::TZ_UTC)); |
|
80 | + if (!$dt) { |
|
81 | + throw new DecodeException( |
|
82 | + "Failed to decode UTCTime: " . |
|
83 | + self::_getLastDateTimeImmutableErrorsStr()); |
|
84 | + } |
|
85 | + $offset = $idx; |
|
86 | + return new self($dt); |
|
87 | + } |
|
88 | 88 | } |
@@ -12,39 +12,39 @@ |
||
12 | 12 | */ |
13 | 13 | class RelativeOID extends ObjectIdentifier |
14 | 14 | { |
15 | - /** |
|
16 | - * Constructor. |
|
17 | - * |
|
18 | - * @param string $oid OID in dotted format |
|
19 | - */ |
|
20 | - public function __construct(string $oid) |
|
21 | - { |
|
22 | - $this->_oid = $oid; |
|
23 | - $this->_subids = self::_explodeDottedOID($oid); |
|
24 | - $this->_typeTag = self::TYPE_RELATIVE_OID; |
|
25 | - } |
|
15 | + /** |
|
16 | + * Constructor. |
|
17 | + * |
|
18 | + * @param string $oid OID in dotted format |
|
19 | + */ |
|
20 | + public function __construct(string $oid) |
|
21 | + { |
|
22 | + $this->_oid = $oid; |
|
23 | + $this->_subids = self::_explodeDottedOID($oid); |
|
24 | + $this->_typeTag = self::TYPE_RELATIVE_OID; |
|
25 | + } |
|
26 | 26 | |
27 | - /** |
|
28 | - * |
|
29 | - * {@inheritdoc} |
|
30 | - */ |
|
31 | - protected function _encodedContentDER(): string |
|
32 | - { |
|
33 | - return self::_encodeSubIDs(...$this->_subids); |
|
34 | - } |
|
27 | + /** |
|
28 | + * |
|
29 | + * {@inheritdoc} |
|
30 | + */ |
|
31 | + protected function _encodedContentDER(): string |
|
32 | + { |
|
33 | + return self::_encodeSubIDs(...$this->_subids); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * |
|
38 | - * {@inheritdoc} |
|
39 | - * @return self |
|
40 | - */ |
|
41 | - protected static function _decodeFromDER(Identifier $identifier, |
|
42 | - string $data, int &$offset): ElementBase |
|
43 | - { |
|
44 | - $idx = $offset; |
|
45 | - $len = Length::expectFromDER($data, $idx)->intLength(); |
|
46 | - $subids = self::_decodeSubIDs(substr($data, $idx, $len)); |
|
47 | - $offset = $idx + $len; |
|
48 | - return new self(self::_implodeSubIDs(...$subids)); |
|
49 | - } |
|
36 | + /** |
|
37 | + * |
|
38 | + * {@inheritdoc} |
|
39 | + * @return self |
|
40 | + */ |
|
41 | + protected static function _decodeFromDER(Identifier $identifier, |
|
42 | + string $data, int &$offset): ElementBase |
|
43 | + { |
|
44 | + $idx = $offset; |
|
45 | + $len = Length::expectFromDER($data, $idx)->intLength(); |
|
46 | + $subids = self::_decodeSubIDs(substr($data, $idx, $len)); |
|
47 | + $offset = $idx + $len; |
|
48 | + return new self(self::_implodeSubIDs(...$subids)); |
|
49 | + } |
|
50 | 50 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace ASN1\Type\Primitive; |
6 | 6 |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace ASN1\Type\Primitive; |
6 | 6 |
@@ -16,113 +16,113 @@ |
||
16 | 16 | */ |
17 | 17 | class GeneralizedTime extends TimeType |
18 | 18 | { |
19 | - use UniversalClass; |
|
20 | - use PrimitiveType; |
|
19 | + use UniversalClass; |
|
20 | + use PrimitiveType; |
|
21 | 21 | |
22 | - /** |
|
23 | - * Regular expression to parse date. |
|
24 | - * |
|
25 | - * DER restricts format to UTC timezone (Z suffix). |
|
26 | - * |
|
27 | - * @var string |
|
28 | - */ |
|
29 | - const REGEX = /* @formatter:off */ '#^' . |
|
30 | - '(\d\d\d\d)' . /* YYYY */ |
|
31 | - '(\d\d)' . /* MM */ |
|
32 | - '(\d\d)' . /* DD */ |
|
33 | - '(\d\d)' . /* hh */ |
|
34 | - '(\d\d)' . /* mm */ |
|
35 | - '(\d\d)' . /* ss */ |
|
36 | - '(?:\.(\d+))?' . /* frac */ |
|
37 | - 'Z' . /* TZ */ |
|
38 | - '$#' /* @formatter:on */; |
|
22 | + /** |
|
23 | + * Regular expression to parse date. |
|
24 | + * |
|
25 | + * DER restricts format to UTC timezone (Z suffix). |
|
26 | + * |
|
27 | + * @var string |
|
28 | + */ |
|
29 | + const REGEX = /* @formatter:off */ '#^' . |
|
30 | + '(\d\d\d\d)' . /* YYYY */ |
|
31 | + '(\d\d)' . /* MM */ |
|
32 | + '(\d\d)' . /* DD */ |
|
33 | + '(\d\d)' . /* hh */ |
|
34 | + '(\d\d)' . /* mm */ |
|
35 | + '(\d\d)' . /* ss */ |
|
36 | + '(?:\.(\d+))?' . /* frac */ |
|
37 | + 'Z' . /* TZ */ |
|
38 | + '$#' /* @formatter:on */; |
|
39 | 39 | |
40 | - /** |
|
41 | - * Cached formatted date. |
|
42 | - * |
|
43 | - * @var string|null |
|
44 | - */ |
|
45 | - private $_formatted; |
|
40 | + /** |
|
41 | + * Cached formatted date. |
|
42 | + * |
|
43 | + * @var string|null |
|
44 | + */ |
|
45 | + private $_formatted; |
|
46 | 46 | |
47 | - /** |
|
48 | - * Constructor. |
|
49 | - * |
|
50 | - * @param \DateTimeImmutable $dt |
|
51 | - */ |
|
52 | - public function __construct(\DateTimeImmutable $dt) |
|
53 | - { |
|
54 | - $this->_typeTag = self::TYPE_GENERALIZED_TIME; |
|
55 | - parent::__construct($dt); |
|
56 | - } |
|
47 | + /** |
|
48 | + * Constructor. |
|
49 | + * |
|
50 | + * @param \DateTimeImmutable $dt |
|
51 | + */ |
|
52 | + public function __construct(\DateTimeImmutable $dt) |
|
53 | + { |
|
54 | + $this->_typeTag = self::TYPE_GENERALIZED_TIME; |
|
55 | + parent::__construct($dt); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * Clear cached variables on clone. |
|
60 | - */ |
|
61 | - public function __clone() |
|
62 | - { |
|
63 | - $this->_formatted = null; |
|
64 | - } |
|
58 | + /** |
|
59 | + * Clear cached variables on clone. |
|
60 | + */ |
|
61 | + public function __clone() |
|
62 | + { |
|
63 | + $this->_formatted = null; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * |
|
68 | - * {@inheritdoc} |
|
69 | - */ |
|
70 | - protected function _encodedContentDER(): string |
|
71 | - { |
|
72 | - if (!isset($this->_formatted)) { |
|
73 | - $dt = $this->_dateTime->setTimezone( |
|
74 | - self::_createTimeZone(self::TZ_UTC)); |
|
75 | - $this->_formatted = $dt->format("YmdHis"); |
|
76 | - // if fractions were used |
|
77 | - $frac = $dt->format("u"); |
|
78 | - if ($frac != 0) { |
|
79 | - $frac = rtrim($frac, "0"); |
|
80 | - $this->_formatted .= ".$frac"; |
|
81 | - } |
|
82 | - // timezone |
|
83 | - $this->_formatted .= "Z"; |
|
84 | - } |
|
85 | - return $this->_formatted; |
|
86 | - } |
|
66 | + /** |
|
67 | + * |
|
68 | + * {@inheritdoc} |
|
69 | + */ |
|
70 | + protected function _encodedContentDER(): string |
|
71 | + { |
|
72 | + if (!isset($this->_formatted)) { |
|
73 | + $dt = $this->_dateTime->setTimezone( |
|
74 | + self::_createTimeZone(self::TZ_UTC)); |
|
75 | + $this->_formatted = $dt->format("YmdHis"); |
|
76 | + // if fractions were used |
|
77 | + $frac = $dt->format("u"); |
|
78 | + if ($frac != 0) { |
|
79 | + $frac = rtrim($frac, "0"); |
|
80 | + $this->_formatted .= ".$frac"; |
|
81 | + } |
|
82 | + // timezone |
|
83 | + $this->_formatted .= "Z"; |
|
84 | + } |
|
85 | + return $this->_formatted; |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * |
|
90 | - * {@inheritdoc} |
|
91 | - * @return self |
|
92 | - */ |
|
93 | - protected static function _decodeFromDER(Identifier $identifier, |
|
94 | - string $data, int &$offset): ElementBase |
|
95 | - { |
|
96 | - $idx = $offset; |
|
97 | - $length = Length::expectFromDER($data, $idx)->intLength(); |
|
98 | - $str = substr($data, $idx, $length); |
|
99 | - $idx += $length; |
|
100 | - /** @var $match string[] */ |
|
101 | - if (!preg_match(self::REGEX, $str, $match)) { |
|
102 | - throw new DecodeException("Invalid GeneralizedTime format."); |
|
103 | - } |
|
104 | - list(, $year, $month, $day, $hour, $minute, $second) = $match; |
|
105 | - if (isset($match[7])) { |
|
106 | - $frac = $match[7]; |
|
107 | - // DER restricts trailing zeroes in fractional seconds component |
|
108 | - if ('0' === $frac[strlen($frac) - 1]) { |
|
109 | - throw new DecodeException( |
|
110 | - "Fractional seconds must omit trailing zeroes."); |
|
111 | - } |
|
112 | - $frac = (int) $frac; |
|
113 | - } else { |
|
114 | - $frac = 0; |
|
115 | - } |
|
116 | - $time = $year . $month . $day . $hour . $minute . $second . "." . $frac . |
|
117 | - self::TZ_UTC; |
|
118 | - $dt = \DateTimeImmutable::createFromFormat("!YmdHis.uT", $time, |
|
119 | - self::_createTimeZone(self::TZ_UTC)); |
|
120 | - if (!$dt) { |
|
121 | - throw new DecodeException( |
|
122 | - "Failed to decode GeneralizedTime: " . |
|
123 | - self::_getLastDateTimeImmutableErrorsStr()); |
|
124 | - } |
|
125 | - $offset = $idx; |
|
126 | - return new self($dt); |
|
127 | - } |
|
88 | + /** |
|
89 | + * |
|
90 | + * {@inheritdoc} |
|
91 | + * @return self |
|
92 | + */ |
|
93 | + protected static function _decodeFromDER(Identifier $identifier, |
|
94 | + string $data, int &$offset): ElementBase |
|
95 | + { |
|
96 | + $idx = $offset; |
|
97 | + $length = Length::expectFromDER($data, $idx)->intLength(); |
|
98 | + $str = substr($data, $idx, $length); |
|
99 | + $idx += $length; |
|
100 | + /** @var $match string[] */ |
|
101 | + if (!preg_match(self::REGEX, $str, $match)) { |
|
102 | + throw new DecodeException("Invalid GeneralizedTime format."); |
|
103 | + } |
|
104 | + list(, $year, $month, $day, $hour, $minute, $second) = $match; |
|
105 | + if (isset($match[7])) { |
|
106 | + $frac = $match[7]; |
|
107 | + // DER restricts trailing zeroes in fractional seconds component |
|
108 | + if ('0' === $frac[strlen($frac) - 1]) { |
|
109 | + throw new DecodeException( |
|
110 | + "Fractional seconds must omit trailing zeroes."); |
|
111 | + } |
|
112 | + $frac = (int) $frac; |
|
113 | + } else { |
|
114 | + $frac = 0; |
|
115 | + } |
|
116 | + $time = $year . $month . $day . $hour . $minute . $second . "." . $frac . |
|
117 | + self::TZ_UTC; |
|
118 | + $dt = \DateTimeImmutable::createFromFormat("!YmdHis.uT", $time, |
|
119 | + self::_createTimeZone(self::TZ_UTC)); |
|
120 | + if (!$dt) { |
|
121 | + throw new DecodeException( |
|
122 | + "Failed to decode GeneralizedTime: " . |
|
123 | + self::_getLastDateTimeImmutableErrorsStr()); |
|
124 | + } |
|
125 | + $offset = $idx; |
|
126 | + return new self($dt); |
|
127 | + } |
|
128 | 128 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace ASN1\Type\Tagged; |
6 | 6 |
@@ -19,107 +19,107 @@ |
||
19 | 19 | * May be encoded back to complete DER encoding. |
20 | 20 | */ |
21 | 21 | class DERTaggedType extends TaggedType implements |
22 | - ExplicitTagging, |
|
23 | - ImplicitTagging |
|
22 | + ExplicitTagging, |
|
23 | + ImplicitTagging |
|
24 | 24 | { |
25 | - /** |
|
26 | - * Identifier. |
|
27 | - * |
|
28 | - * @var Identifier |
|
29 | - */ |
|
30 | - private $_identifier; |
|
25 | + /** |
|
26 | + * Identifier. |
|
27 | + * |
|
28 | + * @var Identifier |
|
29 | + */ |
|
30 | + private $_identifier; |
|
31 | 31 | |
32 | - /** |
|
33 | - * DER data. |
|
34 | - * |
|
35 | - * @var string |
|
36 | - */ |
|
37 | - private $_data; |
|
32 | + /** |
|
33 | + * DER data. |
|
34 | + * |
|
35 | + * @var string |
|
36 | + */ |
|
37 | + private $_data; |
|
38 | 38 | |
39 | - /** |
|
40 | - * Offset to data. |
|
41 | - * |
|
42 | - * @var int |
|
43 | - */ |
|
44 | - private $_offset; |
|
39 | + /** |
|
40 | + * Offset to data. |
|
41 | + * |
|
42 | + * @var int |
|
43 | + */ |
|
44 | + private $_offset; |
|
45 | 45 | |
46 | - /** |
|
47 | - * Constructor. |
|
48 | - * |
|
49 | - * @param Identifier $identifier |
|
50 | - * @param string $data |
|
51 | - * @param int $offset Offset to next byte after identifier |
|
52 | - */ |
|
53 | - public function __construct(Identifier $identifier, string $data, |
|
54 | - int $offset) |
|
55 | - { |
|
56 | - $this->_identifier = $identifier; |
|
57 | - $this->_data = $data; |
|
58 | - $this->_offset = $offset; |
|
59 | - $this->_typeTag = $identifier->intTag(); |
|
60 | - } |
|
46 | + /** |
|
47 | + * Constructor. |
|
48 | + * |
|
49 | + * @param Identifier $identifier |
|
50 | + * @param string $data |
|
51 | + * @param int $offset Offset to next byte after identifier |
|
52 | + */ |
|
53 | + public function __construct(Identifier $identifier, string $data, |
|
54 | + 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 | - /** @var \ASN1\Feature\ElementBase $element */ |
|
106 | - $element = $cls::_decodeFromDER($identifier, $this->_data, $idx); |
|
107 | - return $element->asUnspecified(); |
|
108 | - } |
|
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 | + /** @var \ASN1\Feature\ElementBase $element */ |
|
106 | + $element = $cls::_decodeFromDER($identifier, $this->_data, $idx); |
|
107 | + return $element->asUnspecified(); |
|
108 | + } |
|
109 | 109 | |
110 | - /** |
|
111 | - * |
|
112 | - * @see \ASN1\Type\Tagged\ExplicitTagging::explicit() |
|
113 | - * @return UnspecifiedType |
|
114 | - */ |
|
115 | - public function explicit($expectedTag = null): UnspecifiedType |
|
116 | - { |
|
117 | - $idx = $this->_offset; |
|
118 | - Length::expectFromDER($this->_data, $idx); |
|
119 | - $element = Element::fromDER($this->_data, $idx); |
|
120 | - if (isset($expectedTag)) { |
|
121 | - $element->expectType($expectedTag); |
|
122 | - } |
|
123 | - return $element->asUnspecified(); |
|
124 | - } |
|
110 | + /** |
|
111 | + * |
|
112 | + * @see \ASN1\Type\Tagged\ExplicitTagging::explicit() |
|
113 | + * @return UnspecifiedType |
|
114 | + */ |
|
115 | + public function explicit($expectedTag = null): UnspecifiedType |
|
116 | + { |
|
117 | + $idx = $this->_offset; |
|
118 | + Length::expectFromDER($this->_data, $idx); |
|
119 | + $element = Element::fromDER($this->_data, $idx); |
|
120 | + if (isset($expectedTag)) { |
|
121 | + $element->expectType($expectedTag); |
|
122 | + } |
|
123 | + return $element->asUnspecified(); |
|
124 | + } |
|
125 | 125 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace ASN1\Type\Tagged; |
6 | 6 |
@@ -12,17 +12,17 @@ |
||
12 | 12 | */ |
13 | 13 | class PrivateType extends DERTaggedType |
14 | 14 | { |
15 | - /** |
|
16 | - * |
|
17 | - * {@inheritdoc} |
|
18 | - */ |
|
19 | - protected static function _decodeFromDER(Identifier $identifier, |
|
20 | - string $data, int &$offset): ElementBase |
|
21 | - { |
|
22 | - $idx = $offset; |
|
23 | - $type = new self($identifier, $data, $idx); |
|
24 | - $length = Length::expectFromDER($data, $idx)->intLength(); |
|
25 | - $offset = $idx + $length; |
|
26 | - return $type; |
|
27 | - } |
|
15 | + /** |
|
16 | + * |
|
17 | + * {@inheritdoc} |
|
18 | + */ |
|
19 | + protected static function _decodeFromDER(Identifier $identifier, |
|
20 | + string $data, int &$offset): ElementBase |
|
21 | + { |
|
22 | + $idx = $offset; |
|
23 | + $type = new self($identifier, $data, $idx); |
|
24 | + $length = Length::expectFromDER($data, $idx)->intLength(); |
|
25 | + $offset = $idx + $length; |
|
26 | + return $type; |
|
27 | + } |
|
28 | 28 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace ASN1\Type\Tagged; |
6 | 6 |
@@ -12,17 +12,17 @@ |
||
12 | 12 | */ |
13 | 13 | class ApplicationType extends DERTaggedType |
14 | 14 | { |
15 | - /** |
|
16 | - * |
|
17 | - * {@inheritdoc} |
|
18 | - */ |
|
19 | - protected static function _decodeFromDER(Identifier $identifier, |
|
20 | - string $data, int &$offset): ElementBase |
|
21 | - { |
|
22 | - $idx = $offset; |
|
23 | - $type = new self($identifier, $data, $idx); |
|
24 | - $length = Length::expectFromDER($data, $idx)->intLength(); |
|
25 | - $offset = $idx + $length; |
|
26 | - return $type; |
|
27 | - } |
|
15 | + /** |
|
16 | + * |
|
17 | + * {@inheritdoc} |
|
18 | + */ |
|
19 | + protected static function _decodeFromDER(Identifier $identifier, |
|
20 | + string $data, int &$offset): ElementBase |
|
21 | + { |
|
22 | + $idx = $offset; |
|
23 | + $type = new self($identifier, $data, $idx); |
|
24 | + $length = Length::expectFromDER($data, $idx)->intLength(); |
|
25 | + $offset = $idx + $length; |
|
26 | + return $type; |
|
27 | + } |
|
28 | 28 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace ASN1\Type; |
6 | 6 |
@@ -13,41 +13,41 @@ |
||
13 | 13 | */ |
14 | 14 | abstract class PrimitiveString extends StringType |
15 | 15 | { |
16 | - use PrimitiveType; |
|
16 | + use PrimitiveType; |
|
17 | 17 | |
18 | - /** |
|
19 | - * |
|
20 | - * @see \ASN1\Element::_encodedContentDER() |
|
21 | - * @return string |
|
22 | - */ |
|
23 | - protected function _encodedContentDER(): string |
|
24 | - { |
|
25 | - return $this->_string; |
|
26 | - } |
|
18 | + /** |
|
19 | + * |
|
20 | + * @see \ASN1\Element::_encodedContentDER() |
|
21 | + * @return string |
|
22 | + */ |
|
23 | + protected function _encodedContentDER(): string |
|
24 | + { |
|
25 | + return $this->_string; |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * |
|
30 | - * {@inheritdoc} |
|
31 | - * @see \ASN1\Element::_decodeFromDER() |
|
32 | - * @return self |
|
33 | - */ |
|
34 | - protected static function _decodeFromDER(Identifier $identifier, |
|
35 | - string $data, int &$offset): ElementBase |
|
36 | - { |
|
37 | - $idx = $offset; |
|
38 | - if (!$identifier->isPrimitive()) { |
|
39 | - throw new DecodeException("DER encoded string must be primitive."); |
|
40 | - } |
|
41 | - $length = Length::expectFromDER($data, $idx)->intLength(); |
|
42 | - $str = $length ? substr($data, $idx, $length) : ""; |
|
43 | - // substr should never return false, since length is |
|
44 | - // checked by Length::expectFromDER. |
|
45 | - assert(is_string($str), new DecodeException("substr")); |
|
46 | - $offset = $idx + $length; |
|
47 | - try { |
|
48 | - return new static($str); |
|
49 | - } catch (\InvalidArgumentException $e) { |
|
50 | - throw new DecodeException($e->getMessage(), 0, $e); |
|
51 | - } |
|
52 | - } |
|
28 | + /** |
|
29 | + * |
|
30 | + * {@inheritdoc} |
|
31 | + * @see \ASN1\Element::_decodeFromDER() |
|
32 | + * @return self |
|
33 | + */ |
|
34 | + protected static function _decodeFromDER(Identifier $identifier, |
|
35 | + string $data, int &$offset): ElementBase |
|
36 | + { |
|
37 | + $idx = $offset; |
|
38 | + if (!$identifier->isPrimitive()) { |
|
39 | + throw new DecodeException("DER encoded string must be primitive."); |
|
40 | + } |
|
41 | + $length = Length::expectFromDER($data, $idx)->intLength(); |
|
42 | + $str = $length ? substr($data, $idx, $length) : ""; |
|
43 | + // substr should never return false, since length is |
|
44 | + // checked by Length::expectFromDER. |
|
45 | + assert(is_string($str), new DecodeException("substr")); |
|
46 | + $offset = $idx + $length; |
|
47 | + try { |
|
48 | + return new static($str); |
|
49 | + } catch (\InvalidArgumentException $e) { |
|
50 | + throw new DecodeException($e->getMessage(), 0, $e); |
|
51 | + } |
|
52 | + } |
|
53 | 53 | } |