Completed
Branch master (68ed5c)
by Ivan
04:20
created
src/CRL.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
                 'children' => [
16 16
                     'version' => [
17 17
                         'tag' => ASN1::TYPE_INTEGER,
18
-                        'mapping' => [1=>'v1','v2','v3']
18
+                        'mapping' => [ 1=>'v1', 'v2', 'v3' ]
19 19
                     ],
20 20
                     'signature' => [
21 21
                         'tag' => ASN1::TYPE_SEQUENCE,
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
     public static function parseData($data)
134 134
     {
135 135
         if (strpos($data, ' -BEGIN X509 CRL-') !== false) {
136
-            $data = str_replace([' -----BEGIN X509 CRL-----', '-----END X509 CRL-----', "\r", "\n"], '', $data);
136
+            $data = str_replace([ ' -----BEGIN X509 CRL-----', '-----END X509 CRL-----', "\r", "\n" ], '', $data);
137 137
             $data = base64_decode($data);
138 138
         }
139 139
         return ASN1::decodeDER($data, static::$crl);
Please login to merge, or discard this patch.
src/Certificate.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
                 'children' => [
16 16
                     'version' => [
17 17
                         'tag' => ASN1::TYPE_INTEGER,
18
-                        'mapping' => [1=>'v1','v2','v3']
18
+                        'mapping' => [ 1=>'v1', 'v2', 'v3' ]
19 19
                     ],
20 20
                     'serialNumber' => [
21 21
                         'tag' => ASN1::TYPE_INTEGER,
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
     public static function parseData($data, $meta = false)
157 157
     {
158 158
         if (strpos($data, '-BEGIN CERTIFICATE-') !== false) {
159
-            $data = str_replace(['-----BEGIN CERTIFICATE-----', '-----END CERTIFICATE-----', "\r", "\n"], '', $data);
159
+            $data = str_replace([ '-----BEGIN CERTIFICATE-----', '-----END CERTIFICATE-----', "\r", "\n" ], '', $data);
160 160
             $data = base64_decode($data);
161 161
         }
162 162
         return ASN1::decodeDER($data, static::$x509v3, false, $meta);
Please login to merge, or discard this patch.
src/OCSP.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
                 'children' => [
16 16
                     'version' => [
17 17
                         'tag' => ASN1::TYPE_INTEGER,
18
-                        'mapping' => [1=>'v1'],
18
+                        'mapping' => [ 1=>'v1' ],
19 19
                         'optional' => true
20 20
                     ],
21 21
                     'requestorName' => [
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
                                     'children' => [
144 144
                                         'version' => [
145 145
                                             'tag' => ASN1::TYPE_INTEGER,
146
-                                            'mapping' => [1=>'v1'],
146
+                                            'mapping' => [ 1=>'v1' ],
147 147
                                             'optional' => true
148 148
                                         ],
149 149
                                         'responderID' => [
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
                     [
272 272
                         'reqCert' => [
273 273
                             'hashAlgorithm' => [
274
-                                'algorithm' => ASN1::$oids[strtolower($algorithm)] ?? ASN1::$oids['md5']
274
+                                'algorithm' => ASN1::$oids[ strtolower($algorithm) ] ?? ASN1::$oids[ 'md5' ]
275 275
                             ],
276 276
                             'issuerNameHash' => $issuerNameHash,
277 277
                             'issuerKeyHash' => $issuerKeyHash,
@@ -307,8 +307,8 @@  discard block
 block discarded – undo
307 307
     public static function parseResponseSubject($data)
308 308
     {
309 309
         $map = static::$response;
310
-        $map['children']['responseBytes']['children']['response']['mapping']['children']['tbsResponseData']['tag'] = ASN1::TYPE_ANY_DER;
310
+        $map[ 'children' ][ 'responseBytes' ][ 'children' ][ 'response' ][ 'mapping' ][ 'children' ][ 'tbsResponseData' ][ 'tag' ] = ASN1::TYPE_ANY_DER;
311 311
         $temp = ASN1::decodeDER($data, $map);
312
-        return $temp['responseBytes']['response']['tbsResponseData'];
312
+        return $temp[ 'responseBytes' ][ 'response' ][ 'tbsResponseData' ];
313 313
     }
314 314
 }
Please login to merge, or discard this patch.
src/Timestamp.php 2 patches
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
             'messageImprint' => [
22 22
                 'tag' => ASN1::TYPE_SEQUENCE,
23 23
                 'children' => [
24
-                   'hashAlgorithm' => [
24
+                    'hashAlgorithm' => [
25 25
                         'tag' => ASN1::TYPE_SEQUENCE,
26 26
                         'children' => [
27 27
                             "algorithm" => [
@@ -32,10 +32,10 @@  discard block
 block discarded – undo
32 32
                                 'optional' => true
33 33
                             ]
34 34
                         ]
35
-                   ],
36
-                   'hashedMessage' => [
35
+                    ],
36
+                    'hashedMessage' => [
37 37
                         'tag' => ASN1::TYPE_OCTET_STRING
38
-                   ]
38
+                    ]
39 39
                 ]
40 40
             ],
41 41
             'nonce' => [
@@ -92,16 +92,16 @@  discard block
 block discarded – undo
92 92
                                 'tag' => ASN1::TYPE_SET,
93 93
                                 'children' => [
94 94
                                     'hashAlgorithm' => [
95
-                                         'tag' => ASN1::TYPE_SEQUENCE,
96
-                                         'children' => [
97
-                                             "algorithm" => [
98
-                                                 'tag' => ASN1::TYPE_OBJECT_IDENTIFIER
99
-                                             ],
100
-                                             'parameters' => [
101
-                                                 'tag' => ASN1::TYPE_ANY,
102
-                                                 'optional' => true
103
-                                             ]
104
-                                         ]
95
+                                            'tag' => ASN1::TYPE_SEQUENCE,
96
+                                            'children' => [
97
+                                                "algorithm" => [
98
+                                                    'tag' => ASN1::TYPE_OBJECT_IDENTIFIER
99
+                                                ],
100
+                                                'parameters' => [
101
+                                                    'tag' => ASN1::TYPE_ANY,
102
+                                                    'optional' => true
103
+                                                ]
104
+                                            ]
105 105
                                     ],
106 106
                                 ],
107 107
                             ],
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
             'messageImprint' => [
121 121
                 'tag' => ASN1::TYPE_SEQUENCE,
122 122
                 'children' => [
123
-                   'hashAlgorithm' => [
123
+                    'hashAlgorithm' => [
124 124
                         'tag' => ASN1::TYPE_SEQUENCE,
125 125
                         'children' => [
126 126
                             "algorithm" => [
@@ -131,11 +131,11 @@  discard block
 block discarded – undo
131 131
                                 'optional' => true
132 132
                             ]
133 133
                         ]
134
-                   ],
135
-                   'hashedMessage' => [
134
+                    ],
135
+                    'hashedMessage' => [
136 136
                         'tag' => ASN1::TYPE_OCTET_STRING,
137 137
                         'optional' => true // non-optional
138
-                   ]
138
+                    ]
139 139
                 ]
140 140
             ],
141 141
             'serialNumber' => ['tag' => ASN1::TYPE_INTEGER, 'optional' => true ], // non-optional
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
         'children' => [
13 13
             'version' => [
14 14
                 'tag' => ASN1::TYPE_INTEGER,
15
-                'mapping' => [1=>'v1','v2','v3']
15
+                'mapping' => [ 1=>'v1', 'v2', 'v3' ]
16 16
             ],
17 17
             'reqPolicy' => [
18 18
                 'tag' => ASN1::TYPE_OBJECT_IDENTIFIER,
@@ -83,11 +83,11 @@  discard block
 block discarded – undo
83 83
                 'tag' => ASN1::TYPE_SEQUENCE,
84 84
                 'optional' => true,
85 85
                 'children' => [
86
-                    'contentType' => ['tag' => ASN1::TYPE_OBJECT_IDENTIFIER ],
86
+                    'contentType' => [ 'tag' => ASN1::TYPE_OBJECT_IDENTIFIER ],
87 87
                     'signedData' => [
88 88
                         'tag' => ASN1::TYPE_SEQUENCE,
89 89
                         'children' => [
90
-                            'version' => ['tag' => ASN1::TYPE_INTEGER ],
90
+                            'version' => [ 'tag' => ASN1::TYPE_INTEGER ],
91 91
                             'algorithms' => [
92 92
                                 'tag' => ASN1::TYPE_SET,
93 93
                                 'children' => [
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
                                     ],
106 106
                                 ],
107 107
                             ],
108
-                            "tokenInfo" => ['tag' => ASN1::TYPE_ANY_RAW]
108
+                            "tokenInfo" => [ 'tag' => ASN1::TYPE_ANY_RAW ]
109 109
                         ]
110 110
                     ]
111 111
                 ]
@@ -115,8 +115,8 @@  discard block
 block discarded – undo
115 115
     protected static $tokenInfo = [
116 116
         'tag' => ASN1::TYPE_SEQUENCE,
117 117
         'children' => [
118
-            'version' => ['tag' => ASN1::TYPE_INTEGER, 'mapping' => [1 => 'v1','v2','v3'] ],
119
-            'policy' =>  ['tag' => ASN1::TYPE_OBJECT_IDENTIFIER, 'optional' => true ],
118
+            'version' => [ 'tag' => ASN1::TYPE_INTEGER, 'mapping' => [ 1 => 'v1', 'v2', 'v3' ] ],
119
+            'policy' =>  [ 'tag' => ASN1::TYPE_OBJECT_IDENTIFIER, 'optional' => true ],
120 120
             'messageImprint' => [
121 121
                 'tag' => ASN1::TYPE_SEQUENCE,
122 122
                 'children' => [
@@ -138,15 +138,15 @@  discard block
 block discarded – undo
138 138
                    ]
139 139
                 ]
140 140
             ],
141
-            'serialNumber' => ['tag' => ASN1::TYPE_INTEGER, 'optional' => true ], // non-optional
142
-            'genTime' => ['tag' => ASN1::TYPE_GENERALIZED_TIME], // GeneralizedTime (non-optional]
141
+            'serialNumber' => [ 'tag' => ASN1::TYPE_INTEGER, 'optional' => true ], // non-optional
142
+            'genTime' => [ 'tag' => ASN1::TYPE_GENERALIZED_TIME ], // GeneralizedTime (non-optional]
143 143
             'accuracy' => [
144 144
                 'tag' => ASN1::TYPE_SEQUENCE,
145 145
                 'optional' => true,
146 146
                 'children' => [
147
-                    'seconds' => ['tag' => ASN1::TYPE_ANY, 'optional' => true ],
148
-                    'millis' => ['tag' => ASN1::TYPE_ANY, 'optional' => true ],
149
-                    'micros' => ['tag' => ASN1::TYPE_ANY, 'optional' => true ],
147
+                    'seconds' => [ 'tag' => ASN1::TYPE_ANY, 'optional' => true ],
148
+                    'millis' => [ 'tag' => ASN1::TYPE_ANY, 'optional' => true ],
149
+                    'micros' => [ 'tag' => ASN1::TYPE_ANY, 'optional' => true ],
150 150
                 ]
151 151
             ],
152 152
             'ordering' => [
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
                 'tag' => ASN1::TYPE_INTEGER,
158 158
                 'optional' => true
159 159
             ],
160
-            'tsa' => ['tag' => ASN1::TYPE_NULL, 'optional' => true] // [0] GeneralName
160
+            'tsa' => [ 'tag' => ASN1::TYPE_NULL, 'optional' => true ] // [0] GeneralName
161 161
         ]
162 162
     ];
163 163
 
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
      */
187 187
     public static function generateRequestFromData($data, $nonce = true, $requireCert = false, $alg = 'sha1', $policy = null)
188 188
     {
189
-        if (!in_array($alg, ['sha1', 'sha256', 'sha384', 'sha512', 'md5'])) {
189
+        if (!in_array($alg, [ 'sha1', 'sha256', 'sha384', 'sha512', 'md5' ])) {
190 190
             throw new TimestampException('Unsupported hash algorithm');
191 191
         }
192 192
         $hash = hash($alg, $data, true);
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
      */
222 222
     public static function generateRequestFromHash($data, $nonce = true, $requireCert = false, $alg = 'sha1', $policy = null)
223 223
     {
224
-        if (!in_array($alg, ['sha1', 'sha256', 'sha384', 'sha512', 'md5'])) {
224
+        if (!in_array($alg, [ 'sha1', 'sha256', 'sha384', 'sha512', 'md5' ])) {
225 225
             throw new TimestampException('Unsupported hash algorithm');
226 226
         }
227 227
         if ($nonce === true) {
@@ -271,14 +271,14 @@  discard block
 block discarded – undo
271 271
     public static function parseResponseFromData($data)
272 272
     {
273 273
         $tsr = ASN1::decodeDER($data, static::$response);
274
-        if (in_array($tsr['status']['status'], [ 'granted', 'grantedWithMods']) &&
275
-            isset($tsr['timeStampToken']) &&
276
-            isset($tsr['timeStampToken']["signedData"]) &&
277
-            isset($tsr['timeStampToken']["signedData"]["tokenInfo"]) &&
278
-            isset($tsr['timeStampToken']["signedData"]["tokenInfo"][1])
274
+        if (in_array($tsr[ 'status' ][ 'status' ], [ 'granted', 'grantedWithMods' ]) &&
275
+            isset($tsr[ 'timeStampToken' ]) &&
276
+            isset($tsr[ 'timeStampToken' ][ "signedData" ]) &&
277
+            isset($tsr[ 'timeStampToken' ][ "signedData" ][ "tokenInfo" ]) &&
278
+            isset($tsr[ 'timeStampToken' ][ "signedData" ][ "tokenInfo" ][ 1 ])
279 279
         ) {
280
-            $tsr['timeStampToken']["signedData"]["tokenInfo"] = ASN1::decodeDER(
281
-                $tsr['timeStampToken']["signedData"]["tokenInfo"][1],
280
+            $tsr[ 'timeStampToken' ][ "signedData" ][ "tokenInfo" ] = ASN1::decodeDER(
281
+                $tsr[ 'timeStampToken' ][ "signedData" ][ "tokenInfo" ][ 1 ],
282 282
                 static::$tokenInfo
283 283
             );
284 284
         }
Please login to merge, or discard this patch.
src/ASN1.php 1 patch
Spacing   +222 added lines, -223 removed lines patch added patch discarded remove patch
@@ -293,8 +293,8 @@  discard block
 block discarded – undo
293 293
         $res = "";
294 294
         $len = ceil(strlen($bin) / 8) * 8;
295 295
         $bin = str_pad($bin, $len, "0", STR_PAD_LEFT);
296
-        for ($i = ($len-8); $i >= 0; $i -= 8) {
297
-            $res = chr(base_convert(substr($bin, $i, 8), 2, 10)) . $res;
296
+        for ($i = ($len - 8); $i >= 0; $i -= 8) {
297
+            $res = chr(base_convert(substr($bin, $i, 8), 2, 10)).$res;
298 298
         }
299 299
         return $res;
300 300
     }
@@ -321,18 +321,18 @@  discard block
 block discarded – undo
321 321
      */
322 322
     public static function encodeDER($source, $mapping)
323 323
     {
324
-        if (isset($mapping['default']) && $source === $mapping['default']) {
324
+        if (isset($mapping[ 'default' ]) && $source === $mapping[ 'default' ]) {
325 325
             return '';
326 326
         }
327 327
 
328
-        $tag = $mapping['tag'];
328
+        $tag = $mapping[ 'tag' ];
329 329
         switch ($tag) {
330 330
             case static::TYPE_SET:
331 331
             case static::TYPE_SEQUENCE:
332 332
                 $tag |= 0x20; // set the constructed bit
333 333
                 $value = '';
334
-                if (isset($mapping['min']) && isset($mapping['max'])) {
335
-                    $child = $mapping['children'];
334
+                if (isset($mapping[ 'min' ]) && isset($mapping[ 'max' ])) {
335
+                    $child = $mapping[ 'children' ];
336 336
                     foreach ($source as $content) {
337 337
                         $temp = static::encodeDER($content, $child);
338 338
                         if ($temp === false) {
@@ -342,23 +342,23 @@  discard block
 block discarded – undo
342 342
                     }
343 343
                     break;
344 344
                 }
345
-                if (isset($mapping['repeat'])) {
345
+                if (isset($mapping[ 'repeat' ])) {
346 346
                     foreach ($source as $content) {
347
-                        $temp = static::encodeDER($content, $mapping['repeat']);
347
+                        $temp = static::encodeDER($content, $mapping[ 'repeat' ]);
348 348
                         if ($temp === false) {
349 349
                             return false;
350 350
                         }
351 351
                         $value .= $temp;
352 352
                     }
353 353
                 } else {
354
-                    foreach ($mapping['children'] as $key => $child) {
354
+                    foreach ($mapping[ 'children' ] as $key => $child) {
355 355
                         if (!array_key_exists($key, $source)) {
356
-                            if (!isset($child['optional'])) {
356
+                            if (!isset($child[ 'optional' ])) {
357 357
                                 return false;
358 358
                             }
359 359
                             continue;
360 360
                         }
361
-                        $temp = static::encodeDER($source[$key], $child);
361
+                        $temp = static::encodeDER($source[ $key ], $child);
362 362
                         if ($temp === false) {
363 363
                             return false;
364 364
                         }
@@ -371,33 +371,33 @@  discard block
 block discarded – undo
371 371
                 break;
372 372
             case static::TYPE_CHOICE:
373 373
                 $temp = false;
374
-                foreach ($mapping['children'] as $key => $child) {
375
-                    if (!isset($source[$key])) {
374
+                foreach ($mapping[ 'children' ] as $key => $child) {
375
+                    if (!isset($source[ $key ])) {
376 376
                         continue;
377 377
                     }
378
-                    $temp = static::encodeDER($source[$key], $child);
378
+                    $temp = static::encodeDER($source[ $key ], $child);
379 379
                     if ($temp === false) {
380 380
                         return false;
381 381
                     }
382 382
                     if ($temp === '') {
383 383
                         continue;
384 384
                     }
385
-                    $tag = ord($temp[0]);
385
+                    $tag = ord($temp[ 0 ]);
386 386
                 }
387 387
                 return $temp;
388 388
             case static::TYPE_INTEGER:
389 389
             case static::TYPE_ENUMERATED:
390
-                if (!isset($mapping['mapping']) && isset($mapping['base']) && $mapping['base'] === 16) {
390
+                if (!isset($mapping[ 'mapping' ]) && isset($mapping[ 'base' ]) && $mapping[ 'base' ] === 16) {
391 391
                     $value = hex2bin($source);
392 392
                 } else {
393
-                    if (!isset($mapping['mapping'])) {
394
-                        $value = static::toBase256($source, isset($mapping['base']) ? $mapping['base'] : 10);
393
+                    if (!isset($mapping[ 'mapping' ])) {
394
+                        $value = static::toBase256($source, isset($mapping[ 'base' ]) ? $mapping[ 'base' ] : 10);
395 395
                     } else {
396
-                        $value = array_search($source, $mapping['mapping']);
396
+                        $value = array_search($source, $mapping[ 'mapping' ]);
397 397
                         if ($value === false) {
398 398
                             return false;
399 399
                         }
400
-                        $value = static::toBase256($value, isset($mapping['base']) ? $mapping['base'] : 10);
400
+                        $value = static::toBase256($value, isset($mapping[ 'base' ]) ? $mapping[ 'base' ] : 10);
401 401
                     }
402 402
                 }
403 403
                 if (!strlen($value)) {
@@ -406,23 +406,23 @@  discard block
 block discarded – undo
406 406
                 break;
407 407
             case static::TYPE_UTC_TIME:
408 408
             case static::TYPE_GENERALIZED_TIME:
409
-                $format = $mapping['tag'] == static::TYPE_UTC_TIME ? 'y' : 'Y';
410
-                $format.= 'mdHis';
411
-                $value = @gmdate($format, strtotime($source)) . 'Z';
409
+                $format = $mapping[ 'tag' ] == static::TYPE_UTC_TIME ? 'y' : 'Y';
410
+                $format .= 'mdHis';
411
+                $value = @gmdate($format, strtotime($source)).'Z';
412 412
                 break;
413 413
             case static::TYPE_BIT_STRING:
414
-                if (isset($mapping['mapping'])) {
415
-                    $bits = array_fill(0, count($mapping['mapping']), 0);
414
+                if (isset($mapping[ 'mapping' ])) {
415
+                    $bits = array_fill(0, count($mapping[ 'mapping' ]), 0);
416 416
                     $size = 0;
417
-                    for ($i = 0; $i < count($mapping['mapping']); $i++) {
418
-                        if (in_array($mapping['mapping'][$i], $source)) {
419
-                            $bits[$i] = 1;
417
+                    for ($i = 0; $i < count($mapping[ 'mapping' ]); $i++) {
418
+                        if (in_array($mapping[ 'mapping' ][ $i ], $source)) {
419
+                            $bits[ $i ] = 1;
420 420
                             $size = $i;
421 421
                         }
422 422
                     }
423 423
 
424
-                    if (isset($mapping['min']) && $mapping['min'] >= 1 && $size < $mapping['min']) {
425
-                        $size = $mapping['min'] - 1;
424
+                    if (isset($mapping[ 'min' ]) && $mapping[ 'min' ] >= 1 && $size < $mapping[ 'min' ]) {
425
+                        $size = $mapping[ 'min' ] - 1;
426 426
                     }
427 427
 
428 428
                     $offset = 8 - (($size + 1) & 7);
@@ -430,47 +430,46 @@  discard block
 block discarded – undo
430 430
 
431 431
                     $value = chr($offset);
432 432
 
433
-                    for ($i = $size + 1; $i < count($mapping['mapping']); $i++) {
434
-                        unset($bits[$i]);
433
+                    for ($i = $size + 1; $i < count($mapping[ 'mapping' ]); $i++) {
434
+                        unset($bits[ $i ]);
435 435
                     }
436 436
 
437 437
                     $bits = implode('', array_pad($bits, $size + $offset + 1, 0));
438 438
                     $bytes = explode(' ', rtrim(chunk_split($bits, 8, ' ')));
439 439
                     foreach ($bytes as $byte) {
440
-                        $value.= chr(bindec($byte));
440
+                        $value .= chr(bindec($byte));
441 441
                     }
442 442
 
443 443
                     break;
444 444
                 }
445 445
                 // default to octet string if no mapping is present
446 446
             case static::TYPE_OCTET_STRING:
447
-                $value = isset($mapping['raw']) && $mapping['raw'] ? $source : base64_decode($source);
447
+                $value = isset($mapping[ 'raw' ]) && $mapping[ 'raw' ] ? $source : base64_decode($source);
448 448
                 break;
449 449
             case static::TYPE_OBJECT_IDENTIFIER:
450
-                if (!isset($source) && $mapping['optional']) {
450
+                if (!isset($source) && $mapping[ 'optional' ]) {
451 451
                     return;
452 452
                 }
453 453
                 $oid = preg_match('(^(\d+\.?)+$)', $source) ?
454
-                    $source :
455
-                    (isset(static::$oids[$source]) ? static::$oids[$source] : false);
454
+                    $source : (isset(static::$oids[ $source ]) ? static::$oids[ $source ] : false);
456 455
                 if ($oid === false) {
457 456
                     throw new ASN1Exception('Invalid OID');
458 457
                 }
459 458
                 $value = '';
460 459
                 $parts = explode('.', $oid);
461
-                $value = chr(40 * $parts[0] + $parts[1]);
460
+                $value = chr(40 * $parts[ 0 ] + $parts[ 1 ]);
462 461
                 for ($i = 2; $i < count($parts); $i++) {
463 462
                     $temp = '';
464
-                    if (!$parts[$i]) {
463
+                    if (!$parts[ $i ]) {
465 464
                         $temp = "\0";
466 465
                     } else {
467
-                        while ($parts[$i]) {
468
-                            $temp = chr(0x80 | ($parts[$i] & 0x7F)) . $temp;
469
-                            $parts[$i] >>= 7;
466
+                        while ($parts[ $i ]) {
467
+                            $temp = chr(0x80 | ($parts[ $i ] & 0x7F)).$temp;
468
+                            $parts[ $i ] >>= 7;
470 469
                         }
471
-                        $temp[strlen($temp) - 1] = $temp[strlen($temp) - 1] & chr(0x7F);
470
+                        $temp[ strlen($temp) - 1 ] = $temp[ strlen($temp) - 1 ] & chr(0x7F);
472 471
                     }
473
-                    $value.= $temp;
472
+                    $value .= $temp;
474 473
                 }
475 474
                 break;
476 475
             case static::TYPE_ANY:
@@ -510,7 +509,7 @@  discard block
 block discarded – undo
510 509
                 throw new ASN1Exception('Mapping provides no type definition');
511 510
         }
512 511
 
513
-        return chr($tag) . static::encodeLength(strlen($value)) . $value;
512
+        return chr($tag).static::encodeLength(strlen($value)).$value;
514 513
     }
515 514
 
516 515
     protected static function encodeLength($length)
@@ -533,7 +532,7 @@  discard block
 block discarded – undo
533 532
     {
534 533
         $decoded = static::decode($encoded);
535 534
         if (count($decoded) === 1) {
536
-            $decoded = $decoded[0];
535
+            $decoded = $decoded[ 0 ];
537 536
         }
538 537
         $result = null;
539 538
         if ($mapping) {
@@ -558,7 +557,7 @@  discard block
 block discarded – undo
558 557
             fwrite($stream, $temp);
559 558
             rewind($stream);
560 559
         }
561
-        $result = [];
560
+        $result = [ ];
562 561
         $total = 0;
563 562
         while (!feof($stream)) {
564 563
             $read = 0;
@@ -609,7 +608,7 @@  discard block
 block discarded – undo
609 608
                     if (ord($oct1) === 0 && ord($oct2) === 0) {
610 609
                         break;
611 610
                     }
612
-                    $contents .= $oct1 . $oct2;
611
+                    $contents .= $oct1.$oct2;
613 612
                 }
614 613
                 $length = strlen($contents);
615 614
             } else {
@@ -622,19 +621,19 @@  discard block
 block discarded – undo
622 621
                 if ($constructed) {
623 622
                     $contents = static::decode($contents, $total + $start + $read);
624 623
                     if (count($contents) === 1) {
625
-                        $contents = $contents[0];
624
+                        $contents = $contents[ 0 ];
626 625
                     }
627 626
                 }
628 627
             } else {
629 628
                 switch ($tag) {
630 629
                     case static::TYPE_BOOLEAN:
631
-                        $contents = (bool)ord($contents[0]);
630
+                        $contents = (bool) ord($contents[ 0 ]);
632 631
                         break;
633 632
                     case static::TYPE_INTEGER:
634 633
                         $contents = static::fromBase256($contents);
635 634
                         break;
636 635
                     case static::TYPE_ENUMERATED:
637
-                        $contents = (int)base_convert(static::fromBase256($contents), 2, 10);
636
+                        $contents = (int) base_convert(static::fromBase256($contents), 2, 10);
638 637
                         break;
639 638
                     case static::TYPE_REAL:
640 639
                         // TODO: read the specs
@@ -644,16 +643,16 @@  discard block
 block discarded – undo
644 643
                             $temp = static::decode($contents, $total + $start + $read);
645 644
                             $real = '';
646 645
                             for ($i = 0; $i < count($temp) - 1; $i++) {
647
-                                $real .= $temp['contents'];
646
+                                $real .= $temp[ 'contents' ];
648 647
                             }
649
-                            $real = $temp[count($temp) - 1]['content'][0] . $real . substr($temp[$i]['content'], 1);
648
+                            $real = $temp[ count($temp) - 1 ][ 'content' ][ 0 ].$real.substr($temp[ $i ][ 'content' ], 1);
650 649
                             $contents = $real;
651 650
                         }
652 651
                         break;
653 652
                     case static::TYPE_OCTET_STRING:
654 653
                         if ($constructed) {
655
-                            $contents = implode('', array_map(function ($v) {
656
-                                return $v['contents'];
654
+                            $contents = implode('', array_map(function($v) {
655
+                                return $v[ 'contents' ];
657 656
                             }, static::decode($contents, $total + $start + $read)));
658 657
                         }
659 658
                         break;
@@ -666,16 +665,16 @@  discard block
 block discarded – undo
666 665
                         break;
667 666
                     case static::TYPE_OBJECT_IDENTIFIER:
668 667
                         $real = '';
669
-                        $temp = ord($contents[0]);
668
+                        $temp = ord($contents[ 0 ]);
670 669
                         $real = sprintf('%d.%d', floor($temp / 40), $temp % 40);
671 670
                         $obid = 0;
672 671
                         // process septets
673 672
                         for ($i = 1; $i < strlen($contents); $i++) {
674
-                            $temp = ord($contents[$i]);
673
+                            $temp = ord($contents[ $i ]);
675 674
                             $obid <<= 7;
676 675
                             $obid |= $temp & 0x7F;
677 676
                             if (~$temp & 0x80) {
678
-                                $real .= '.' . $obid;
677
+                                $real .= '.'.$obid;
679 678
                                 $obid = 0;
680 679
                             }
681 680
                         }
@@ -698,7 +697,7 @@  discard block
 block discarded – undo
698 697
                 }
699 698
             }
700 699
             if ($class > 0 || $tag > 0) {
701
-                $result[] = [
700
+                $result[ ] = [
702 701
                     'class'    => $class,
703 702
                     'tag'      => $tag,
704 703
                     'start'    => $total + $start,
@@ -716,37 +715,37 @@  discard block
 block discarded – undo
716 715
 
717 716
     protected static function map($decoded, $mapping, &$result, &$encoded)
718 717
     {
719
-        while ($decoded['class'] !== 0 && isset($decoded['contents']) && is_array($decoded['contents'])) {
720
-            $decoded = $decoded['contents'];
718
+        while ($decoded[ 'class' ] !== 0 && isset($decoded[ 'contents' ]) && is_array($decoded[ 'contents' ])) {
719
+            $decoded = $decoded[ 'contents' ];
721 720
         }
722
-        if ($mapping['tag'] === ASN1::TYPE_CHOICE) {
723
-            foreach ($mapping['children'] as $child) {
724
-                if ($decoded['tag'] === $child['tag']) {
721
+        if ($mapping[ 'tag' ] === ASN1::TYPE_CHOICE) {
722
+            foreach ($mapping[ 'children' ] as $child) {
723
+                if ($decoded[ 'tag' ] === $child[ 'tag' ]) {
725 724
                     $mapping = $child;
726
-                    if (isset($child['value']) && $child['value']) {
727
-                        $result = $child['value'];
725
+                    if (isset($child[ 'value' ]) && $child[ 'value' ]) {
726
+                        $result = $child[ 'value' ];
728 727
                         return true;
729 728
                     }
730 729
                     break;
731 730
                 }
732 731
             }
733 732
         }
734
-        if (in_array($mapping['tag'], [ASN1::TYPE_SEQUENCE, ASN1::TYPE_SET]) &&
735
-            in_array($decoded['tag'], [ASN1::TYPE_SEQUENCE, ASN1::TYPE_SET])) {
736
-            $mapping['tag'] = $decoded['tag'];
733
+        if (in_array($mapping[ 'tag' ], [ ASN1::TYPE_SEQUENCE, ASN1::TYPE_SET ]) &&
734
+            in_array($decoded[ 'tag' ], [ ASN1::TYPE_SEQUENCE, ASN1::TYPE_SET ])) {
735
+            $mapping[ 'tag' ] = $decoded[ 'tag' ];
737 736
         }
738
-        if (!in_array($mapping['tag'], [ASN1::TYPE_ANY, ASN1::TYPE_ANY_RAW, ASN1::TYPE_ANY_SKIP, ASN1::TYPE_ANY_DER]) && $mapping['tag'] !== $decoded['tag']) {
739
-            if (!isset($mapping['optional']) || !$mapping['optional']) {
737
+        if (!in_array($mapping[ 'tag' ], [ ASN1::TYPE_ANY, ASN1::TYPE_ANY_RAW, ASN1::TYPE_ANY_SKIP, ASN1::TYPE_ANY_DER ]) && $mapping[ 'tag' ] !== $decoded[ 'tag' ]) {
738
+            if (!isset($mapping[ 'optional' ]) || !$mapping[ 'optional' ]) {
740 739
                 throw new ASN1Exception('Decoded data does not match mapping');
741 740
             }
742 741
             return false;
743 742
         }
744
-        if ($mapping['tag'] === ASN1::TYPE_ANY && isset($decoded['tag'])) {
745
-            $mapping['tag'] = $decoded['tag'];
743
+        if ($mapping[ 'tag' ] === ASN1::TYPE_ANY && isset($decoded[ 'tag' ])) {
744
+            $mapping[ 'tag' ] = $decoded[ 'tag' ];
746 745
         }
747
-        switch ($mapping['tag']) {
746
+        switch ($mapping[ 'tag' ]) {
748 747
             case static::TYPE_ANY_DER:
749
-                $result = substr($encoded, $decoded['start'], $decoded['length']);
748
+                $result = substr($encoded, $decoded[ 'start' ], $decoded[ 'length' ]);
750 749
                 return true;
751 750
             case static::TYPE_ANY_SKIP:
752 751
                 $result = null;
@@ -755,58 +754,58 @@  discard block
 block discarded – undo
755 754
                 static::values($decoded, $result);
756 755
                 break;
757 756
             case static::TYPE_SET:
758
-                if (isset($mapping['repeat'])) {
759
-                    foreach ($decoded['contents'] as $i => $v) {
757
+                if (isset($mapping[ 'repeat' ])) {
758
+                    foreach ($decoded[ 'contents' ] as $i => $v) {
760 759
                         static::map(
761
-                            isset($decoded['contents'][$i]) ? $decoded['contents'][$i] : null,
762
-                            $mapping['repeat'],
763
-                            $result[$i],
760
+                            isset($decoded[ 'contents' ][ $i ]) ? $decoded[ 'contents' ][ $i ] : null,
761
+                            $mapping[ 'repeat' ],
762
+                            $result[ $i ],
764 763
                             $encoded
765 764
                         );
766 765
                     }
767 766
                 } else {
768
-                    $temp = $decoded['contents'];
769
-                    foreach ($mapping['children'] as $k => $v) {
770
-                        $result[$k] = null;
767
+                    $temp = $decoded[ 'contents' ];
768
+                    foreach ($mapping[ 'children' ] as $k => $v) {
769
+                        $result[ $k ] = null;
771 770
                         foreach ($temp as $kk => $vv) {
772
-                            if ($v['tag'] === ASN1::TYPE_ANY || $v['tag'] === $vv['tag']) {
773
-                                if (static::map($vv, $v, $result[$k], $encoded)) {
774
-                                    unset($temp[$kk]);
771
+                            if ($v[ 'tag' ] === ASN1::TYPE_ANY || $v[ 'tag' ] === $vv[ 'tag' ]) {
772
+                                if (static::map($vv, $v, $result[ $k ], $encoded)) {
773
+                                    unset($temp[ $kk ]);
775 774
                                 } else {
776
-                                    $result[$k] = null;
775
+                                    $result[ $k ] = null;
777 776
                                 }
778 777
                                 break;
779 778
                             }
780 779
                         }
781
-                        if ($result[$k] === null && (!isset($v['optional']) || !$v['optional'])) {
780
+                        if ($result[ $k ] === null && (!isset($v[ 'optional' ]) || !$v[ 'optional' ])) {
782 781
                             throw new ASN1Exception('Decoded data does not match mapping');
783 782
                         }
784 783
                     }
785 784
                 }
786 785
                 break;
787 786
             case static::TYPE_SEQUENCE:
788
-                $result = [];
787
+                $result = [ ];
789 788
                 $i = 0;
790
-                if (isset($mapping['repeat'])) {
791
-                    foreach ($decoded['contents'] as $i => $v) {
789
+                if (isset($mapping[ 'repeat' ])) {
790
+                    foreach ($decoded[ 'contents' ] as $i => $v) {
792 791
                         static::map(
793
-                            isset($decoded['contents'][$i]) ? $decoded['contents'][$i] : null,
794
-                            $mapping['repeat'],
795
-                            $result[$i],
792
+                            isset($decoded[ 'contents' ][ $i ]) ? $decoded[ 'contents' ][ $i ] : null,
793
+                            $mapping[ 'repeat' ],
794
+                            $result[ $i ],
796 795
                             $encoded
797 796
                         );
798 797
                     }
799 798
                 } else {
800
-                    if (!isset($mapping['children'])) {
799
+                    if (!isset($mapping[ 'children' ])) {
801 800
                         $result = null;
802 801
                         return true;
803 802
                     }
804
-                    foreach ($mapping['children'] as $k => $v) {
805
-                        $result[$k] = null;
803
+                    foreach ($mapping[ 'children' ] as $k => $v) {
804
+                        $result[ $k ] = null;
806 805
                         if (static::map(
807
-                                isset($decoded['contents'][$i]) ? $decoded['contents'][$i] : null,
806
+                                isset($decoded[ 'contents' ][ $i ]) ? $decoded[ 'contents' ][ $i ] : null,
808 807
                                 $v,
809
-                                $result[$k],
808
+                                $result[ $k ],
810 809
                                 $encoded
811 810
                         )) {
812 811
                             $i++;
@@ -815,78 +814,78 @@  discard block
 block discarded – undo
815 814
                 }
816 815
                 break;
817 816
             case static::TYPE_OBJECT_IDENTIFIER:
818
-                $result = array_search($decoded['contents'], static::$oids);
817
+                $result = array_search($decoded[ 'contents' ], static::$oids);
819 818
                 if ($result === false) {
820
-                    $result = $decoded['contents'];
819
+                    $result = $decoded[ 'contents' ];
821 820
                 }
822 821
                 break;
823 822
             case static::TYPE_OCTET_STRING:
824
-                if (isset($mapping['der']) && $mapping['der']) {
825
-                    $result = static::decodeDER($decoded['contents'], isset($mapping['mapping']) ? $mapping['mapping'] : null);
823
+                if (isset($mapping[ 'der' ]) && $mapping[ 'der' ]) {
824
+                    $result = static::decodeDER($decoded[ 'contents' ], isset($mapping[ 'mapping' ]) ? $mapping[ 'mapping' ] : null);
826 825
                 } else {
827
-                    $result = base64_encode($decoded['contents']);
826
+                    $result = base64_encode($decoded[ 'contents' ]);
828 827
                 }
829 828
                 break;
830 829
             case static::TYPE_INTEGER:
831
-                $base = isset($mapping['base']) && (int)$mapping['base'] ? (int)$mapping['base'] : 10;
830
+                $base = isset($mapping[ 'base' ]) && (int) $mapping[ 'base' ] ? (int) $mapping[ 'base' ] : 10;
832 831
                 if ($base < 3) {
833
-                    $result = $decoded['contents'];
832
+                    $result = $decoded[ 'contents' ];
834 833
                 } else {
835
-                    if (strlen($decoded['contents']) > 53 && $base === 16) {
834
+                    if (strlen($decoded[ 'contents' ]) > 53 && $base === 16) {
836 835
                         $hex = '';
837
-                        for ($i = strlen($decoded['contents']) - 4; $i >= 0; $i-=4) {
838
-                            $hex .= dechex(bindec(substr($decoded['contents'], $i, 4)));
836
+                        for ($i = strlen($decoded[ 'contents' ]) - 4; $i >= 0; $i -= 4) {
837
+                            $hex .= dechex(bindec(substr($decoded[ 'contents' ], $i, 4)));
839 838
                         }
840 839
                         $result = strrev($hex);
841 840
                     } else {
842
-                        $temp = base_convert($decoded['contents'], 2, $base);
841
+                        $temp = base_convert($decoded[ 'contents' ], 2, $base);
843 842
                         if ($base === 10) {
844
-                            $temp = (int)$temp;
843
+                            $temp = (int) $temp;
845 844
                         }
846 845
                         $result = $temp;
847 846
                     }
848 847
                 }
849
-                if (isset($mapping['mapping']) && isset($mapping['mapping'][$result])) {
850
-                    $result = $mapping['mapping'][$result];
848
+                if (isset($mapping[ 'mapping' ]) && isset($mapping[ 'mapping' ][ $result ])) {
849
+                    $result = $mapping[ 'mapping' ][ $result ];
851 850
                 }
852 851
                 break;
853 852
             case static::TYPE_UTC_TIME:
854
-                $content = $decoded['contents'];
853
+                $content = $decoded[ 'contents' ];
855 854
                 $format = 'YmdHis';
856
-                $matches = [];
855
+                $matches = [ ];
857 856
                 if (preg_match('#^(\d{10})(Z|[+-]\d{4})$#', $content, $matches)) {
858
-                    $content = $matches[1] . '00' . $matches[2];
857
+                    $content = $matches[ 1 ].'00'.$matches[ 2 ];
859 858
                 }
860 859
                 $prefix = substr($content, 0, 2) >= 50 ? '19' : '20';
861
-                $content = $prefix . $content;
862
-                if ($content[strlen($content) - 1] == 'Z') {
863
-                    $content = substr($content, 0, -1) . '+0000';
860
+                $content = $prefix.$content;
861
+                if ($content[ strlen($content) - 1 ] == 'Z') {
862
+                    $content = substr($content, 0, -1).'+0000';
864 863
                 }
865 864
                 if (strpos($content, '-') !== false || strpos($content, '+') !== false) {
866
-                    $format.= 'O';
865
+                    $format .= 'O';
867 866
                 }
868 867
                 $result = @DateTime::createFromFormat($format, $content);
869 868
                 $result = $result ? $result->getTimestamp() : false;
870 869
                 break;
871 870
             case static::TYPE_GENERALIZED_TIME:
872
-                $content = $decoded['contents'];
871
+                $content = $decoded[ 'contents' ];
873 872
                 $format = 'YmdHis';
874 873
                 if (strpos($content, '.') !== false) {
875
-                    $format.= '.u';
874
+                    $format .= '.u';
876 875
                 }
877
-                if ($content[strlen($content) - 1] == 'Z') {
878
-                    $content = substr($content, 0, -1) . '+0000';
876
+                if ($content[ strlen($content) - 1 ] == 'Z') {
877
+                    $content = substr($content, 0, -1).'+0000';
879 878
                 }
880 879
                 if (strpos($content, '-') !== false || strpos($content, '+') !== false) {
881
-                    $format.= 'O';
880
+                    $format .= 'O';
882 881
                 }
883 882
                 $result = @DateTime::createFromFormat($format, $content);
884 883
                 $result = $result ? $result->getTimestamp() : false;
885 884
                 break;
886 885
             default:
887
-                $result = $decoded['contents'];
888
-                if (isset($mapping['mapping']) && isset($mapping['mapping'][$result])) {
889
-                    $result = $mapping['mapping'][$result];
886
+                $result = $decoded[ 'contents' ];
887
+                if (isset($mapping[ 'mapping' ]) && isset($mapping[ 'mapping' ][ $result ])) {
888
+                    $result = $mapping[ 'mapping' ][ $result ];
890 889
                 }
891 890
                 break;
892 891
         }
@@ -895,104 +894,104 @@  discard block
 block discarded – undo
895 894
 
896 895
     protected static function mapMeta($decoded, $mapping, &$result, &$encoded)
897 896
     {
898
-        while ($decoded['class'] !== 0 && isset($decoded['contents']) && is_array($decoded['contents'])) {
899
-            $decoded = $decoded['contents'];
897
+        while ($decoded[ 'class' ] !== 0 && isset($decoded[ 'contents' ]) && is_array($decoded[ 'contents' ])) {
898
+            $decoded = $decoded[ 'contents' ];
900 899
         }
901 900
         $result = [
902
-            'raw'    => substr($encoded, $decoded['start'], $decoded['length']),
903
-            'start'  => $decoded['start'],
904
-            'length' => $decoded['length'],
905
-            'tag'    => $decoded['tag'],
906
-            'value'  => []
901
+            'raw'    => substr($encoded, $decoded[ 'start' ], $decoded[ 'length' ]),
902
+            'start'  => $decoded[ 'start' ],
903
+            'length' => $decoded[ 'length' ],
904
+            'tag'    => $decoded[ 'tag' ],
905
+            'value'  => [ ]
907 906
         ];
908
-        if ($mapping['tag'] === ASN1::TYPE_CHOICE) {
909
-            foreach ($mapping['children'] as $child) {
910
-                if ($decoded['tag'] === $child['tag']) {
907
+        if ($mapping[ 'tag' ] === ASN1::TYPE_CHOICE) {
908
+            foreach ($mapping[ 'children' ] as $child) {
909
+                if ($decoded[ 'tag' ] === $child[ 'tag' ]) {
911 910
                     $mapping = $child;
912
-                    if (isset($child['value']) && $child['value']) {
913
-                        $result['value'] = $child['value'];
911
+                    if (isset($child[ 'value' ]) && $child[ 'value' ]) {
912
+                        $result[ 'value' ] = $child[ 'value' ];
914 913
                         return true;
915 914
                     }
916 915
                     break;
917 916
                 }
918 917
             }
919 918
         }
920
-        if (in_array($mapping['tag'], [ASN1::TYPE_SEQUENCE, ASN1::TYPE_SET]) &&
921
-            in_array($decoded['tag'], [ASN1::TYPE_SEQUENCE, ASN1::TYPE_SET])) {
922
-            $mapping['tag'] = $decoded['tag'];
919
+        if (in_array($mapping[ 'tag' ], [ ASN1::TYPE_SEQUENCE, ASN1::TYPE_SET ]) &&
920
+            in_array($decoded[ 'tag' ], [ ASN1::TYPE_SEQUENCE, ASN1::TYPE_SET ])) {
921
+            $mapping[ 'tag' ] = $decoded[ 'tag' ];
923 922
         }
924
-        if (!in_array($mapping['tag'], [ASN1::TYPE_ANY, ASN1::TYPE_ANY_RAW, ASN1::TYPE_ANY_SKIP, ASN1::TYPE_ANY_DER]) && $mapping['tag'] !== $decoded['tag']) {
925
-            if (!isset($mapping['optional']) || !$mapping['optional']) {
923
+        if (!in_array($mapping[ 'tag' ], [ ASN1::TYPE_ANY, ASN1::TYPE_ANY_RAW, ASN1::TYPE_ANY_SKIP, ASN1::TYPE_ANY_DER ]) && $mapping[ 'tag' ] !== $decoded[ 'tag' ]) {
924
+            if (!isset($mapping[ 'optional' ]) || !$mapping[ 'optional' ]) {
926 925
                 throw new ASN1Exception('Decoded data does not match mapping');
927 926
             }
928 927
             return false;
929 928
         }
930
-        if ($mapping['tag'] === ASN1::TYPE_ANY && isset($decoded['tag'])) {
931
-            $mapping['tag'] = $decoded['tag'];
929
+        if ($mapping[ 'tag' ] === ASN1::TYPE_ANY && isset($decoded[ 'tag' ])) {
930
+            $mapping[ 'tag' ] = $decoded[ 'tag' ];
932 931
         }
933
-        switch ($mapping['tag']) {
932
+        switch ($mapping[ 'tag' ]) {
934 933
             case static::TYPE_ANY_DER:
935
-                $result['value'] = substr($encoded, $decoded['start'], $decoded['length']);
934
+                $result[ 'value' ] = substr($encoded, $decoded[ 'start' ], $decoded[ 'length' ]);
936 935
                 return true;
937 936
             case static::TYPE_ANY_SKIP:
938
-                $result['value'] = null;
937
+                $result[ 'value' ] = null;
939 938
                 return true;
940 939
             case static::TYPE_ANY_RAW:
941
-                static::values($decoded, $result['value']);
940
+                static::values($decoded, $result[ 'value' ]);
942 941
                 break;
943 942
             case static::TYPE_SET:
944
-                if (isset($mapping['repeat'])) {
945
-                    foreach ($decoded['contents'] as $i => $v) {
943
+                if (isset($mapping[ 'repeat' ])) {
944
+                    foreach ($decoded[ 'contents' ] as $i => $v) {
946 945
                         static::mapMeta(
947
-                            isset($decoded['contents'][$i]) ? $decoded['contents'][$i] : null,
948
-                            $mapping['repeat'],
949
-                            $result['value'][$i],
946
+                            isset($decoded[ 'contents' ][ $i ]) ? $decoded[ 'contents' ][ $i ] : null,
947
+                            $mapping[ 'repeat' ],
948
+                            $result[ 'value' ][ $i ],
950 949
                             $encoded
951 950
                         );
952 951
                     }
953 952
                 } else {
954
-                    $temp = $decoded['contents'];
955
-                    foreach ($mapping['children'] as $k => $v) {
956
-                        $result['value'][$k] = null;
953
+                    $temp = $decoded[ 'contents' ];
954
+                    foreach ($mapping[ 'children' ] as $k => $v) {
955
+                        $result[ 'value' ][ $k ] = null;
957 956
                         foreach ($temp as $kk => $vv) {
958
-                            if ($v['tag'] === ASN1::TYPE_ANY || $v['tag'] === $vv['tag']) {
959
-                                if (static::mapMeta($vv, $v, $result['value'][$k], $encoded)) {
960
-                                    unset($temp[$kk]);
957
+                            if ($v[ 'tag' ] === ASN1::TYPE_ANY || $v[ 'tag' ] === $vv[ 'tag' ]) {
958
+                                if (static::mapMeta($vv, $v, $result[ 'value' ][ $k ], $encoded)) {
959
+                                    unset($temp[ $kk ]);
961 960
                                 } else {
962
-                                    $result['value'][$k] = null;
961
+                                    $result[ 'value' ][ $k ] = null;
963 962
                                 }
964 963
                                 break;
965 964
                             }
966 965
                         }
967
-                        if ($result['value'][$k] === null && (!isset($v['optional']) || !$v['optional'])) {
966
+                        if ($result[ 'value' ][ $k ] === null && (!isset($v[ 'optional' ]) || !$v[ 'optional' ])) {
968 967
                             throw new ASN1Exception('Decoded data does not match mapping');
969 968
                         }
970 969
                     }
971 970
                 }
972 971
                 break;
973 972
             case static::TYPE_SEQUENCE:
974
-                $result['value'] = [];
973
+                $result[ 'value' ] = [ ];
975 974
                 $i = 0;
976
-                if (isset($mapping['repeat'])) {
977
-                    foreach ($decoded['contents'] as $i => $v) {
975
+                if (isset($mapping[ 'repeat' ])) {
976
+                    foreach ($decoded[ 'contents' ] as $i => $v) {
978 977
                         static::mapMeta(
979
-                            isset($decoded['contents'][$i]) ? $decoded['contents'][$i] : null,
980
-                            $mapping['repeat'],
981
-                            $result['value'][$i],
978
+                            isset($decoded[ 'contents' ][ $i ]) ? $decoded[ 'contents' ][ $i ] : null,
979
+                            $mapping[ 'repeat' ],
980
+                            $result[ 'value' ][ $i ],
982 981
                             $encoded
983 982
                         );
984 983
                     }
985 984
                 } else {
986
-                    if (!isset($mapping['children'])) {
985
+                    if (!isset($mapping[ 'children' ])) {
987 986
                         $result = null;
988 987
                         return true;
989 988
                     }
990
-                    foreach ($mapping['children'] as $k => $v) {
991
-                        $result['value'][$k] = null;
989
+                    foreach ($mapping[ 'children' ] as $k => $v) {
990
+                        $result[ 'value' ][ $k ] = null;
992 991
                         if (static::mapMeta(
993
-                                isset($decoded['contents'][$i]) ? $decoded['contents'][$i] : null,
992
+                                isset($decoded[ 'contents' ][ $i ]) ? $decoded[ 'contents' ][ $i ] : null,
994 993
                                 $v,
995
-                                $result['value'][$k],
994
+                                $result[ 'value' ][ $k ],
996 995
                                 $encoded
997 996
                         )) {
998 997
                             $i++;
@@ -1001,78 +1000,78 @@  discard block
 block discarded – undo
1001 1000
                 }
1002 1001
                 break;
1003 1002
             case static::TYPE_OBJECT_IDENTIFIER:
1004
-                $result['value'] = array_search($decoded['contents'], static::$oids);
1005
-                if ($result['value'] === false) {
1006
-                    $result['value'] = $decoded['contents'];
1003
+                $result[ 'value' ] = array_search($decoded[ 'contents' ], static::$oids);
1004
+                if ($result[ 'value' ] === false) {
1005
+                    $result[ 'value' ] = $decoded[ 'contents' ];
1007 1006
                 }
1008 1007
                 break;
1009 1008
             case static::TYPE_OCTET_STRING:
1010
-                if (isset($mapping['der']) && $mapping['der']) {
1011
-                    $result['value'] = static::decodeDER($decoded['contents'], isset($mapping['mapping']) ? $mapping['mapping'] : null, false, true);
1009
+                if (isset($mapping[ 'der' ]) && $mapping[ 'der' ]) {
1010
+                    $result[ 'value' ] = static::decodeDER($decoded[ 'contents' ], isset($mapping[ 'mapping' ]) ? $mapping[ 'mapping' ] : null, false, true);
1012 1011
                 } else {
1013
-                    $result['value'] = base64_encode($decoded['contents']);
1012
+                    $result[ 'value' ] = base64_encode($decoded[ 'contents' ]);
1014 1013
                 }
1015 1014
                 break;
1016 1015
             case static::TYPE_INTEGER:
1017
-                $base = isset($mapping['base']) && (int)$mapping['base'] ? (int)$mapping['base'] : 10;
1016
+                $base = isset($mapping[ 'base' ]) && (int) $mapping[ 'base' ] ? (int) $mapping[ 'base' ] : 10;
1018 1017
                 if ($base < 3) {
1019
-                    $result['value'] = $decoded['contents'];
1018
+                    $result[ 'value' ] = $decoded[ 'contents' ];
1020 1019
                 } else {
1021
-                    if (strlen($decoded['contents']) > 53 && $base === 16) {
1020
+                    if (strlen($decoded[ 'contents' ]) > 53 && $base === 16) {
1022 1021
                         $hex = '';
1023
-                        for ($i = strlen($decoded['contents']) - 4; $i >= 0; $i-=4) {
1024
-                            $hex .= dechex(bindec(substr($decoded['contents'], $i, 4)));
1022
+                        for ($i = strlen($decoded[ 'contents' ]) - 4; $i >= 0; $i -= 4) {
1023
+                            $hex .= dechex(bindec(substr($decoded[ 'contents' ], $i, 4)));
1025 1024
                         }
1026
-                        $result['value'] = strrev($hex);
1025
+                        $result[ 'value' ] = strrev($hex);
1027 1026
                     } else {
1028
-                        $temp = base_convert($decoded['contents'], 2, $base);
1027
+                        $temp = base_convert($decoded[ 'contents' ], 2, $base);
1029 1028
                         if ($base === 10) {
1030
-                            $temp = (int)$temp;
1029
+                            $temp = (int) $temp;
1031 1030
                         }
1032
-                        $result['value'] = $temp;
1031
+                        $result[ 'value' ] = $temp;
1033 1032
                     }
1034 1033
                 }
1035
-                if (isset($mapping['mapping']) && isset($mapping['mapping'][$result['value']])) {
1036
-                    $result['value'] = $mapping['mapping'][$result['value']];
1034
+                if (isset($mapping[ 'mapping' ]) && isset($mapping[ 'mapping' ][ $result[ 'value' ] ])) {
1035
+                    $result[ 'value' ] = $mapping[ 'mapping' ][ $result[ 'value' ] ];
1037 1036
                 }
1038 1037
                 break;
1039 1038
             case static::TYPE_UTC_TIME:
1040
-                $content = $decoded['contents'];
1039
+                $content = $decoded[ 'contents' ];
1041 1040
                 $format = 'YmdHis';
1042
-                $matches = [];
1041
+                $matches = [ ];
1043 1042
                 if (preg_match('#^(\d{10})(Z|[+-]\d{4})$#', $content, $matches)) {
1044
-                    $content = $matches[1] . '00' . $matches[2];
1043
+                    $content = $matches[ 1 ].'00'.$matches[ 2 ];
1045 1044
                 }
1046 1045
                 $prefix = substr($content, 0, 2) >= 50 ? '19' : '20';
1047
-                $content = $prefix . $content;
1048
-                if ($content[strlen($content) - 1] == 'Z') {
1049
-                    $content = substr($content, 0, -1) . '+0000';
1046
+                $content = $prefix.$content;
1047
+                if ($content[ strlen($content) - 1 ] == 'Z') {
1048
+                    $content = substr($content, 0, -1).'+0000';
1050 1049
                 }
1051 1050
                 if (strpos($content, '-') !== false || strpos($content, '+') !== false) {
1052
-                    $format.= 'O';
1051
+                    $format .= 'O';
1053 1052
                 }
1054
-                $result['value'] = @DateTime::createFromFormat($format, $content);
1055
-                $result['value'] = $result['value'] ? $result['value']->getTimestamp() : false;
1053
+                $result[ 'value' ] = @DateTime::createFromFormat($format, $content);
1054
+                $result[ 'value' ] = $result[ 'value' ] ? $result[ 'value' ]->getTimestamp() : false;
1056 1055
                 break;
1057 1056
             case static::TYPE_GENERALIZED_TIME:
1058
-                $content = $decoded['contents'];
1057
+                $content = $decoded[ 'contents' ];
1059 1058
                 $format = 'YmdHis';
1060 1059
                 if (strpos($content, '.') !== false) {
1061
-                    $format.= '.u';
1060
+                    $format .= '.u';
1062 1061
                 }
1063
-                if ($content[strlen($content) - 1] == 'Z') {
1064
-                    $content = substr($content, 0, -1) . '+0000';
1062
+                if ($content[ strlen($content) - 1 ] == 'Z') {
1063
+                    $content = substr($content, 0, -1).'+0000';
1065 1064
                 }
1066 1065
                 if (strpos($content, '-') !== false || strpos($content, '+') !== false) {
1067
-                    $format.= 'O';
1066
+                    $format .= 'O';
1068 1067
                 }
1069
-                $result['value'] = @DateTime::createFromFormat($format, $content);
1070
-                $result['value'] = $result['value'] ? $result['value']->getTimestamp() : false;
1068
+                $result[ 'value' ] = @DateTime::createFromFormat($format, $content);
1069
+                $result[ 'value' ] = $result[ 'value' ] ? $result[ 'value' ]->getTimestamp() : false;
1071 1070
                 break;
1072 1071
             default:
1073
-                $result['value'] = $decoded['contents'];
1074
-                if (isset($mapping['mapping']) && isset($mapping['mapping'][$result['value']])) {
1075
-                    $result['value'] = $mapping['mapping'][$result['value']];
1072
+                $result[ 'value' ] = $decoded[ 'contents' ];
1073
+                if (isset($mapping[ 'mapping' ]) && isset($mapping[ 'mapping' ][ $result[ 'value' ] ])) {
1074
+                    $result[ 'value' ] = $mapping[ 'mapping' ][ $result[ 'value' ] ];
1076 1075
                 }
1077 1076
                 break;
1078 1077
         }
@@ -1080,29 +1079,29 @@  discard block
 block discarded – undo
1080 1079
     }
1081 1080
 
1082 1081
     protected static function values($decoded, &$result) {
1083
-        while ($decoded['class'] !== 0 &&
1084
-            isset($decoded['contents']) &&
1085
-            is_array($decoded['contents']) &&
1086
-            isset($decoded['contents']['tag'])
1082
+        while ($decoded[ 'class' ] !== 0 &&
1083
+            isset($decoded[ 'contents' ]) &&
1084
+            is_array($decoded[ 'contents' ]) &&
1085
+            isset($decoded[ 'contents' ][ 'tag' ])
1087 1086
         ) {
1088
-            $decoded = $decoded['contents'];
1087
+            $decoded = $decoded[ 'contents' ];
1089 1088
         }
1090
-        switch ($decoded['tag']) {
1089
+        switch ($decoded[ 'tag' ]) {
1091 1090
             case static::TYPE_SEQUENCE:
1092 1091
             case static::TYPE_SET:
1093
-                foreach ($decoded['contents'] as $k => $v) {
1094
-                    $result[$k] = null;
1095
-                    static::values($v, $result[$k]);
1092
+                foreach ($decoded[ 'contents' ] as $k => $v) {
1093
+                    $result[ $k ] = null;
1094
+                    static::values($v, $result[ $k ]);
1096 1095
                 }
1097 1096
                 break;
1098 1097
             case static::TYPE_OBJECT_IDENTIFIER:
1099
-                $result = array_search($decoded['contents'], static::$oids);
1098
+                $result = array_search($decoded[ 'contents' ], static::$oids);
1100 1099
                 if ($result === false) {
1101
-                    $result = $decoded['contents'];
1100
+                    $result = $decoded[ 'contents' ];
1102 1101
                 }
1103 1102
                 break;
1104 1103
             default:
1105
-                $result = $decoded['contents'];
1104
+                $result = $decoded[ 'contents' ];
1106 1105
                 break;
1107 1106
         }
1108 1107
         return true;
Please login to merge, or discard this patch.