@@ -100,36 +100,35 @@ discard block |
||
100 | 100 | } |
101 | 101 | protected function decode($header) |
102 | 102 | { |
103 | - $contents = $header['content_length'] > 0 ? |
|
104 | - $this->reader->chunk($header['content_start'], $header['content_length']) : |
|
105 | - ''; |
|
106 | - if ($header['class'] !== ASN1::CLASS_UNIVERSAL) { |
|
103 | + $contents = $header[ 'content_length' ] > 0 ? |
|
104 | + $this->reader->chunk($header[ 'content_start' ], $header[ 'content_length' ]) : ''; |
|
105 | + if ($header[ 'class' ] !== ASN1::CLASS_UNIVERSAL) { |
|
107 | 106 | return $contents; |
108 | 107 | } |
109 | - switch ($header['tag']) { |
|
108 | + switch ($header[ 'tag' ]) { |
|
110 | 109 | case ASN1::TYPE_BOOLEAN: |
111 | - return (bool)ord($contents[0]); |
|
110 | + return (bool) ord($contents[ 0 ]); |
|
112 | 111 | case ASN1::TYPE_INTEGER: |
113 | 112 | return ASN1::fromBase256($contents); |
114 | 113 | case ASN1::TYPE_ENUMERATED: |
115 | - return (int)base_convert(ASN1::fromBase256($contents), 2, 10); |
|
114 | + return (int) base_convert(ASN1::fromBase256($contents), 2, 10); |
|
116 | 115 | case ASN1::TYPE_REAL: |
117 | 116 | // TODO: read the specs |
118 | 117 | return false; |
119 | 118 | case ASN1::TYPE_BIT_STRING: |
120 | - if ($header['constructed']) { |
|
119 | + if ($header[ 'constructed' ]) { |
|
121 | 120 | $temp = static::fromString($contents)->values(); |
122 | 121 | $real = ''; |
123 | 122 | for ($i = 0; $i < count($temp) - 1; $i++) { |
124 | - $real .= $temp['value']; |
|
123 | + $real .= $temp[ 'value' ]; |
|
125 | 124 | } |
126 | - return $temp[count($temp) - 1]['value'][0] . $real . substr($temp[$i]['value'], 1); |
|
125 | + return $temp[ count($temp) - 1 ][ 'value' ][ 0 ].$real.substr($temp[ $i ][ 'value' ], 1); |
|
127 | 126 | } |
128 | 127 | return $contents; |
129 | 128 | case ASN1::TYPE_OCTET_STRING: |
130 | - if ($header['constructed']) { |
|
131 | - return implode('', array_map(function ($v) { |
|
132 | - return $v['value']; |
|
129 | + if ($header[ 'constructed' ]) { |
|
130 | + return implode('', array_map(function($v) { |
|
131 | + return $v[ 'value' ]; |
|
133 | 132 | }, static::fromString($contents)->values())); |
134 | 133 | } |
135 | 134 | return $contents; |
@@ -137,14 +136,14 @@ discard block |
||
137 | 136 | return null; |
138 | 137 | case ASN1::TYPE_UTC_TIME: |
139 | 138 | $format = 'YmdHis'; |
140 | - $matches = []; |
|
139 | + $matches = [ ]; |
|
141 | 140 | if (preg_match('#^(\d{10})(Z|[+-]\d{4})$#', $contents, $matches)) { |
142 | - $contents = $matches[1] . '00' . $matches[2]; |
|
141 | + $contents = $matches[ 1 ].'00'.$matches[ 2 ]; |
|
143 | 142 | } |
144 | 143 | $prefix = substr($contents, 0, 2) >= 50 ? '19' : '20'; |
145 | - $contents = $prefix . $contents; |
|
146 | - if ($contents[strlen($contents) - 1] == 'Z') { |
|
147 | - $contents = substr($contents, 0, -1) . '+0000'; |
|
144 | + $contents = $prefix.$contents; |
|
145 | + if ($contents[ strlen($contents) - 1 ] == 'Z') { |
|
146 | + $contents = substr($contents, 0, -1).'+0000'; |
|
148 | 147 | } |
149 | 148 | if (strpos($contents, '-') !== false || strpos($contents, '+') !== false) { |
150 | 149 | $format .= 'O'; |
@@ -156,8 +155,8 @@ discard block |
||
156 | 155 | if (strpos($contents, '.') !== false) { |
157 | 156 | $format .= '.u'; |
158 | 157 | } |
159 | - if ($contents[strlen($contents) - 1] == 'Z') { |
|
160 | - $contents = substr($contents, 0, -1) . '+0000'; |
|
158 | + if ($contents[ strlen($contents) - 1 ] == 'Z') { |
|
159 | + $contents = substr($contents, 0, -1).'+0000'; |
|
161 | 160 | } |
162 | 161 | if (strpos($contents, '-') !== false || strpos($contents, '+') !== false) { |
163 | 162 | $format .= 'O'; |
@@ -165,16 +164,16 @@ discard block |
||
165 | 164 | $result = @DateTime::createFromFormat($format, $contents); |
166 | 165 | return $result ? $result->getTimestamp() : false; |
167 | 166 | case ASN1::TYPE_OBJECT_IDENTIFIER: |
168 | - $temp = ord($contents[0]); |
|
167 | + $temp = ord($contents[ 0 ]); |
|
169 | 168 | $real = sprintf('%d.%d', floor($temp / 40), $temp % 40); |
170 | 169 | $obid = 0; |
171 | 170 | // process septets |
172 | 171 | for ($i = 1; $i < strlen($contents); $i++) { |
173 | - $temp = ord($contents[$i]); |
|
172 | + $temp = ord($contents[ $i ]); |
|
174 | 173 | $obid <<= 7; |
175 | 174 | $obid |= $temp & 0x7F; |
176 | 175 | if (~$temp & 0x80) { |
177 | - $real .= '.' . $obid; |
|
176 | + $real .= '.'.$obid; |
|
178 | 177 | $obid = 0; |
179 | 178 | } |
180 | 179 | } |
@@ -191,55 +190,55 @@ discard block |
||
191 | 190 | */ |
192 | 191 | public function structure($max = null) |
193 | 192 | { |
194 | - $skeleton = []; |
|
193 | + $skeleton = [ ]; |
|
195 | 194 | while (!$this->reader->eof() && ($max === null || $this->reader->pos() < $max)) { |
196 | 195 | $header = $this->header(); |
197 | - if ($header['class'] === 0 && $header['tag'] === 0) { |
|
196 | + if ($header[ 'class' ] === 0 && $header[ 'tag' ] === 0) { |
|
198 | 197 | if ($max === null) { |
199 | 198 | break; |
200 | 199 | } else { |
201 | 200 | continue; |
202 | 201 | } |
203 | 202 | } |
204 | - if ($header['class'] !== ASN1::CLASS_UNIVERSAL && $header['constructed']) { |
|
205 | - $header['children'] = $this->structure( |
|
206 | - $header['length'] ? $header['start'] + $header['length'] - 1 : null |
|
203 | + if ($header[ 'class' ] !== ASN1::CLASS_UNIVERSAL && $header[ 'constructed' ]) { |
|
204 | + $header[ 'children' ] = $this->structure( |
|
205 | + $header[ 'length' ] ? $header[ 'start' ] + $header[ 'length' ] - 1 : null |
|
207 | 206 | ); |
208 | - if ($header['length'] === null) { |
|
207 | + if ($header[ 'length' ] === null) { |
|
209 | 208 | $this->reader->byte(); |
210 | - $header['length'] = $this->reader->pos() - $header['start']; |
|
211 | - $header['content_length'] = $this->reader->pos() - $header['content_start']; |
|
209 | + $header[ 'length' ] = $this->reader->pos() - $header[ 'start' ]; |
|
210 | + $header[ 'content_length' ] = $this->reader->pos() - $header[ 'content_start' ]; |
|
212 | 211 | } |
213 | - $skeleton[] = $header; |
|
212 | + $skeleton[ ] = $header; |
|
214 | 213 | } else { |
215 | - if ($header['class'] === ASN1::CLASS_UNIVERSAL && |
|
216 | - in_array($header['tag'], [ASN1::TYPE_SET, ASN1::TYPE_SEQUENCE]) |
|
214 | + if ($header[ 'class' ] === ASN1::CLASS_UNIVERSAL && |
|
215 | + in_array($header[ 'tag' ], [ ASN1::TYPE_SET, ASN1::TYPE_SEQUENCE ]) |
|
217 | 216 | ) { |
218 | - $header['children'] = $this->structure( |
|
219 | - $header['length'] ? $header['start'] + $header['length'] - 1 : null |
|
217 | + $header[ 'children' ] = $this->structure( |
|
218 | + $header[ 'length' ] ? $header[ 'start' ] + $header[ 'length' ] - 1 : null |
|
220 | 219 | ); |
221 | - if ($header['length'] === null) { |
|
220 | + if ($header[ 'length' ] === null) { |
|
222 | 221 | $this->reader->byte(); |
223 | - $header['length'] = $this->reader->pos() - $header['start']; |
|
224 | - $header['content_length'] = $this->reader->pos() - $header['content_start']; |
|
222 | + $header[ 'length' ] = $this->reader->pos() - $header[ 'start' ]; |
|
223 | + $header[ 'content_length' ] = $this->reader->pos() - $header[ 'content_start' ]; |
|
225 | 224 | } |
226 | 225 | } else { |
227 | - if ($header['length'] === null) { |
|
226 | + if ($header[ 'length' ] === null) { |
|
228 | 227 | $this->reader->readUntil(chr(0).chr(0)); |
229 | - $header['length'] = $this->reader->pos() - $header['start']; |
|
230 | - $header['content_length'] = $this->reader->pos() - $header['content_start']; |
|
228 | + $header[ 'length' ] = $this->reader->pos() - $header[ 'start' ]; |
|
229 | + $header[ 'content_length' ] = $this->reader->pos() - $header[ 'content_start' ]; |
|
231 | 230 | } else { |
232 | - if ($header['content_length'] > 0) { |
|
233 | - $this->reader->bytes($header['content_length']); |
|
231 | + if ($header[ 'content_length' ] > 0) { |
|
232 | + $this->reader->bytes($header[ 'content_length' ]); |
|
234 | 233 | } |
235 | 234 | } |
236 | 235 | } |
237 | - if (!isset($header['children'])) { |
|
236 | + if (!isset($header[ 'children' ])) { |
|
238 | 237 | $pos = $this->reader->pos(); |
239 | - $header['value'] = $this->decode($header); |
|
238 | + $header[ 'value' ] = $this->decode($header); |
|
240 | 239 | $this->reader->seek($pos); |
241 | 240 | } |
242 | - $skeleton[] = $header; |
|
241 | + $skeleton[ ] = $header; |
|
243 | 242 | } |
244 | 243 | } |
245 | 244 | return $skeleton; |
@@ -254,10 +253,10 @@ discard block |
||
254 | 253 | { |
255 | 254 | $skeleton = $skeleton ?? $this->structure(); |
256 | 255 | foreach ($skeleton as $k => $v) { |
257 | - if (isset($v['children'])) { |
|
258 | - $skeleton[$k] = $this->values($v['children']); |
|
256 | + if (isset($v[ 'children' ])) { |
|
257 | + $skeleton[ $k ] = $this->values($v[ 'children' ]); |
|
259 | 258 | } else { |
260 | - $skeleton[$k] = $v['value'] ?? null; |
|
259 | + $skeleton[ $k ] = $v[ 'value' ] ?? null; |
|
261 | 260 | } |
262 | 261 | } |
263 | 262 | return $skeleton; |
@@ -274,112 +273,112 @@ discard block |
||
274 | 273 | if ($skeleton === null && $this->reader->pos() !== 0) { |
275 | 274 | $this->reader->rewind(); |
276 | 275 | } |
277 | - $skeleton = $skeleton ?? $this->structure()[0] ?? null; |
|
276 | + $skeleton = $skeleton ?? $this->structure()[ 0 ] ?? null; |
|
278 | 277 | if (!isset($skeleton)) { |
279 | 278 | throw new ASN1Exception('No decoded data for map'); |
280 | 279 | } |
281 | - if ($skeleton['class'] !== ASN1::CLASS_UNIVERSAL) { |
|
282 | - if ($map['tag'] === ASN1::TYPE_CHOICE) { |
|
283 | - foreach ($map['children'] as $child) { |
|
284 | - if (isset($child['name']) && (int)$skeleton['tag'] === (int)$child['name']) { |
|
280 | + if ($skeleton[ 'class' ] !== ASN1::CLASS_UNIVERSAL) { |
|
281 | + if ($map[ 'tag' ] === ASN1::TYPE_CHOICE) { |
|
282 | + foreach ($map[ 'children' ] as $child) { |
|
283 | + if (isset($child[ 'name' ]) && (int) $skeleton[ 'tag' ] === (int) $child[ 'name' ]) { |
|
285 | 284 | $map = $child; |
286 | - if (isset($child['value']) && $child['value']) { |
|
287 | - return $child['value']; |
|
285 | + if (isset($child[ 'value' ]) && $child[ 'value' ]) { |
|
286 | + return $child[ 'value' ]; |
|
288 | 287 | } |
289 | 288 | break; |
290 | 289 | } |
291 | 290 | } |
292 | 291 | } |
293 | 292 | } |
294 | - if ($skeleton['class'] !== ASN1::CLASS_UNIVERSAL) { |
|
295 | - if (isset($map['implicit']) && $map['implicit']) { |
|
296 | - $skeleton['class'] = ASN1::CLASS_UNIVERSAL; |
|
297 | - $skeleton['tag'] = $map['tag']; |
|
293 | + if ($skeleton[ 'class' ] !== ASN1::CLASS_UNIVERSAL) { |
|
294 | + if (isset($map[ 'implicit' ]) && $map[ 'implicit' ]) { |
|
295 | + $skeleton[ 'class' ] = ASN1::CLASS_UNIVERSAL; |
|
296 | + $skeleton[ 'tag' ] = $map[ 'tag' ]; |
|
298 | 297 | } else { |
299 | - $skeleton = $skeleton['children'][0] ?? null; |
|
298 | + $skeleton = $skeleton[ 'children' ][ 0 ] ?? null; |
|
300 | 299 | } |
301 | 300 | } |
302 | - if ($map['tag'] === ASN1::TYPE_CHOICE) { |
|
303 | - foreach ($map['children'] as $child) { |
|
304 | - if ($skeleton['tag'] === $child['tag']) { |
|
301 | + if ($map[ 'tag' ] === ASN1::TYPE_CHOICE) { |
|
302 | + foreach ($map[ 'children' ] as $child) { |
|
303 | + if ($skeleton[ 'tag' ] === $child[ 'tag' ]) { |
|
305 | 304 | $map = $child; |
306 | - if (isset($child['value']) && $child['value']) { |
|
307 | - return $child['value']; |
|
305 | + if (isset($child[ 'value' ]) && $child[ 'value' ]) { |
|
306 | + return $child[ 'value' ]; |
|
308 | 307 | } |
309 | 308 | break; |
310 | 309 | } |
311 | 310 | } |
312 | 311 | } |
313 | - if (in_array($map['tag'], [ASN1::TYPE_SEQUENCE, ASN1::TYPE_SET]) && |
|
314 | - in_array($skeleton['tag'], [ASN1::TYPE_SEQUENCE, ASN1::TYPE_SET])) { |
|
315 | - $map['tag'] = $skeleton['tag']; |
|
312 | + if (in_array($map[ 'tag' ], [ ASN1::TYPE_SEQUENCE, ASN1::TYPE_SET ]) && |
|
313 | + in_array($skeleton[ 'tag' ], [ ASN1::TYPE_SEQUENCE, ASN1::TYPE_SET ])) { |
|
314 | + $map[ 'tag' ] = $skeleton[ 'tag' ]; |
|
316 | 315 | } |
317 | - if ($map['tag'] === ASN1::TYPE_ANY && isset($skeleton['tag'])) { |
|
318 | - $map['tag'] = $skeleton['tag']; |
|
316 | + if ($map[ 'tag' ] === ASN1::TYPE_ANY && isset($skeleton[ 'tag' ])) { |
|
317 | + $map[ 'tag' ] = $skeleton[ 'tag' ]; |
|
319 | 318 | } |
320 | - if (!in_array($map['tag'], [ASN1::TYPE_ANY, ASN1::TYPE_ANY_RAW, ASN1::TYPE_ANY_SKIP, ASN1::TYPE_ANY_DER]) && |
|
321 | - $map['tag'] !== $skeleton['tag'] |
|
319 | + if (!in_array($map[ 'tag' ], [ ASN1::TYPE_ANY, ASN1::TYPE_ANY_RAW, ASN1::TYPE_ANY_SKIP, ASN1::TYPE_ANY_DER ]) && |
|
320 | + $map[ 'tag' ] !== $skeleton[ 'tag' ] |
|
322 | 321 | ) { |
323 | - if (!isset($map['optional']) || !$map['optional']) { |
|
324 | - throw new ASN1Exception('Decoded data does not match mapping - ' . $skeleton['tag']); |
|
322 | + if (!isset($map[ 'optional' ]) || !$map[ 'optional' ]) { |
|
323 | + throw new ASN1Exception('Decoded data does not match mapping - '.$skeleton[ 'tag' ]); |
|
325 | 324 | } |
326 | 325 | return null; |
327 | 326 | } else { |
328 | - switch ($map['tag']) { |
|
327 | + switch ($map[ 'tag' ]) { |
|
329 | 328 | case ASN1::TYPE_ANY_DER: |
330 | - return $this->reader->chunk($skeleton['start'], $skeleton['length']); |
|
329 | + return $this->reader->chunk($skeleton[ 'start' ], $skeleton[ 'length' ]); |
|
331 | 330 | case ASN1::TYPE_ANY_SKIP: |
332 | 331 | return null; |
333 | 332 | case ASN1::TYPE_ANY_RAW: |
334 | - return $skeleton['value'] ?? null; |
|
333 | + return $skeleton[ 'value' ] ?? null; |
|
335 | 334 | case ASN1::TYPE_SET: |
336 | - if (isset($map['repeat'])) { |
|
337 | - $result = []; |
|
338 | - foreach ($skeleton['children'] as $v) { |
|
339 | - $result[] = $this->map($map['repeat'], $v); |
|
335 | + if (isset($map[ 'repeat' ])) { |
|
336 | + $result = [ ]; |
|
337 | + foreach ($skeleton[ 'children' ] as $v) { |
|
338 | + $result[ ] = $this->map($map[ 'repeat' ], $v); |
|
340 | 339 | } |
341 | 340 | return $result; |
342 | 341 | } else { |
343 | - if (!isset($map['children'])) { |
|
342 | + if (!isset($map[ 'children' ])) { |
|
344 | 343 | return null; |
345 | 344 | } |
346 | - $temp = $skeleton['children']; |
|
347 | - $result = []; |
|
345 | + $temp = $skeleton[ 'children' ]; |
|
346 | + $result = [ ]; |
|
348 | 347 | // named first |
349 | - foreach ($map['children'] as $k => $v) { |
|
350 | - if (isset($v['name'])) { |
|
351 | - $result[$k] = null; |
|
348 | + foreach ($map[ 'children' ] as $k => $v) { |
|
349 | + if (isset($v[ 'name' ])) { |
|
350 | + $result[ $k ] = null; |
|
352 | 351 | foreach ($temp as $kk => $vv) { |
353 | - if ($vv['class'] !== ASN1::CLASS_UNIVERSAL && (int)$v['name'] === $vv['tag']) { |
|
352 | + if ($vv[ 'class' ] !== ASN1::CLASS_UNIVERSAL && (int) $v[ 'name' ] === $vv[ 'tag' ]) { |
|
354 | 353 | try { |
355 | - if (isset($v['implicit']) && $v['implicit']) { |
|
356 | - $vv['class'] = ASN1::CLASS_UNIVERSAL; |
|
357 | - $vv['tag'] = $map['tag']; |
|
354 | + if (isset($v[ 'implicit' ]) && $v[ 'implicit' ]) { |
|
355 | + $vv[ 'class' ] = ASN1::CLASS_UNIVERSAL; |
|
356 | + $vv[ 'tag' ] = $map[ 'tag' ]; |
|
358 | 357 | } else { |
359 | - $vv = $vv['children'][0] ?? null; |
|
358 | + $vv = $vv[ 'children' ][ 0 ] ?? null; |
|
360 | 359 | } |
361 | - $result[$k] = $this->map($v, $vv); |
|
362 | - unset($temp[$kk]); |
|
360 | + $result[ $k ] = $this->map($v, $vv); |
|
361 | + unset($temp[ $kk ]); |
|
363 | 362 | break; |
364 | 363 | } catch (ASN1Exception $e) { |
365 | 364 | // continue trying other children in case of failure |
366 | 365 | } |
367 | 366 | } |
368 | 367 | } |
369 | - if ($result[$k] === null && (!isset($v['optional']) || !$v['optional'])) { |
|
370 | - throw new ASN1Exception('Missing tagged type - ' . $k); |
|
368 | + if ($result[ $k ] === null && (!isset($v[ 'optional' ]) || !$v[ 'optional' ])) { |
|
369 | + throw new ASN1Exception('Missing tagged type - '.$k); |
|
371 | 370 | } |
372 | 371 | } |
373 | 372 | } |
374 | - foreach ($map['children'] as $k => $v) { |
|
375 | - if (isset($v['name'])) { |
|
373 | + foreach ($map[ 'children' ] as $k => $v) { |
|
374 | + if (isset($v[ 'name' ])) { |
|
376 | 375 | continue; |
377 | 376 | } |
378 | - $result[$k] = null; |
|
377 | + $result[ $k ] = null; |
|
379 | 378 | foreach ($temp as $kk => $vv) { |
380 | - if ($v['tag'] === $vv['tag'] || |
|
379 | + if ($v[ 'tag' ] === $vv[ 'tag' ] || |
|
381 | 380 | in_array( |
382 | - $v['tag'], |
|
381 | + $v[ 'tag' ], |
|
383 | 382 | [ |
384 | 383 | ASN1::TYPE_ANY, |
385 | 384 | ASN1::TYPE_ANY_DER, |
@@ -390,53 +389,53 @@ discard block |
||
390 | 389 | ) |
391 | 390 | ) { |
392 | 391 | try { |
393 | - $result[$k] = $this->map($v, $vv); |
|
394 | - unset($temp[$kk]); |
|
392 | + $result[ $k ] = $this->map($v, $vv); |
|
393 | + unset($temp[ $kk ]); |
|
395 | 394 | break; |
396 | 395 | } catch (ASN1Exception $e) { |
397 | - $result[$k] = null; |
|
396 | + $result[ $k ] = null; |
|
398 | 397 | } |
399 | 398 | } |
400 | 399 | } |
401 | - if ($result[$k] === null && (!isset($v['optional']) || !$v['optional'])) { |
|
402 | - throw new ASN1Exception('Decoded data does not match mapping - ' . $k); |
|
400 | + if ($result[ $k ] === null && (!isset($v[ 'optional' ]) || !$v[ 'optional' ])) { |
|
401 | + throw new ASN1Exception('Decoded data does not match mapping - '.$k); |
|
403 | 402 | } |
404 | 403 | } |
405 | 404 | return $result; |
406 | 405 | } |
407 | 406 | break; |
408 | 407 | case ASN1::TYPE_SEQUENCE: |
409 | - if (isset($map['repeat'])) { |
|
410 | - $result = []; |
|
411 | - foreach ($skeleton['children'] as $v) { |
|
412 | - $result[] = $this->map($map['repeat'], $v); |
|
408 | + if (isset($map[ 'repeat' ])) { |
|
409 | + $result = [ ]; |
|
410 | + foreach ($skeleton[ 'children' ] as $v) { |
|
411 | + $result[ ] = $this->map($map[ 'repeat' ], $v); |
|
413 | 412 | } |
414 | 413 | return $result; |
415 | 414 | } else { |
416 | - if (!isset($map['children'])) { |
|
415 | + if (!isset($map[ 'children' ])) { |
|
417 | 416 | return null; |
418 | 417 | } |
419 | - $result = []; |
|
420 | - foreach ($skeleton['children'] as $vv) { |
|
421 | - foreach ($map['children'] as $k => $v) { |
|
422 | - if (isset($v['name']) && $vv['class'] !== ASN1::CLASS_UNIVERSAL && |
|
423 | - (int)$v['name'] === $vv['tag'] |
|
418 | + $result = [ ]; |
|
419 | + foreach ($skeleton[ 'children' ] as $vv) { |
|
420 | + foreach ($map[ 'children' ] as $k => $v) { |
|
421 | + if (isset($v[ 'name' ]) && $vv[ 'class' ] !== ASN1::CLASS_UNIVERSAL && |
|
422 | + (int) $v[ 'name' ] === $vv[ 'tag' ] |
|
424 | 423 | ) { |
425 | - if (isset($v['implicit']) && $v['implicit']) { |
|
426 | - $vv['class'] = ASN1::CLASS_UNIVERSAL; |
|
427 | - $vv['tag'] = $map['tag']; |
|
424 | + if (isset($v[ 'implicit' ]) && $v[ 'implicit' ]) { |
|
425 | + $vv[ 'class' ] = ASN1::CLASS_UNIVERSAL; |
|
426 | + $vv[ 'tag' ] = $map[ 'tag' ]; |
|
428 | 427 | } else { |
429 | - $vv = $vv['children'][0] ?? null; |
|
428 | + $vv = $vv[ 'children' ][ 0 ] ?? null; |
|
430 | 429 | } |
431 | - $result[$k] = $this->map($v, $vv); |
|
432 | - unset($map['children'][$k]); |
|
430 | + $result[ $k ] = $this->map($v, $vv); |
|
431 | + unset($map[ 'children' ][ $k ]); |
|
433 | 432 | break; |
434 | 433 | } |
435 | - if (!isset($v['name']) && |
|
434 | + if (!isset($v[ 'name' ]) && |
|
436 | 435 | ( |
437 | - $v['tag'] === $vv['tag'] || |
|
436 | + $v[ 'tag' ] === $vv[ 'tag' ] || |
|
438 | 437 | in_array( |
439 | - $v['tag'], |
|
438 | + $v[ 'tag' ], |
|
440 | 439 | [ |
441 | 440 | ASN1::TYPE_ANY, |
442 | 441 | ASN1::TYPE_ANY_DER, |
@@ -449,18 +448,18 @@ discard block |
||
449 | 448 | ) { |
450 | 449 | try { |
451 | 450 | $temp = $this->map($v, $vv); |
452 | - $result[$k] = $temp; |
|
453 | - unset($map['children'][$k]); |
|
451 | + $result[ $k ] = $temp; |
|
452 | + unset($map[ 'children' ][ $k ]); |
|
454 | 453 | break; |
455 | 454 | } catch (ASN1Exception $e) { |
456 | 455 | // continue trying other children in case of failure |
457 | 456 | } |
458 | 457 | } |
459 | - if (!isset($v['optional']) || !$v['optional']) { |
|
460 | - throw new ASN1Exception('Missing type - ' . $k); |
|
458 | + if (!isset($v[ 'optional' ]) || !$v[ 'optional' ]) { |
|
459 | + throw new ASN1Exception('Missing type - '.$k); |
|
461 | 460 | } else { |
462 | - $result[$k] = null; |
|
463 | - unset($map['children'][$k]); |
|
461 | + $result[ $k ] = null; |
|
462 | + unset($map[ 'children' ][ $k ]); |
|
464 | 463 | } |
465 | 464 | } |
466 | 465 | } |
@@ -468,49 +467,47 @@ discard block |
||
468 | 467 | } |
469 | 468 | break; |
470 | 469 | case ASN1::TYPE_OBJECT_IDENTIFIER: |
471 | - return isset($map['resolve']) && $map['resolve'] ? |
|
472 | - ASN1::OIDtoText($skeleton['value']) : |
|
473 | - $skeleton['value']; |
|
470 | + return isset($map[ 'resolve' ]) && $map[ 'resolve' ] ? |
|
471 | + ASN1::OIDtoText($skeleton[ 'value' ]) : $skeleton[ 'value' ]; |
|
474 | 472 | case ASN1::TYPE_OCTET_STRING: |
475 | - if (isset($map['der']) && $map['der']) { |
|
476 | - $temp = static::fromString($skeleton['value']); |
|
477 | - return isset($map['map']) ? $temp->map($map['map']) : $temp->values(); |
|
473 | + if (isset($map[ 'der' ]) && $map[ 'der' ]) { |
|
474 | + $temp = static::fromString($skeleton[ 'value' ]); |
|
475 | + return isset($map[ 'map' ]) ? $temp->map($map[ 'map' ]) : $temp->values(); |
|
478 | 476 | } else { |
479 | - return isset($map['raw']) && $map['raw'] ? |
|
480 | - $skeleton['value'] : |
|
481 | - base64_encode($skeleton['value']); |
|
477 | + return isset($map[ 'raw' ]) && $map[ 'raw' ] ? |
|
478 | + $skeleton[ 'value' ] : base64_encode($skeleton[ 'value' ]); |
|
482 | 479 | } |
483 | 480 | break; |
484 | 481 | case ASN1::TYPE_INTEGER: |
485 | - $base = isset($map['base']) && (int)$map['base'] ? (int)$map['base'] : 10; |
|
482 | + $base = isset($map[ 'base' ]) && (int) $map[ 'base' ] ? (int) $map[ 'base' ] : 10; |
|
486 | 483 | if ($base < 3) { |
487 | - $result = $skeleton['value']; |
|
484 | + $result = $skeleton[ 'value' ]; |
|
488 | 485 | } else { |
489 | - if (strlen($skeleton['value']) > 53 && $base === 16) { |
|
486 | + if (strlen($skeleton[ 'value' ]) > 53 && $base === 16) { |
|
490 | 487 | $hex = ''; |
491 | - for ($i = strlen($skeleton['value']) - 4; $i >= 0; $i-=4) { |
|
492 | - $hex .= dechex((int)bindec(substr($skeleton['value'], $i, 4))); |
|
488 | + for ($i = strlen($skeleton[ 'value' ]) - 4; $i >= 0; $i -= 4) { |
|
489 | + $hex .= dechex((int) bindec(substr($skeleton[ 'value' ], $i, 4))); |
|
493 | 490 | } |
494 | 491 | $result = strrev($hex); |
495 | 492 | } else { |
496 | - $temp = base_convert($skeleton['value'], 2, $base); |
|
493 | + $temp = base_convert($skeleton[ 'value' ], 2, $base); |
|
497 | 494 | if ($base === 10) { |
498 | - $temp = (int)$temp; |
|
495 | + $temp = (int) $temp; |
|
499 | 496 | } |
500 | 497 | $result = $temp; |
501 | 498 | } |
502 | 499 | } |
503 | - if (isset($map['map']) && isset($map['map'][$result])) { |
|
504 | - $result = $map['map'][$result]; |
|
500 | + if (isset($map[ 'map' ]) && isset($map[ 'map' ][ $result ])) { |
|
501 | + $result = $map[ 'map' ][ $result ]; |
|
505 | 502 | } |
506 | 503 | return $result; |
507 | 504 | case ASN1::TYPE_UTC_TIME: |
508 | 505 | case ASN1::TYPE_GENERALIZED_TIME: |
509 | - return $skeleton['value']; |
|
506 | + return $skeleton[ 'value' ]; |
|
510 | 507 | default: |
511 | - $result = $skeleton['value']; |
|
512 | - if (isset($map['map']) && isset($map['map'][$result])) { |
|
513 | - $result = $map['map'][$result]; |
|
508 | + $result = $skeleton[ 'value' ]; |
|
509 | + if (isset($map[ 'map' ]) && isset($map[ 'map' ][ $result ])) { |
|
510 | + $result = $map[ 'map' ][ $result ]; |
|
514 | 511 | } |
515 | 512 | return $result; |
516 | 513 | } |