@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace Sop\ASN1\Type; |
6 | 6 | |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | public function __construct(ElementBase ...$elements) |
47 | 47 | { |
48 | 48 | $this->_elements = array_map( |
49 | - function (ElementBase $el) { |
|
49 | + function(ElementBase $el) { |
|
50 | 50 | return $el->asElement(); |
51 | 51 | }, $elements); |
52 | 52 | } |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | { |
206 | 206 | if (!isset($this->_unspecifiedTypes)) { |
207 | 207 | $this->_unspecifiedTypes = array_map( |
208 | - function (Element $el) { |
|
208 | + function(Element $el) { |
|
209 | 209 | return new UnspecifiedType($el); |
210 | 210 | }, $this->_elements); |
211 | 211 | } |
@@ -15,402 +15,402 @@ |
||
15 | 15 | */ |
16 | 16 | abstract class Structure extends Element implements \Countable, \IteratorAggregate |
17 | 17 | { |
18 | - use UniversalClass; |
|
18 | + use UniversalClass; |
|
19 | 19 | |
20 | - /** |
|
21 | - * Array of elements in the structure. |
|
22 | - * |
|
23 | - * @var Element[] |
|
24 | - */ |
|
25 | - protected $_elements; |
|
20 | + /** |
|
21 | + * Array of elements in the structure. |
|
22 | + * |
|
23 | + * @var Element[] |
|
24 | + */ |
|
25 | + protected $_elements; |
|
26 | 26 | |
27 | - /** |
|
28 | - * Lookup table for the tagged elements. |
|
29 | - * |
|
30 | - * @var null|TaggedType[] |
|
31 | - */ |
|
32 | - private $_taggedMap; |
|
27 | + /** |
|
28 | + * Lookup table for the tagged elements. |
|
29 | + * |
|
30 | + * @var null|TaggedType[] |
|
31 | + */ |
|
32 | + private $_taggedMap; |
|
33 | 33 | |
34 | - /** |
|
35 | - * Cache variable of elements wrapped into UnspecifiedType objects. |
|
36 | - * |
|
37 | - * @var null|UnspecifiedType[] |
|
38 | - */ |
|
39 | - private $_unspecifiedTypes; |
|
34 | + /** |
|
35 | + * Cache variable of elements wrapped into UnspecifiedType objects. |
|
36 | + * |
|
37 | + * @var null|UnspecifiedType[] |
|
38 | + */ |
|
39 | + private $_unspecifiedTypes; |
|
40 | 40 | |
41 | - /** |
|
42 | - * Constructor. |
|
43 | - * |
|
44 | - * @param ElementBase ...$elements Any number of elements |
|
45 | - */ |
|
46 | - public function __construct(ElementBase ...$elements) |
|
47 | - { |
|
48 | - $this->_elements = array_map( |
|
49 | - function (ElementBase $el) { |
|
50 | - return $el->asElement(); |
|
51 | - }, $elements); |
|
52 | - } |
|
41 | + /** |
|
42 | + * Constructor. |
|
43 | + * |
|
44 | + * @param ElementBase ...$elements Any number of elements |
|
45 | + */ |
|
46 | + public function __construct(ElementBase ...$elements) |
|
47 | + { |
|
48 | + $this->_elements = array_map( |
|
49 | + function (ElementBase $el) { |
|
50 | + return $el->asElement(); |
|
51 | + }, $elements); |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Clone magic method. |
|
56 | - */ |
|
57 | - public function __clone() |
|
58 | - { |
|
59 | - // clear cache-variables |
|
60 | - $this->_taggedMap = null; |
|
61 | - $this->_unspecifiedTypes = null; |
|
62 | - } |
|
54 | + /** |
|
55 | + * Clone magic method. |
|
56 | + */ |
|
57 | + public function __clone() |
|
58 | + { |
|
59 | + // clear cache-variables |
|
60 | + $this->_taggedMap = null; |
|
61 | + $this->_unspecifiedTypes = null; |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * {@inheritdoc} |
|
66 | - */ |
|
67 | - public function isConstructed(): bool |
|
68 | - { |
|
69 | - return true; |
|
70 | - } |
|
64 | + /** |
|
65 | + * {@inheritdoc} |
|
66 | + */ |
|
67 | + public function isConstructed(): bool |
|
68 | + { |
|
69 | + return true; |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * Explode DER structure to DER encoded components that it contains. |
|
74 | - * |
|
75 | - * @param string $data |
|
76 | - * |
|
77 | - * @throws DecodeException |
|
78 | - * |
|
79 | - * @return string[] |
|
80 | - */ |
|
81 | - public static function explodeDER(string $data): array |
|
82 | - { |
|
83 | - $offset = 0; |
|
84 | - $identifier = Identifier::fromDER($data, $offset); |
|
85 | - if (!$identifier->isConstructed()) { |
|
86 | - throw new DecodeException('Element is not constructed.'); |
|
87 | - } |
|
88 | - $length = Length::expectFromDER($data, $offset); |
|
89 | - if ($length->isIndefinite()) { |
|
90 | - throw new DecodeException( |
|
91 | - 'Explode not implemented for indefinite length encoding.'); |
|
92 | - } |
|
93 | - $end = $offset + $length->intLength(); |
|
94 | - $parts = []; |
|
95 | - while ($offset < $end) { |
|
96 | - // start of the element |
|
97 | - $idx = $offset; |
|
98 | - // skip identifier |
|
99 | - Identifier::fromDER($data, $offset); |
|
100 | - // decode element length |
|
101 | - $length = Length::expectFromDER($data, $offset)->intLength(); |
|
102 | - // extract der encoding of the element |
|
103 | - $parts[] = substr($data, $idx, $offset - $idx + $length); |
|
104 | - // update offset over content |
|
105 | - $offset += $length; |
|
106 | - } |
|
107 | - return $parts; |
|
108 | - } |
|
72 | + /** |
|
73 | + * Explode DER structure to DER encoded components that it contains. |
|
74 | + * |
|
75 | + * @param string $data |
|
76 | + * |
|
77 | + * @throws DecodeException |
|
78 | + * |
|
79 | + * @return string[] |
|
80 | + */ |
|
81 | + public static function explodeDER(string $data): array |
|
82 | + { |
|
83 | + $offset = 0; |
|
84 | + $identifier = Identifier::fromDER($data, $offset); |
|
85 | + if (!$identifier->isConstructed()) { |
|
86 | + throw new DecodeException('Element is not constructed.'); |
|
87 | + } |
|
88 | + $length = Length::expectFromDER($data, $offset); |
|
89 | + if ($length->isIndefinite()) { |
|
90 | + throw new DecodeException( |
|
91 | + 'Explode not implemented for indefinite length encoding.'); |
|
92 | + } |
|
93 | + $end = $offset + $length->intLength(); |
|
94 | + $parts = []; |
|
95 | + while ($offset < $end) { |
|
96 | + // start of the element |
|
97 | + $idx = $offset; |
|
98 | + // skip identifier |
|
99 | + Identifier::fromDER($data, $offset); |
|
100 | + // decode element length |
|
101 | + $length = Length::expectFromDER($data, $offset)->intLength(); |
|
102 | + // extract der encoding of the element |
|
103 | + $parts[] = substr($data, $idx, $offset - $idx + $length); |
|
104 | + // update offset over content |
|
105 | + $offset += $length; |
|
106 | + } |
|
107 | + return $parts; |
|
108 | + } |
|
109 | 109 | |
110 | - /** |
|
111 | - * Get self with an element at the given index replaced by another. |
|
112 | - * |
|
113 | - * @param int $idx Element index |
|
114 | - * @param Element $el New element to insert into the structure |
|
115 | - * |
|
116 | - * @throws \OutOfBoundsException |
|
117 | - * |
|
118 | - * @return self |
|
119 | - */ |
|
120 | - public function withReplaced(int $idx, Element $el): self |
|
121 | - { |
|
122 | - if (!isset($this->_elements[$idx])) { |
|
123 | - throw new \OutOfBoundsException( |
|
124 | - "Structure doesn't have element at index {$idx}."); |
|
125 | - } |
|
126 | - $obj = clone $this; |
|
127 | - $obj->_elements[$idx] = $el; |
|
128 | - return $obj; |
|
129 | - } |
|
110 | + /** |
|
111 | + * Get self with an element at the given index replaced by another. |
|
112 | + * |
|
113 | + * @param int $idx Element index |
|
114 | + * @param Element $el New element to insert into the structure |
|
115 | + * |
|
116 | + * @throws \OutOfBoundsException |
|
117 | + * |
|
118 | + * @return self |
|
119 | + */ |
|
120 | + public function withReplaced(int $idx, Element $el): self |
|
121 | + { |
|
122 | + if (!isset($this->_elements[$idx])) { |
|
123 | + throw new \OutOfBoundsException( |
|
124 | + "Structure doesn't have element at index {$idx}."); |
|
125 | + } |
|
126 | + $obj = clone $this; |
|
127 | + $obj->_elements[$idx] = $el; |
|
128 | + return $obj; |
|
129 | + } |
|
130 | 130 | |
131 | - /** |
|
132 | - * Get self with an element inserted before the given index. |
|
133 | - * |
|
134 | - * @param int $idx Element index |
|
135 | - * @param Element $el New element to insert into the structure |
|
136 | - * |
|
137 | - * @throws \OutOfBoundsException |
|
138 | - * |
|
139 | - * @return self |
|
140 | - */ |
|
141 | - public function withInserted(int $idx, Element $el): self |
|
142 | - { |
|
143 | - if (count($this->_elements) < $idx || $idx < 0) { |
|
144 | - throw new \OutOfBoundsException("Index {$idx} is out of bounds."); |
|
145 | - } |
|
146 | - $obj = clone $this; |
|
147 | - array_splice($obj->_elements, $idx, 0, [$el]); |
|
148 | - return $obj; |
|
149 | - } |
|
131 | + /** |
|
132 | + * Get self with an element inserted before the given index. |
|
133 | + * |
|
134 | + * @param int $idx Element index |
|
135 | + * @param Element $el New element to insert into the structure |
|
136 | + * |
|
137 | + * @throws \OutOfBoundsException |
|
138 | + * |
|
139 | + * @return self |
|
140 | + */ |
|
141 | + public function withInserted(int $idx, Element $el): self |
|
142 | + { |
|
143 | + if (count($this->_elements) < $idx || $idx < 0) { |
|
144 | + throw new \OutOfBoundsException("Index {$idx} is out of bounds."); |
|
145 | + } |
|
146 | + $obj = clone $this; |
|
147 | + array_splice($obj->_elements, $idx, 0, [$el]); |
|
148 | + return $obj; |
|
149 | + } |
|
150 | 150 | |
151 | - /** |
|
152 | - * Get self with an element appended to the end. |
|
153 | - * |
|
154 | - * @param Element $el Element to insert into the structure |
|
155 | - * |
|
156 | - * @return self |
|
157 | - */ |
|
158 | - public function withAppended(Element $el): self |
|
159 | - { |
|
160 | - $obj = clone $this; |
|
161 | - array_push($obj->_elements, $el); |
|
162 | - return $obj; |
|
163 | - } |
|
151 | + /** |
|
152 | + * Get self with an element appended to the end. |
|
153 | + * |
|
154 | + * @param Element $el Element to insert into the structure |
|
155 | + * |
|
156 | + * @return self |
|
157 | + */ |
|
158 | + public function withAppended(Element $el): self |
|
159 | + { |
|
160 | + $obj = clone $this; |
|
161 | + array_push($obj->_elements, $el); |
|
162 | + return $obj; |
|
163 | + } |
|
164 | 164 | |
165 | - /** |
|
166 | - * Get self with an element prepended in the beginning. |
|
167 | - * |
|
168 | - * @param Element $el Element to insert into the structure |
|
169 | - * |
|
170 | - * @return self |
|
171 | - */ |
|
172 | - public function withPrepended(Element $el): self |
|
173 | - { |
|
174 | - $obj = clone $this; |
|
175 | - array_unshift($obj->_elements, $el); |
|
176 | - return $obj; |
|
177 | - } |
|
165 | + /** |
|
166 | + * Get self with an element prepended in the beginning. |
|
167 | + * |
|
168 | + * @param Element $el Element to insert into the structure |
|
169 | + * |
|
170 | + * @return self |
|
171 | + */ |
|
172 | + public function withPrepended(Element $el): self |
|
173 | + { |
|
174 | + $obj = clone $this; |
|
175 | + array_unshift($obj->_elements, $el); |
|
176 | + return $obj; |
|
177 | + } |
|
178 | 178 | |
179 | - /** |
|
180 | - * Get self with an element at the given index removed. |
|
181 | - * |
|
182 | - * @param int $idx Element index |
|
183 | - * |
|
184 | - * @throws \OutOfBoundsException |
|
185 | - * |
|
186 | - * @return self |
|
187 | - */ |
|
188 | - public function withoutElement(int $idx): self |
|
189 | - { |
|
190 | - if (!isset($this->_elements[$idx])) { |
|
191 | - throw new \OutOfBoundsException( |
|
192 | - "Structure doesn't have element at index {$idx}."); |
|
193 | - } |
|
194 | - $obj = clone $this; |
|
195 | - array_splice($obj->_elements, $idx, 1); |
|
196 | - return $obj; |
|
197 | - } |
|
179 | + /** |
|
180 | + * Get self with an element at the given index removed. |
|
181 | + * |
|
182 | + * @param int $idx Element index |
|
183 | + * |
|
184 | + * @throws \OutOfBoundsException |
|
185 | + * |
|
186 | + * @return self |
|
187 | + */ |
|
188 | + public function withoutElement(int $idx): self |
|
189 | + { |
|
190 | + if (!isset($this->_elements[$idx])) { |
|
191 | + throw new \OutOfBoundsException( |
|
192 | + "Structure doesn't have element at index {$idx}."); |
|
193 | + } |
|
194 | + $obj = clone $this; |
|
195 | + array_splice($obj->_elements, $idx, 1); |
|
196 | + return $obj; |
|
197 | + } |
|
198 | 198 | |
199 | - /** |
|
200 | - * Get elements in the structure. |
|
201 | - * |
|
202 | - * @return UnspecifiedType[] |
|
203 | - */ |
|
204 | - public function elements(): array |
|
205 | - { |
|
206 | - if (!isset($this->_unspecifiedTypes)) { |
|
207 | - $this->_unspecifiedTypes = array_map( |
|
208 | - function (Element $el) { |
|
209 | - return new UnspecifiedType($el); |
|
210 | - }, $this->_elements); |
|
211 | - } |
|
212 | - return $this->_unspecifiedTypes; |
|
213 | - } |
|
199 | + /** |
|
200 | + * Get elements in the structure. |
|
201 | + * |
|
202 | + * @return UnspecifiedType[] |
|
203 | + */ |
|
204 | + public function elements(): array |
|
205 | + { |
|
206 | + if (!isset($this->_unspecifiedTypes)) { |
|
207 | + $this->_unspecifiedTypes = array_map( |
|
208 | + function (Element $el) { |
|
209 | + return new UnspecifiedType($el); |
|
210 | + }, $this->_elements); |
|
211 | + } |
|
212 | + return $this->_unspecifiedTypes; |
|
213 | + } |
|
214 | 214 | |
215 | - /** |
|
216 | - * Check whether the structure has an element at the given index, optionally |
|
217 | - * satisfying given tag expectation. |
|
218 | - * |
|
219 | - * @param int $idx Index 0..n |
|
220 | - * @param null|int $expectedTag Optional type tag expectation |
|
221 | - * |
|
222 | - * @return bool |
|
223 | - */ |
|
224 | - public function has(int $idx, ?int $expectedTag = null): bool |
|
225 | - { |
|
226 | - if (!isset($this->_elements[$idx])) { |
|
227 | - return false; |
|
228 | - } |
|
229 | - if (isset($expectedTag)) { |
|
230 | - if (!$this->_elements[$idx]->isType($expectedTag)) { |
|
231 | - return false; |
|
232 | - } |
|
233 | - } |
|
234 | - return true; |
|
235 | - } |
|
215 | + /** |
|
216 | + * Check whether the structure has an element at the given index, optionally |
|
217 | + * satisfying given tag expectation. |
|
218 | + * |
|
219 | + * @param int $idx Index 0..n |
|
220 | + * @param null|int $expectedTag Optional type tag expectation |
|
221 | + * |
|
222 | + * @return bool |
|
223 | + */ |
|
224 | + public function has(int $idx, ?int $expectedTag = null): bool |
|
225 | + { |
|
226 | + if (!isset($this->_elements[$idx])) { |
|
227 | + return false; |
|
228 | + } |
|
229 | + if (isset($expectedTag)) { |
|
230 | + if (!$this->_elements[$idx]->isType($expectedTag)) { |
|
231 | + return false; |
|
232 | + } |
|
233 | + } |
|
234 | + return true; |
|
235 | + } |
|
236 | 236 | |
237 | - /** |
|
238 | - * Get the element at the given index, optionally checking that the element |
|
239 | - * has a given tag. |
|
240 | - * |
|
241 | - * @param int $idx Index 0..n |
|
242 | - * |
|
243 | - * @throws \OutOfBoundsException If element doesn't exists |
|
244 | - * @throws \UnexpectedValueException If expectation fails |
|
245 | - * |
|
246 | - * @return UnspecifiedType |
|
247 | - */ |
|
248 | - public function at(int $idx): UnspecifiedType |
|
249 | - { |
|
250 | - if (!isset($this->_elements[$idx])) { |
|
251 | - throw new \OutOfBoundsException( |
|
252 | - "Structure doesn't have an element at index {$idx}."); |
|
253 | - } |
|
254 | - return new UnspecifiedType($this->_elements[$idx]); |
|
255 | - } |
|
237 | + /** |
|
238 | + * Get the element at the given index, optionally checking that the element |
|
239 | + * has a given tag. |
|
240 | + * |
|
241 | + * @param int $idx Index 0..n |
|
242 | + * |
|
243 | + * @throws \OutOfBoundsException If element doesn't exists |
|
244 | + * @throws \UnexpectedValueException If expectation fails |
|
245 | + * |
|
246 | + * @return UnspecifiedType |
|
247 | + */ |
|
248 | + public function at(int $idx): UnspecifiedType |
|
249 | + { |
|
250 | + if (!isset($this->_elements[$idx])) { |
|
251 | + throw new \OutOfBoundsException( |
|
252 | + "Structure doesn't have an element at index {$idx}."); |
|
253 | + } |
|
254 | + return new UnspecifiedType($this->_elements[$idx]); |
|
255 | + } |
|
256 | 256 | |
257 | - /** |
|
258 | - * Check whether the structure contains a context specific element with a |
|
259 | - * given tag. |
|
260 | - * |
|
261 | - * @param int $tag Tag number |
|
262 | - * |
|
263 | - * @return bool |
|
264 | - */ |
|
265 | - public function hasTagged(int $tag): bool |
|
266 | - { |
|
267 | - // lazily build lookup map |
|
268 | - if (!isset($this->_taggedMap)) { |
|
269 | - $this->_taggedMap = []; |
|
270 | - foreach ($this->_elements as $element) { |
|
271 | - if ($element->isTagged()) { |
|
272 | - $this->_taggedMap[$element->tag()] = $element; |
|
273 | - } |
|
274 | - } |
|
275 | - } |
|
276 | - return isset($this->_taggedMap[$tag]); |
|
277 | - } |
|
257 | + /** |
|
258 | + * Check whether the structure contains a context specific element with a |
|
259 | + * given tag. |
|
260 | + * |
|
261 | + * @param int $tag Tag number |
|
262 | + * |
|
263 | + * @return bool |
|
264 | + */ |
|
265 | + public function hasTagged(int $tag): bool |
|
266 | + { |
|
267 | + // lazily build lookup map |
|
268 | + if (!isset($this->_taggedMap)) { |
|
269 | + $this->_taggedMap = []; |
|
270 | + foreach ($this->_elements as $element) { |
|
271 | + if ($element->isTagged()) { |
|
272 | + $this->_taggedMap[$element->tag()] = $element; |
|
273 | + } |
|
274 | + } |
|
275 | + } |
|
276 | + return isset($this->_taggedMap[$tag]); |
|
277 | + } |
|
278 | 278 | |
279 | - /** |
|
280 | - * Get a context specific element tagged with a given tag. |
|
281 | - * |
|
282 | - * @param int $tag |
|
283 | - * |
|
284 | - * @throws \LogicException If tag doesn't exists |
|
285 | - * |
|
286 | - * @return TaggedType |
|
287 | - */ |
|
288 | - public function getTagged(int $tag): TaggedType |
|
289 | - { |
|
290 | - if (!$this->hasTagged($tag)) { |
|
291 | - throw new \LogicException("No tagged element for tag {$tag}."); |
|
292 | - } |
|
293 | - return $this->_taggedMap[$tag]; |
|
294 | - } |
|
279 | + /** |
|
280 | + * Get a context specific element tagged with a given tag. |
|
281 | + * |
|
282 | + * @param int $tag |
|
283 | + * |
|
284 | + * @throws \LogicException If tag doesn't exists |
|
285 | + * |
|
286 | + * @return TaggedType |
|
287 | + */ |
|
288 | + public function getTagged(int $tag): TaggedType |
|
289 | + { |
|
290 | + if (!$this->hasTagged($tag)) { |
|
291 | + throw new \LogicException("No tagged element for tag {$tag}."); |
|
292 | + } |
|
293 | + return $this->_taggedMap[$tag]; |
|
294 | + } |
|
295 | 295 | |
296 | - /** |
|
297 | - * @see \Countable::count() |
|
298 | - * |
|
299 | - * @return int |
|
300 | - */ |
|
301 | - public function count(): int |
|
302 | - { |
|
303 | - return count($this->_elements); |
|
304 | - } |
|
296 | + /** |
|
297 | + * @see \Countable::count() |
|
298 | + * |
|
299 | + * @return int |
|
300 | + */ |
|
301 | + public function count(): int |
|
302 | + { |
|
303 | + return count($this->_elements); |
|
304 | + } |
|
305 | 305 | |
306 | - /** |
|
307 | - * Get an iterator for the UnspecifiedElement objects. |
|
308 | - * |
|
309 | - * @see \IteratorAggregate::getIterator() |
|
310 | - * |
|
311 | - * @return \ArrayIterator |
|
312 | - */ |
|
313 | - public function getIterator(): \ArrayIterator |
|
314 | - { |
|
315 | - return new \ArrayIterator($this->elements()); |
|
316 | - } |
|
306 | + /** |
|
307 | + * Get an iterator for the UnspecifiedElement objects. |
|
308 | + * |
|
309 | + * @see \IteratorAggregate::getIterator() |
|
310 | + * |
|
311 | + * @return \ArrayIterator |
|
312 | + */ |
|
313 | + public function getIterator(): \ArrayIterator |
|
314 | + { |
|
315 | + return new \ArrayIterator($this->elements()); |
|
316 | + } |
|
317 | 317 | |
318 | - /** |
|
319 | - * {@inheritdoc} |
|
320 | - */ |
|
321 | - protected function _encodedContentDER(): string |
|
322 | - { |
|
323 | - $data = ''; |
|
324 | - foreach ($this->_elements as $element) { |
|
325 | - $data .= $element->toDER(); |
|
326 | - } |
|
327 | - return $data; |
|
328 | - } |
|
318 | + /** |
|
319 | + * {@inheritdoc} |
|
320 | + */ |
|
321 | + protected function _encodedContentDER(): string |
|
322 | + { |
|
323 | + $data = ''; |
|
324 | + foreach ($this->_elements as $element) { |
|
325 | + $data .= $element->toDER(); |
|
326 | + } |
|
327 | + return $data; |
|
328 | + } |
|
329 | 329 | |
330 | - /** |
|
331 | - * {@inheritdoc} |
|
332 | - * |
|
333 | - * @return self |
|
334 | - */ |
|
335 | - protected static function _decodeFromDER(Identifier $identifier, |
|
336 | - string $data, int &$offset): ElementBase |
|
337 | - { |
|
338 | - if (!$identifier->isConstructed()) { |
|
339 | - throw new DecodeException( |
|
340 | - 'Structured element must have constructed bit set.'); |
|
341 | - } |
|
342 | - $idx = $offset; |
|
343 | - $length = Length::expectFromDER($data, $idx); |
|
344 | - if ($length->isIndefinite()) { |
|
345 | - $type = self::_decodeIndefiniteLength($data, $idx); |
|
346 | - } else { |
|
347 | - $type = self::_decodeDefiniteLength($data, $idx, |
|
348 | - $length->intLength()); |
|
349 | - } |
|
350 | - $offset = $idx; |
|
351 | - return $type; |
|
352 | - } |
|
330 | + /** |
|
331 | + * {@inheritdoc} |
|
332 | + * |
|
333 | + * @return self |
|
334 | + */ |
|
335 | + protected static function _decodeFromDER(Identifier $identifier, |
|
336 | + string $data, int &$offset): ElementBase |
|
337 | + { |
|
338 | + if (!$identifier->isConstructed()) { |
|
339 | + throw new DecodeException( |
|
340 | + 'Structured element must have constructed bit set.'); |
|
341 | + } |
|
342 | + $idx = $offset; |
|
343 | + $length = Length::expectFromDER($data, $idx); |
|
344 | + if ($length->isIndefinite()) { |
|
345 | + $type = self::_decodeIndefiniteLength($data, $idx); |
|
346 | + } else { |
|
347 | + $type = self::_decodeDefiniteLength($data, $idx, |
|
348 | + $length->intLength()); |
|
349 | + } |
|
350 | + $offset = $idx; |
|
351 | + return $type; |
|
352 | + } |
|
353 | 353 | |
354 | - /** |
|
355 | - * Decode elements for a definite length. |
|
356 | - * |
|
357 | - * @param string $data DER data |
|
358 | - * @param int $offset Offset to data |
|
359 | - * @param int $length Number of bytes to decode |
|
360 | - * |
|
361 | - * @throws DecodeException |
|
362 | - * |
|
363 | - * @return ElementBase |
|
364 | - */ |
|
365 | - private static function _decodeDefiniteLength(string $data, int &$offset, |
|
366 | - int $length): ElementBase |
|
367 | - { |
|
368 | - $idx = $offset; |
|
369 | - $end = $idx + $length; |
|
370 | - $elements = []; |
|
371 | - while ($idx < $end) { |
|
372 | - $elements[] = Element::fromDER($data, $idx); |
|
373 | - // check that element didn't overflow length |
|
374 | - if ($idx > $end) { |
|
375 | - throw new DecodeException( |
|
376 | - "Structure's content overflows length."); |
|
377 | - } |
|
378 | - } |
|
379 | - $offset = $idx; |
|
380 | - // return instance by static late binding |
|
381 | - return new static(...$elements); |
|
382 | - } |
|
354 | + /** |
|
355 | + * Decode elements for a definite length. |
|
356 | + * |
|
357 | + * @param string $data DER data |
|
358 | + * @param int $offset Offset to data |
|
359 | + * @param int $length Number of bytes to decode |
|
360 | + * |
|
361 | + * @throws DecodeException |
|
362 | + * |
|
363 | + * @return ElementBase |
|
364 | + */ |
|
365 | + private static function _decodeDefiniteLength(string $data, int &$offset, |
|
366 | + int $length): ElementBase |
|
367 | + { |
|
368 | + $idx = $offset; |
|
369 | + $end = $idx + $length; |
|
370 | + $elements = []; |
|
371 | + while ($idx < $end) { |
|
372 | + $elements[] = Element::fromDER($data, $idx); |
|
373 | + // check that element didn't overflow length |
|
374 | + if ($idx > $end) { |
|
375 | + throw new DecodeException( |
|
376 | + "Structure's content overflows length."); |
|
377 | + } |
|
378 | + } |
|
379 | + $offset = $idx; |
|
380 | + // return instance by static late binding |
|
381 | + return new static(...$elements); |
|
382 | + } |
|
383 | 383 | |
384 | - /** |
|
385 | - * Decode elements for an indefinite length. |
|
386 | - * |
|
387 | - * @param string $data DER data |
|
388 | - * @param int $offset Offset to data |
|
389 | - * |
|
390 | - * @throws DecodeException |
|
391 | - * |
|
392 | - * @return ElementBase |
|
393 | - */ |
|
394 | - private static function _decodeIndefiniteLength( |
|
395 | - string $data, int &$offset): ElementBase |
|
396 | - { |
|
397 | - $idx = $offset; |
|
398 | - $elements = []; |
|
399 | - $end = strlen($data); |
|
400 | - while (true) { |
|
401 | - if ($idx >= $end) { |
|
402 | - throw new DecodeException( |
|
403 | - 'Unexpected end of data while decoding indefinite length structure.'); |
|
404 | - } |
|
405 | - $el = Element::fromDER($data, $idx); |
|
406 | - if ($el->isType(self::TYPE_EOC)) { |
|
407 | - break; |
|
408 | - } |
|
409 | - $elements[] = $el; |
|
410 | - } |
|
411 | - $offset = $idx; |
|
412 | - $type = new static(...$elements); |
|
413 | - $type->_indefiniteLength = true; |
|
414 | - return $type; |
|
415 | - } |
|
384 | + /** |
|
385 | + * Decode elements for an indefinite length. |
|
386 | + * |
|
387 | + * @param string $data DER data |
|
388 | + * @param int $offset Offset to data |
|
389 | + * |
|
390 | + * @throws DecodeException |
|
391 | + * |
|
392 | + * @return ElementBase |
|
393 | + */ |
|
394 | + private static function _decodeIndefiniteLength( |
|
395 | + string $data, int &$offset): ElementBase |
|
396 | + { |
|
397 | + $idx = $offset; |
|
398 | + $elements = []; |
|
399 | + $end = strlen($data); |
|
400 | + while (true) { |
|
401 | + if ($idx >= $end) { |
|
402 | + throw new DecodeException( |
|
403 | + 'Unexpected end of data while decoding indefinite length structure.'); |
|
404 | + } |
|
405 | + $el = Element::fromDER($data, $idx); |
|
406 | + if ($el->isType(self::TYPE_EOC)) { |
|
407 | + break; |
|
408 | + } |
|
409 | + $elements[] = $el; |
|
410 | + } |
|
411 | + $offset = $idx; |
|
412 | + $type = new static(...$elements); |
|
413 | + $type->_indefiniteLength = true; |
|
414 | + return $type; |
|
415 | + } |
|
416 | 416 | } |
@@ -11,93 +11,93 @@ |
||
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 |
|
25 | - */ |
|
26 | - protected $_dateTime; |
|
21 | + /** |
|
22 | + * Date and time. |
|
23 | + * |
|
24 | + * @var \DateTimeImmutable |
|
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 | - * @see http://php.net/manual/en/datetime.formats.php |
|
42 | - * |
|
43 | - * @param string $time Time string |
|
44 | - * @param null|string $tz timezone, if null use default |
|
45 | - * |
|
46 | - * @throws \RuntimeException |
|
47 | - * |
|
48 | - * @return self |
|
49 | - */ |
|
50 | - public static function fromString(string $time, ?string $tz = null): self |
|
51 | - { |
|
52 | - try { |
|
53 | - if (!isset($tz)) { |
|
54 | - $tz = date_default_timezone_get(); |
|
55 | - } |
|
56 | - return new static( |
|
57 | - new \DateTimeImmutable($time, self::_createTimeZone($tz))); |
|
58 | - } catch (\Exception $e) { |
|
59 | - throw new \RuntimeException( |
|
60 | - 'Failed to create DateTime: ' . |
|
61 | - self::_getLastDateTimeImmutableErrorsStr(), 0, $e); |
|
62 | - } |
|
63 | - } |
|
38 | + /** |
|
39 | + * Initialize from datetime string. |
|
40 | + * |
|
41 | + * @see http://php.net/manual/en/datetime.formats.php |
|
42 | + * |
|
43 | + * @param string $time Time string |
|
44 | + * @param null|string $tz timezone, if null use default |
|
45 | + * |
|
46 | + * @throws \RuntimeException |
|
47 | + * |
|
48 | + * @return self |
|
49 | + */ |
|
50 | + public static function fromString(string $time, ?string $tz = null): self |
|
51 | + { |
|
52 | + try { |
|
53 | + if (!isset($tz)) { |
|
54 | + $tz = date_default_timezone_get(); |
|
55 | + } |
|
56 | + return new static( |
|
57 | + new \DateTimeImmutable($time, self::_createTimeZone($tz))); |
|
58 | + } catch (\Exception $e) { |
|
59 | + throw new \RuntimeException( |
|
60 | + 'Failed to create DateTime: ' . |
|
61 | + self::_getLastDateTimeImmutableErrorsStr(), 0, $e); |
|
62 | + } |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * Get the date and time. |
|
67 | - * |
|
68 | - * @return \DateTimeImmutable |
|
69 | - */ |
|
70 | - public function dateTime(): \DateTimeImmutable |
|
71 | - { |
|
72 | - return $this->_dateTime; |
|
73 | - } |
|
65 | + /** |
|
66 | + * Get the date and time. |
|
67 | + * |
|
68 | + * @return \DateTimeImmutable |
|
69 | + */ |
|
70 | + public function dateTime(): \DateTimeImmutable |
|
71 | + { |
|
72 | + return $this->_dateTime; |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Create DateTimeZone object from string. |
|
77 | - * |
|
78 | - * @param string $tz |
|
79 | - * |
|
80 | - * @throws \UnexpectedValueException If timezone is invalid |
|
81 | - * |
|
82 | - * @return \DateTimeZone |
|
83 | - */ |
|
84 | - protected static function _createTimeZone(string $tz): \DateTimeZone |
|
85 | - { |
|
86 | - try { |
|
87 | - return new \DateTimeZone($tz); |
|
88 | - } catch (\Exception $e) { |
|
89 | - throw new \UnexpectedValueException('Invalid timezone.', 0, $e); |
|
90 | - } |
|
91 | - } |
|
75 | + /** |
|
76 | + * Create DateTimeZone object from string. |
|
77 | + * |
|
78 | + * @param string $tz |
|
79 | + * |
|
80 | + * @throws \UnexpectedValueException If timezone is invalid |
|
81 | + * |
|
82 | + * @return \DateTimeZone |
|
83 | + */ |
|
84 | + protected static function _createTimeZone(string $tz): \DateTimeZone |
|
85 | + { |
|
86 | + try { |
|
87 | + return new \DateTimeZone($tz); |
|
88 | + } catch (\Exception $e) { |
|
89 | + throw new \UnexpectedValueException('Invalid timezone.', 0, $e); |
|
90 | + } |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * Get last error caused by DateTimeImmutable. |
|
95 | - * |
|
96 | - * @return string |
|
97 | - */ |
|
98 | - protected static function _getLastDateTimeImmutableErrorsStr(): string |
|
99 | - { |
|
100 | - $errors = \DateTimeImmutable::getLastErrors()['errors']; |
|
101 | - return implode(', ', $errors); |
|
102 | - } |
|
93 | + /** |
|
94 | + * Get last error caused by DateTimeImmutable. |
|
95 | + * |
|
96 | + * @return string |
|
97 | + */ |
|
98 | + protected static function _getLastDateTimeImmutableErrorsStr(): string |
|
99 | + { |
|
100 | + $errors = \DateTimeImmutable::getLastErrors()['errors']; |
|
101 | + return implode(', ', $errors); |
|
102 | + } |
|
103 | 103 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace Sop\ASN1\Type; |
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 Sop\ASN1\Type\Tagged; |
6 | 6 |
@@ -13,15 +13,15 @@ |
||
13 | 13 | */ |
14 | 14 | interface ImplicitTagging extends ElementBase |
15 | 15 | { |
16 | - /** |
|
17 | - * Get implicitly tagged wrapped element. |
|
18 | - * |
|
19 | - * @param int $tag Tag of the element |
|
20 | - * @param int $class Expected type class of the element |
|
21 | - * |
|
22 | - * @throws \UnexpectedValueException If expectation fails |
|
23 | - * |
|
24 | - * @return \Sop\ASN1\Type\UnspecifiedType |
|
25 | - */ |
|
26 | - public function implicit(int $tag, int $class = Identifier::CLASS_UNIVERSAL): UnspecifiedType; |
|
16 | + /** |
|
17 | + * Get implicitly tagged wrapped element. |
|
18 | + * |
|
19 | + * @param int $tag Tag of the element |
|
20 | + * @param int $class Expected type class of the element |
|
21 | + * |
|
22 | + * @throws \UnexpectedValueException If expectation fails |
|
23 | + * |
|
24 | + * @return \Sop\ASN1\Type\UnspecifiedType |
|
25 | + */ |
|
26 | + public function implicit(int $tag, int $class = Identifier::CLASS_UNIVERSAL): UnspecifiedType; |
|
27 | 27 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace Sop\ASN1\Type\Tagged; |
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 Sop\ASN1\Type\Primitive; |
6 | 6 |
@@ -17,276 +17,276 @@ |
||
17 | 17 | */ |
18 | 18 | class Real extends Element |
19 | 19 | { |
20 | - use UniversalClass; |
|
21 | - use PrimitiveType; |
|
20 | + use UniversalClass; |
|
21 | + use PrimitiveType; |
|
22 | 22 | |
23 | - /** |
|
24 | - * Regex pattern to parse NR3 form number conforming to DER. |
|
25 | - * |
|
26 | - * @var string |
|
27 | - */ |
|
28 | - const NR3_REGEX = '/^(-?)(\d+)?\.E([+\-]?\d+)$/'; |
|
23 | + /** |
|
24 | + * Regex pattern to parse NR3 form number conforming to DER. |
|
25 | + * |
|
26 | + * @var string |
|
27 | + */ |
|
28 | + const NR3_REGEX = '/^(-?)(\d+)?\.E([+\-]?\d+)$/'; |
|
29 | 29 | |
30 | - /** |
|
31 | - * Regex pattern to parse PHP exponent number format. |
|
32 | - * |
|
33 | - * @see http://php.net/manual/en/language.types.float.php |
|
34 | - * |
|
35 | - * @var string |
|
36 | - */ |
|
37 | - const PHP_EXPONENT_DNUM = '/^' . |
|
38 | - '([+\-]?' . // sign |
|
39 | - '(?:' . |
|
40 | - '\d+' . // LNUM |
|
41 | - '|' . |
|
42 | - '(?:\d*\.\d+|\d+\.\d*)' . // DNUM |
|
43 | - '))[eE]' . |
|
44 | - '([+\-]?\d+)' . // exponent |
|
45 | - '$/'; |
|
30 | + /** |
|
31 | + * Regex pattern to parse PHP exponent number format. |
|
32 | + * |
|
33 | + * @see http://php.net/manual/en/language.types.float.php |
|
34 | + * |
|
35 | + * @var string |
|
36 | + */ |
|
37 | + const PHP_EXPONENT_DNUM = '/^' . |
|
38 | + '([+\-]?' . // sign |
|
39 | + '(?:' . |
|
40 | + '\d+' . // LNUM |
|
41 | + '|' . |
|
42 | + '(?:\d*\.\d+|\d+\.\d*)' . // DNUM |
|
43 | + '))[eE]' . |
|
44 | + '([+\-]?\d+)' . // exponent |
|
45 | + '$/'; |
|
46 | 46 | |
47 | - /** |
|
48 | - * Number zero represented in NR3 form. |
|
49 | - * |
|
50 | - * @var string |
|
51 | - */ |
|
52 | - const NR3_ZERO = '.E+0'; |
|
47 | + /** |
|
48 | + * Number zero represented in NR3 form. |
|
49 | + * |
|
50 | + * @var string |
|
51 | + */ |
|
52 | + const NR3_ZERO = '.E+0'; |
|
53 | 53 | |
54 | - /** |
|
55 | - * Number in NR3 form. |
|
56 | - * |
|
57 | - * @var string |
|
58 | - */ |
|
59 | - private $_number; |
|
54 | + /** |
|
55 | + * Number in NR3 form. |
|
56 | + * |
|
57 | + * @var string |
|
58 | + */ |
|
59 | + private $_number; |
|
60 | 60 | |
61 | - /** |
|
62 | - * Constructor. |
|
63 | - * |
|
64 | - * @param string $number number in NR3 form |
|
65 | - */ |
|
66 | - public function __construct(string $number) |
|
67 | - { |
|
68 | - $this->_typeTag = self::TYPE_REAL; |
|
69 | - if (!self::_validateNumber($number)) { |
|
70 | - throw new \InvalidArgumentException( |
|
71 | - "'{$number}' is not a valid NR3 form real."); |
|
72 | - } |
|
73 | - $this->_number = $number; |
|
74 | - } |
|
61 | + /** |
|
62 | + * Constructor. |
|
63 | + * |
|
64 | + * @param string $number number in NR3 form |
|
65 | + */ |
|
66 | + public function __construct(string $number) |
|
67 | + { |
|
68 | + $this->_typeTag = self::TYPE_REAL; |
|
69 | + if (!self::_validateNumber($number)) { |
|
70 | + throw new \InvalidArgumentException( |
|
71 | + "'{$number}' is not a valid NR3 form real."); |
|
72 | + } |
|
73 | + $this->_number = $number; |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * Initialize from float. |
|
78 | - * |
|
79 | - * @param float $number |
|
80 | - * |
|
81 | - * @return self |
|
82 | - */ |
|
83 | - public static function fromFloat(float $number): self |
|
84 | - { |
|
85 | - return new self(self::_decimalToNR3(strval($number))); |
|
86 | - } |
|
76 | + /** |
|
77 | + * Initialize from float. |
|
78 | + * |
|
79 | + * @param float $number |
|
80 | + * |
|
81 | + * @return self |
|
82 | + */ |
|
83 | + public static function fromFloat(float $number): self |
|
84 | + { |
|
85 | + return new self(self::_decimalToNR3(strval($number))); |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * Get number as a float. |
|
90 | - * |
|
91 | - * @return float |
|
92 | - */ |
|
93 | - public function float(): float |
|
94 | - { |
|
95 | - return self::_nr3ToDecimal($this->_number); |
|
96 | - } |
|
88 | + /** |
|
89 | + * Get number as a float. |
|
90 | + * |
|
91 | + * @return float |
|
92 | + */ |
|
93 | + public function float(): float |
|
94 | + { |
|
95 | + return self::_nr3ToDecimal($this->_number); |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * {@inheritdoc} |
|
100 | - */ |
|
101 | - protected function _encodedContentDER(): string |
|
102 | - { |
|
103 | - /* if the real value is the value zero, there shall be no contents |
|
98 | + /** |
|
99 | + * {@inheritdoc} |
|
100 | + */ |
|
101 | + protected function _encodedContentDER(): string |
|
102 | + { |
|
103 | + /* if the real value is the value zero, there shall be no contents |
|
104 | 104 | octets in the encoding. (X.690 07-2002, section 8.5.2) */ |
105 | - if (self::NR3_ZERO === $this->_number) { |
|
106 | - return ''; |
|
107 | - } |
|
108 | - // encode in NR3 decimal encoding |
|
109 | - return chr(0x03) . $this->_number; |
|
110 | - } |
|
105 | + if (self::NR3_ZERO === $this->_number) { |
|
106 | + return ''; |
|
107 | + } |
|
108 | + // encode in NR3 decimal encoding |
|
109 | + return chr(0x03) . $this->_number; |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * {@inheritdoc} |
|
114 | - */ |
|
115 | - protected static function _decodeFromDER(Identifier $identifier, |
|
116 | - string $data, int &$offset): ElementBase |
|
117 | - { |
|
118 | - $idx = $offset; |
|
119 | - $length = Length::expectFromDER($data, $idx)->intLength(); |
|
120 | - // if length is zero, value is zero (spec 8.5.2) |
|
121 | - if (!$length) { |
|
122 | - $obj = new self(self::NR3_ZERO); |
|
123 | - } else { |
|
124 | - $bytes = substr($data, $idx, $length); |
|
125 | - $byte = ord($bytes[0]); |
|
126 | - if (0x80 & $byte) { // bit 8 = 1 |
|
127 | - $obj = self::_decodeBinaryEncoding($bytes); |
|
128 | - } elseif (0x00 === $byte >> 6) { // bit 8 = 0, bit 7 = 0 |
|
129 | - $obj = self::_decodeDecimalEncoding($bytes); |
|
130 | - } else { // bit 8 = 0, bit 7 = 1 |
|
131 | - $obj = self::_decodeSpecialRealValue($bytes); |
|
132 | - } |
|
133 | - } |
|
134 | - $offset = $idx + $length; |
|
135 | - return $obj; |
|
136 | - } |
|
112 | + /** |
|
113 | + * {@inheritdoc} |
|
114 | + */ |
|
115 | + protected static function _decodeFromDER(Identifier $identifier, |
|
116 | + string $data, int &$offset): ElementBase |
|
117 | + { |
|
118 | + $idx = $offset; |
|
119 | + $length = Length::expectFromDER($data, $idx)->intLength(); |
|
120 | + // if length is zero, value is zero (spec 8.5.2) |
|
121 | + if (!$length) { |
|
122 | + $obj = new self(self::NR3_ZERO); |
|
123 | + } else { |
|
124 | + $bytes = substr($data, $idx, $length); |
|
125 | + $byte = ord($bytes[0]); |
|
126 | + if (0x80 & $byte) { // bit 8 = 1 |
|
127 | + $obj = self::_decodeBinaryEncoding($bytes); |
|
128 | + } elseif (0x00 === $byte >> 6) { // bit 8 = 0, bit 7 = 0 |
|
129 | + $obj = self::_decodeDecimalEncoding($bytes); |
|
130 | + } else { // bit 8 = 0, bit 7 = 1 |
|
131 | + $obj = self::_decodeSpecialRealValue($bytes); |
|
132 | + } |
|
133 | + } |
|
134 | + $offset = $idx + $length; |
|
135 | + return $obj; |
|
136 | + } |
|
137 | 137 | |
138 | - /** |
|
139 | - * @todo Implement |
|
140 | - * |
|
141 | - * @param string $data |
|
142 | - */ |
|
143 | - protected static function _decodeBinaryEncoding(string $data) |
|
144 | - { |
|
145 | - throw new \RuntimeException( |
|
146 | - 'Binary encoding of REAL is not implemented.'); |
|
147 | - } |
|
138 | + /** |
|
139 | + * @todo Implement |
|
140 | + * |
|
141 | + * @param string $data |
|
142 | + */ |
|
143 | + protected static function _decodeBinaryEncoding(string $data) |
|
144 | + { |
|
145 | + throw new \RuntimeException( |
|
146 | + 'Binary encoding of REAL is not implemented.'); |
|
147 | + } |
|
148 | 148 | |
149 | - /** |
|
150 | - * @param string $data |
|
151 | - * |
|
152 | - * @throws \RuntimeException |
|
153 | - * |
|
154 | - * @return self |
|
155 | - */ |
|
156 | - protected static function _decodeDecimalEncoding(string $data): self |
|
157 | - { |
|
158 | - $nr = ord($data[0]) & 0x03; |
|
159 | - if (0x03 !== $nr) { |
|
160 | - throw new \RuntimeException('Only NR3 form supported.'); |
|
161 | - } |
|
162 | - $str = substr($data, 1); |
|
163 | - return new self($str); |
|
164 | - } |
|
149 | + /** |
|
150 | + * @param string $data |
|
151 | + * |
|
152 | + * @throws \RuntimeException |
|
153 | + * |
|
154 | + * @return self |
|
155 | + */ |
|
156 | + protected static function _decodeDecimalEncoding(string $data): self |
|
157 | + { |
|
158 | + $nr = ord($data[0]) & 0x03; |
|
159 | + if (0x03 !== $nr) { |
|
160 | + throw new \RuntimeException('Only NR3 form supported.'); |
|
161 | + } |
|
162 | + $str = substr($data, 1); |
|
163 | + return new self($str); |
|
164 | + } |
|
165 | 165 | |
166 | - /** |
|
167 | - * @todo Implement |
|
168 | - * |
|
169 | - * @param string $data |
|
170 | - */ |
|
171 | - protected static function _decodeSpecialRealValue(string $data) |
|
172 | - { |
|
173 | - if (1 !== strlen($data)) { |
|
174 | - throw new DecodeException( |
|
175 | - 'SpecialRealValue must have one content octet.'); |
|
176 | - } |
|
177 | - $byte = ord($data[0]); |
|
178 | - if (0x40 === $byte) { // positive infinity |
|
179 | - throw new \RuntimeException('PLUS-INFINITY not supported.'); |
|
180 | - } |
|
181 | - if (0x41 === $byte) { // negative infinity |
|
182 | - throw new \RuntimeException('MINUS-INFINITY not supported.'); |
|
183 | - } |
|
184 | - throw new DecodeException('Invalid SpecialRealValue encoding.'); |
|
185 | - } |
|
166 | + /** |
|
167 | + * @todo Implement |
|
168 | + * |
|
169 | + * @param string $data |
|
170 | + */ |
|
171 | + protected static function _decodeSpecialRealValue(string $data) |
|
172 | + { |
|
173 | + if (1 !== strlen($data)) { |
|
174 | + throw new DecodeException( |
|
175 | + 'SpecialRealValue must have one content octet.'); |
|
176 | + } |
|
177 | + $byte = ord($data[0]); |
|
178 | + if (0x40 === $byte) { // positive infinity |
|
179 | + throw new \RuntimeException('PLUS-INFINITY not supported.'); |
|
180 | + } |
|
181 | + if (0x41 === $byte) { // negative infinity |
|
182 | + throw new \RuntimeException('MINUS-INFINITY not supported.'); |
|
183 | + } |
|
184 | + throw new DecodeException('Invalid SpecialRealValue encoding.'); |
|
185 | + } |
|
186 | 186 | |
187 | - /** |
|
188 | - * Convert decimal number string to NR3 form. |
|
189 | - * |
|
190 | - * @param string $str |
|
191 | - * |
|
192 | - * @return string |
|
193 | - */ |
|
194 | - private static function _decimalToNR3(string $str): string |
|
195 | - { |
|
196 | - // if number is in exponent form |
|
197 | - /** @var string[] $match */ |
|
198 | - if (preg_match(self::PHP_EXPONENT_DNUM, $str, $match)) { |
|
199 | - $parts = explode('.', $match[1]); |
|
200 | - $m = ltrim($parts[0], '0'); |
|
201 | - $e = intval($match[2]); |
|
202 | - // if mantissa had decimals |
|
203 | - if (2 === count($parts)) { |
|
204 | - $d = rtrim($parts[1], '0'); |
|
205 | - $e -= strlen($d); |
|
206 | - $m .= $d; |
|
207 | - } |
|
208 | - } else { |
|
209 | - // explode from decimal |
|
210 | - $parts = explode('.', $str); |
|
211 | - $m = ltrim($parts[0], '0'); |
|
212 | - // if number had decimals |
|
213 | - if (2 === count($parts)) { |
|
214 | - // exponent is negative number of the decimals |
|
215 | - $e = -strlen($parts[1]); |
|
216 | - // append decimals to the mantissa |
|
217 | - $m .= $parts[1]; |
|
218 | - } else { |
|
219 | - $e = 0; |
|
220 | - } |
|
221 | - // shift trailing zeroes from the mantissa to the exponent |
|
222 | - while ('0' === substr($m, -1)) { |
|
223 | - ++$e; |
|
224 | - $m = substr($m, 0, -1); |
|
225 | - } |
|
226 | - } |
|
227 | - /* if exponent is zero, it must be prefixed with a "+" sign |
|
187 | + /** |
|
188 | + * Convert decimal number string to NR3 form. |
|
189 | + * |
|
190 | + * @param string $str |
|
191 | + * |
|
192 | + * @return string |
|
193 | + */ |
|
194 | + private static function _decimalToNR3(string $str): string |
|
195 | + { |
|
196 | + // if number is in exponent form |
|
197 | + /** @var string[] $match */ |
|
198 | + if (preg_match(self::PHP_EXPONENT_DNUM, $str, $match)) { |
|
199 | + $parts = explode('.', $match[1]); |
|
200 | + $m = ltrim($parts[0], '0'); |
|
201 | + $e = intval($match[2]); |
|
202 | + // if mantissa had decimals |
|
203 | + if (2 === count($parts)) { |
|
204 | + $d = rtrim($parts[1], '0'); |
|
205 | + $e -= strlen($d); |
|
206 | + $m .= $d; |
|
207 | + } |
|
208 | + } else { |
|
209 | + // explode from decimal |
|
210 | + $parts = explode('.', $str); |
|
211 | + $m = ltrim($parts[0], '0'); |
|
212 | + // if number had decimals |
|
213 | + if (2 === count($parts)) { |
|
214 | + // exponent is negative number of the decimals |
|
215 | + $e = -strlen($parts[1]); |
|
216 | + // append decimals to the mantissa |
|
217 | + $m .= $parts[1]; |
|
218 | + } else { |
|
219 | + $e = 0; |
|
220 | + } |
|
221 | + // shift trailing zeroes from the mantissa to the exponent |
|
222 | + while ('0' === substr($m, -1)) { |
|
223 | + ++$e; |
|
224 | + $m = substr($m, 0, -1); |
|
225 | + } |
|
226 | + } |
|
227 | + /* if exponent is zero, it must be prefixed with a "+" sign |
|
228 | 228 | (X.690 07-2002, section 11.3.2.6) */ |
229 | - if (0 === $e) { |
|
230 | - $es = '+'; |
|
231 | - } else { |
|
232 | - $es = $e < 0 ? '-' : ''; |
|
233 | - } |
|
234 | - return sprintf('%s.E%s%d', $m, $es, abs($e)); |
|
235 | - } |
|
229 | + if (0 === $e) { |
|
230 | + $es = '+'; |
|
231 | + } else { |
|
232 | + $es = $e < 0 ? '-' : ''; |
|
233 | + } |
|
234 | + return sprintf('%s.E%s%d', $m, $es, abs($e)); |
|
235 | + } |
|
236 | 236 | |
237 | - /** |
|
238 | - * Convert NR3 form number to decimal. |
|
239 | - * |
|
240 | - * @param string $str |
|
241 | - * |
|
242 | - * @throws \UnexpectedValueException |
|
243 | - * |
|
244 | - * @return float |
|
245 | - */ |
|
246 | - private static function _nr3ToDecimal(string $str): float |
|
247 | - { |
|
248 | - /** @var string[] $match */ |
|
249 | - if (!preg_match(self::NR3_REGEX, $str, $match)) { |
|
250 | - throw new \UnexpectedValueException( |
|
251 | - "'{$str}' is not a valid NR3 form real."); |
|
252 | - } |
|
253 | - $m = $match[2]; |
|
254 | - // if number started with minus sign |
|
255 | - $inv = '-' === $match[1]; |
|
256 | - $e = intval($match[3]); |
|
257 | - // positive exponent |
|
258 | - if ($e > 0) { |
|
259 | - // pad with trailing zeroes |
|
260 | - $num = $m . str_repeat('0', $e); |
|
261 | - } elseif ($e < 0) { |
|
262 | - // pad with leading zeroes |
|
263 | - if (strlen($m) < abs($e)) { |
|
264 | - $m = str_repeat('0', intval(abs($e)) - strlen($m)) . $m; |
|
265 | - } |
|
266 | - // insert decimal point |
|
267 | - $num = substr($m, 0, $e) . '.' . substr($m, $e); |
|
268 | - } else { |
|
269 | - $num = empty($m) ? '0' : $m; |
|
270 | - } |
|
271 | - // if number is negative |
|
272 | - if ($inv) { |
|
273 | - $num = "-{$num}"; |
|
274 | - } |
|
275 | - return floatval($num); |
|
276 | - } |
|
237 | + /** |
|
238 | + * Convert NR3 form number to decimal. |
|
239 | + * |
|
240 | + * @param string $str |
|
241 | + * |
|
242 | + * @throws \UnexpectedValueException |
|
243 | + * |
|
244 | + * @return float |
|
245 | + */ |
|
246 | + private static function _nr3ToDecimal(string $str): float |
|
247 | + { |
|
248 | + /** @var string[] $match */ |
|
249 | + if (!preg_match(self::NR3_REGEX, $str, $match)) { |
|
250 | + throw new \UnexpectedValueException( |
|
251 | + "'{$str}' is not a valid NR3 form real."); |
|
252 | + } |
|
253 | + $m = $match[2]; |
|
254 | + // if number started with minus sign |
|
255 | + $inv = '-' === $match[1]; |
|
256 | + $e = intval($match[3]); |
|
257 | + // positive exponent |
|
258 | + if ($e > 0) { |
|
259 | + // pad with trailing zeroes |
|
260 | + $num = $m . str_repeat('0', $e); |
|
261 | + } elseif ($e < 0) { |
|
262 | + // pad with leading zeroes |
|
263 | + if (strlen($m) < abs($e)) { |
|
264 | + $m = str_repeat('0', intval(abs($e)) - strlen($m)) . $m; |
|
265 | + } |
|
266 | + // insert decimal point |
|
267 | + $num = substr($m, 0, $e) . '.' . substr($m, $e); |
|
268 | + } else { |
|
269 | + $num = empty($m) ? '0' : $m; |
|
270 | + } |
|
271 | + // if number is negative |
|
272 | + if ($inv) { |
|
273 | + $num = "-{$num}"; |
|
274 | + } |
|
275 | + return floatval($num); |
|
276 | + } |
|
277 | 277 | |
278 | - /** |
|
279 | - * Test that number is valid for this context. |
|
280 | - * |
|
281 | - * @param mixed $num |
|
282 | - * |
|
283 | - * @return bool |
|
284 | - */ |
|
285 | - private static function _validateNumber($num): bool |
|
286 | - { |
|
287 | - if (!preg_match(self::NR3_REGEX, $num)) { |
|
288 | - return false; |
|
289 | - } |
|
290 | - return true; |
|
291 | - } |
|
278 | + /** |
|
279 | + * Test that number is valid for this context. |
|
280 | + * |
|
281 | + * @param mixed $num |
|
282 | + * |
|
283 | + * @return bool |
|
284 | + */ |
|
285 | + private static function _validateNumber($num): bool |
|
286 | + { |
|
287 | + if (!preg_match(self::NR3_REGEX, $num)) { |
|
288 | + return false; |
|
289 | + } |
|
290 | + return true; |
|
291 | + } |
|
292 | 292 | } |
@@ -17,38 +17,38 @@ |
||
17 | 17 | */ |
18 | 18 | class NullType extends Element |
19 | 19 | { |
20 | - use UniversalClass; |
|
21 | - use PrimitiveType; |
|
20 | + use UniversalClass; |
|
21 | + use PrimitiveType; |
|
22 | 22 | |
23 | - /** |
|
24 | - * Constructor. |
|
25 | - */ |
|
26 | - public function __construct() |
|
27 | - { |
|
28 | - $this->_typeTag = self::TYPE_NULL; |
|
29 | - } |
|
23 | + /** |
|
24 | + * Constructor. |
|
25 | + */ |
|
26 | + public function __construct() |
|
27 | + { |
|
28 | + $this->_typeTag = self::TYPE_NULL; |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * {@inheritdoc} |
|
33 | - */ |
|
34 | - protected function _encodedContentDER(): string |
|
35 | - { |
|
36 | - return ''; |
|
37 | - } |
|
31 | + /** |
|
32 | + * {@inheritdoc} |
|
33 | + */ |
|
34 | + protected function _encodedContentDER(): string |
|
35 | + { |
|
36 | + return ''; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * {@inheritdoc} |
|
41 | - */ |
|
42 | - protected static function _decodeFromDER(Identifier $identifier, |
|
43 | - string $data, int &$offset): ElementBase |
|
44 | - { |
|
45 | - $idx = $offset; |
|
46 | - if (!$identifier->isPrimitive()) { |
|
47 | - throw new DecodeException('Null value must be primitive.'); |
|
48 | - } |
|
49 | - // null type has always zero length |
|
50 | - Length::expectFromDER($data, $idx, 0); |
|
51 | - $offset = $idx; |
|
52 | - return new self(); |
|
53 | - } |
|
39 | + /** |
|
40 | + * {@inheritdoc} |
|
41 | + */ |
|
42 | + protected static function _decodeFromDER(Identifier $identifier, |
|
43 | + string $data, int &$offset): ElementBase |
|
44 | + { |
|
45 | + $idx = $offset; |
|
46 | + if (!$identifier->isPrimitive()) { |
|
47 | + throw new DecodeException('Null value must be primitive.'); |
|
48 | + } |
|
49 | + // null type has always zero length |
|
50 | + Length::expectFromDER($data, $idx, 0); |
|
51 | + $offset = $idx; |
|
52 | + return new self(); |
|
53 | + } |
|
54 | 54 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace Sop\ASN1\Type\Primitive; |
6 | 6 |
@@ -12,26 +12,26 @@ |
||
12 | 12 | */ |
13 | 13 | class T61String extends PrimitiveString |
14 | 14 | { |
15 | - use UniversalClass; |
|
15 | + use UniversalClass; |
|
16 | 16 | |
17 | - /** |
|
18 | - * Constructor. |
|
19 | - * |
|
20 | - * @param string $string |
|
21 | - */ |
|
22 | - public function __construct(string $string) |
|
23 | - { |
|
24 | - $this->_typeTag = self::TYPE_T61_STRING; |
|
25 | - parent::__construct($string); |
|
26 | - } |
|
17 | + /** |
|
18 | + * Constructor. |
|
19 | + * |
|
20 | + * @param string $string |
|
21 | + */ |
|
22 | + public function __construct(string $string) |
|
23 | + { |
|
24 | + $this->_typeTag = self::TYPE_T61_STRING; |
|
25 | + parent::__construct($string); |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * {@inheritdoc} |
|
30 | - */ |
|
31 | - protected function _validateString(string $string): bool |
|
32 | - { |
|
33 | - // allow everything since there's literally |
|
34 | - // thousands of allowed characters (16 bit composed characters) |
|
35 | - return true; |
|
36 | - } |
|
28 | + /** |
|
29 | + * {@inheritdoc} |
|
30 | + */ |
|
31 | + protected function _validateString(string $string): bool |
|
32 | + { |
|
33 | + // allow everything since there's literally |
|
34 | + // thousands of allowed characters (16 bit composed characters) |
|
35 | + return true; |
|
36 | + } |
|
37 | 37 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace Sop\ASN1\Type\Primitive; |
6 | 6 |
@@ -14,24 +14,24 @@ |
||
14 | 14 | */ |
15 | 15 | class UTF8String extends PrimitiveString |
16 | 16 | { |
17 | - use UniversalClass; |
|
17 | + use UniversalClass; |
|
18 | 18 | |
19 | - /** |
|
20 | - * Constructor. |
|
21 | - * |
|
22 | - * @param string $string |
|
23 | - */ |
|
24 | - public function __construct(string $string) |
|
25 | - { |
|
26 | - $this->_typeTag = self::TYPE_UTF8_STRING; |
|
27 | - parent::__construct($string); |
|
28 | - } |
|
19 | + /** |
|
20 | + * Constructor. |
|
21 | + * |
|
22 | + * @param string $string |
|
23 | + */ |
|
24 | + public function __construct(string $string) |
|
25 | + { |
|
26 | + $this->_typeTag = self::TYPE_UTF8_STRING; |
|
27 | + parent::__construct($string); |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * {@inheritdoc} |
|
32 | - */ |
|
33 | - protected function _validateString(string $string): bool |
|
34 | - { |
|
35 | - return mb_check_encoding($string, 'UTF-8'); |
|
36 | - } |
|
30 | + /** |
|
31 | + * {@inheritdoc} |
|
32 | + */ |
|
33 | + protected function _validateString(string $string): bool |
|
34 | + { |
|
35 | + return mb_check_encoding($string, 'UTF-8'); |
|
36 | + } |
|
37 | 37 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace Sop\ASN1\Type\Primitive; |
6 | 6 |
@@ -17,70 +17,70 @@ |
||
17 | 17 | */ |
18 | 18 | class UTCTime extends TimeType |
19 | 19 | { |
20 | - use UniversalClass; |
|
21 | - use PrimitiveType; |
|
20 | + use UniversalClass; |
|
21 | + use PrimitiveType; |
|
22 | 22 | |
23 | - /** |
|
24 | - * Regular expression to parse date. |
|
25 | - * |
|
26 | - * DER restricts format to UTC timezone (Z suffix). |
|
27 | - * |
|
28 | - * @var string |
|
29 | - */ |
|
30 | - const REGEX = '#^' . |
|
31 | - '(\d\d)' . // YY |
|
32 | - '(\d\d)' . // MM |
|
33 | - '(\d\d)' . // DD |
|
34 | - '(\d\d)' . // hh |
|
35 | - '(\d\d)' . // mm |
|
36 | - '(\d\d)' . // ss |
|
37 | - 'Z' . // TZ |
|
38 | - '$#'; |
|
23 | + /** |
|
24 | + * Regular expression to parse date. |
|
25 | + * |
|
26 | + * DER restricts format to UTC timezone (Z suffix). |
|
27 | + * |
|
28 | + * @var string |
|
29 | + */ |
|
30 | + const REGEX = '#^' . |
|
31 | + '(\d\d)' . // YY |
|
32 | + '(\d\d)' . // MM |
|
33 | + '(\d\d)' . // DD |
|
34 | + '(\d\d)' . // hh |
|
35 | + '(\d\d)' . // mm |
|
36 | + '(\d\d)' . // ss |
|
37 | + 'Z' . // TZ |
|
38 | + '$#'; |
|
39 | 39 | |
40 | - /** |
|
41 | - * Constructor. |
|
42 | - * |
|
43 | - * @param \DateTimeImmutable $dt |
|
44 | - */ |
|
45 | - public function __construct(\DateTimeImmutable $dt) |
|
46 | - { |
|
47 | - $this->_typeTag = self::TYPE_UTC_TIME; |
|
48 | - parent::__construct($dt); |
|
49 | - } |
|
40 | + /** |
|
41 | + * Constructor. |
|
42 | + * |
|
43 | + * @param \DateTimeImmutable $dt |
|
44 | + */ |
|
45 | + public function __construct(\DateTimeImmutable $dt) |
|
46 | + { |
|
47 | + $this->_typeTag = self::TYPE_UTC_TIME; |
|
48 | + parent::__construct($dt); |
|
49 | + } |
|
50 | 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 | - } |
|
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 | - * {@inheritdoc} |
|
62 | - */ |
|
63 | - protected static function _decodeFromDER(Identifier $identifier, |
|
64 | - string $data, int &$offset): ElementBase |
|
65 | - { |
|
66 | - $idx = $offset; |
|
67 | - $length = Length::expectFromDER($data, $idx)->intLength(); |
|
68 | - $str = substr($data, $idx, $length); |
|
69 | - $idx += $length; |
|
70 | - /** @var string[] $match */ |
|
71 | - if (!preg_match(self::REGEX, $str, $match)) { |
|
72 | - throw new DecodeException('Invalid UTCTime format.'); |
|
73 | - } |
|
74 | - [, $year, $month, $day, $hour, $minute, $second] = $match; |
|
75 | - $time = $year . $month . $day . $hour . $minute . $second . self::TZ_UTC; |
|
76 | - $dt = \DateTimeImmutable::createFromFormat('!ymdHisT', $time, |
|
77 | - self::_createTimeZone(self::TZ_UTC)); |
|
78 | - if (!$dt) { |
|
79 | - throw new DecodeException( |
|
80 | - 'Failed to decode UTCTime: ' . |
|
81 | - self::_getLastDateTimeImmutableErrorsStr()); |
|
82 | - } |
|
83 | - $offset = $idx; |
|
84 | - return new self($dt); |
|
85 | - } |
|
60 | + /** |
|
61 | + * {@inheritdoc} |
|
62 | + */ |
|
63 | + protected static function _decodeFromDER(Identifier $identifier, |
|
64 | + string $data, int &$offset): ElementBase |
|
65 | + { |
|
66 | + $idx = $offset; |
|
67 | + $length = Length::expectFromDER($data, $idx)->intLength(); |
|
68 | + $str = substr($data, $idx, $length); |
|
69 | + $idx += $length; |
|
70 | + /** @var string[] $match */ |
|
71 | + if (!preg_match(self::REGEX, $str, $match)) { |
|
72 | + throw new DecodeException('Invalid UTCTime format.'); |
|
73 | + } |
|
74 | + [, $year, $month, $day, $hour, $minute, $second] = $match; |
|
75 | + $time = $year . $month . $day . $hour . $minute . $second . self::TZ_UTC; |
|
76 | + $dt = \DateTimeImmutable::createFromFormat('!ymdHisT', $time, |
|
77 | + self::_createTimeZone(self::TZ_UTC)); |
|
78 | + if (!$dt) { |
|
79 | + throw new DecodeException( |
|
80 | + 'Failed to decode UTCTime: ' . |
|
81 | + self::_getLastDateTimeImmutableErrorsStr()); |
|
82 | + } |
|
83 | + $offset = $idx; |
|
84 | + return new self($dt); |
|
85 | + } |
|
86 | 86 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace Sop\ASN1\Type\Primitive; |
6 | 6 |