GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( e19c33...8f1635 )
by Joni
03:53
created
lib/ASN1/Type/UnspecifiedType.php 2 patches
Indentation   +661 added lines, -661 removed lines patch added patch discarded remove patch
@@ -17,665 +17,665 @@
 block discarded – undo
17 17
  */
18 18
 class UnspecifiedType implements ElementBase
19 19
 {
20
-    /**
21
-     * The wrapped element.
22
-     *
23
-     * @var Element
24
-     */
25
-    private $_element;
26
-    
27
-    /**
28
-     * Constructor.
29
-     *
30
-     * @param Element $el
31
-     */
32
-    public function __construct(Element $el)
33
-    {
34
-        $this->_element = $el;
35
-    }
36
-    
37
-    /**
38
-     * Initialize from DER data.
39
-     *
40
-     * @param string $data DER encoded data
41
-     * @return self
42
-     */
43
-    public static function fromDER(string $data): self
44
-    {
45
-        return Element::fromDER($data)->asUnspecified();
46
-    }
47
-    
48
-    /**
49
-     * Initialize from ElementBase interface.
50
-     *
51
-     * @param ElementBase $el
52
-     * @return self
53
-     */
54
-    public static function fromElementBase(ElementBase $el): self
55
-    {
56
-        // if element is already wrapped
57
-        if ($el instanceof self) {
58
-            return $el;
59
-        }
60
-        return new self($el->asElement());
61
-    }
62
-    
63
-    /**
64
-     * Compatibility method to dispatch calls to the wrapped element.
65
-     *
66
-     * @deprecated Use <code>as*</code> accessor methods to ensure strict type
67
-     * @param string $mtd Method name
68
-     * @param array $args Arguments
69
-     * @return mixed
70
-     */
71
-    public function __call($mtd, array $args)
72
-    {
73
-        return call_user_func_array([$this->_element, $mtd], $args);
74
-    }
75
-    
76
-    /**
77
-     * Get the wrapped element as a context specific tagged type.
78
-     *
79
-     * @throws \UnexpectedValueException If the element is not tagged
80
-     * @return TaggedType
81
-     */
82
-    public function asTagged(): TaggedType
83
-    {
84
-        if (!$this->_element instanceof TaggedType) {
85
-            throw new \UnexpectedValueException(
86
-                "Tagged element expected, got " . $this->_typeDescriptorString());
87
-        }
88
-        return $this->_element;
89
-    }
90
-    
91
-    /**
92
-     * Get the wrapped element as an application specific type.
93
-     *
94
-     * @throws \UnexpectedValueException If element is not application specific
95
-     * @return \ASN1\Type\Tagged\ApplicationType
96
-     */
97
-    public function asApplication(): Tagged\ApplicationType
98
-    {
99
-        if (!$this->_element instanceof Tagged\ApplicationType) {
100
-            throw new \UnexpectedValueException(
101
-                "Application type expected, got " .
102
-                     $this->_typeDescriptorString());
103
-        }
104
-        return $this->_element;
105
-    }
106
-    
107
-    /**
108
-     * Get the wrapped element as a private tagged type.
109
-     *
110
-     * @throws \UnexpectedValueException If element is not using private tagging
111
-     * @return \ASN1\Type\Tagged\PrivateType
112
-     */
113
-    public function asPrivate(): Tagged\PrivateType
114
-    {
115
-        if (!$this->_element instanceof Tagged\PrivateType) {
116
-            throw new \UnexpectedValueException(
117
-                "Private type expected, got " . $this->_typeDescriptorString());
118
-        }
119
-        return $this->_element;
120
-    }
121
-    
122
-    /**
123
-     * Get the wrapped element as a boolean type.
124
-     *
125
-     * @throws \UnexpectedValueException If the element is not a boolean
126
-     * @return \ASN1\Type\Primitive\Boolean
127
-     */
128
-    public function asBoolean(): Primitive\Boolean
129
-    {
130
-        if (!$this->_element instanceof Primitive\Boolean) {
131
-            throw new \UnexpectedValueException(
132
-                $this->_generateExceptionMessage(Element::TYPE_BOOLEAN));
133
-        }
134
-        return $this->_element;
135
-    }
136
-    
137
-    /**
138
-     * Get the wrapped element as an integer type.
139
-     *
140
-     * @throws \UnexpectedValueException If the element is not an integer
141
-     * @return \ASN1\Type\Primitive\Integer
142
-     */
143
-    public function asInteger(): Primitive\Integer
144
-    {
145
-        if (!$this->_element instanceof Primitive\Integer) {
146
-            throw new \UnexpectedValueException(
147
-                $this->_generateExceptionMessage(Element::TYPE_INTEGER));
148
-        }
149
-        return $this->_element;
150
-    }
151
-    
152
-    /**
153
-     * Get the wrapped element as a bit string type.
154
-     *
155
-     * @throws \UnexpectedValueException If the element is not a bit string
156
-     * @return \ASN1\Type\Primitive\BitString
157
-     */
158
-    public function asBitString(): Primitive\BitString
159
-    {
160
-        if (!$this->_element instanceof Primitive\BitString) {
161
-            throw new \UnexpectedValueException(
162
-                $this->_generateExceptionMessage(Element::TYPE_BIT_STRING));
163
-        }
164
-        return $this->_element;
165
-    }
166
-    
167
-    /**
168
-     * Get the wrapped element as an octet string type.
169
-     *
170
-     * @throws \UnexpectedValueException If the element is not an octet string
171
-     * @return \ASN1\Type\Primitive\OctetString
172
-     */
173
-    public function asOctetString(): Primitive\OctetString
174
-    {
175
-        if (!$this->_element instanceof Primitive\OctetString) {
176
-            throw new \UnexpectedValueException(
177
-                $this->_generateExceptionMessage(Element::TYPE_OCTET_STRING));
178
-        }
179
-        return $this->_element;
180
-    }
181
-    
182
-    /**
183
-     * Get the wrapped element as a null type.
184
-     *
185
-     * @throws \UnexpectedValueException If the element is not a null
186
-     * @return \ASN1\Type\Primitive\NullType
187
-     */
188
-    public function asNull(): Primitive\NullType
189
-    {
190
-        if (!$this->_element instanceof Primitive\NullType) {
191
-            throw new \UnexpectedValueException(
192
-                $this->_generateExceptionMessage(Element::TYPE_NULL));
193
-        }
194
-        return $this->_element;
195
-    }
196
-    
197
-    /**
198
-     * Get the wrapped element as an object identifier type.
199
-     *
200
-     * @throws \UnexpectedValueException If the element is not an object
201
-     *         identifier
202
-     * @return \ASN1\Type\Primitive\ObjectIdentifier
203
-     */
204
-    public function asObjectIdentifier(): Primitive\ObjectIdentifier
205
-    {
206
-        if (!$this->_element instanceof Primitive\ObjectIdentifier) {
207
-            throw new \UnexpectedValueException(
208
-                $this->_generateExceptionMessage(
209
-                    Element::TYPE_OBJECT_IDENTIFIER));
210
-        }
211
-        return $this->_element;
212
-    }
213
-    
214
-    /**
215
-     * Get the wrapped element as an object descriptor type.
216
-     *
217
-     * @throws \UnexpectedValueException If the element is not an object
218
-     *         descriptor
219
-     * @return \ASN1\Type\Primitive\ObjectDescriptor
220
-     */
221
-    public function asObjectDescriptor(): Primitive\ObjectDescriptor
222
-    {
223
-        if (!$this->_element instanceof Primitive\ObjectDescriptor) {
224
-            throw new \UnexpectedValueException(
225
-                $this->_generateExceptionMessage(
226
-                    Element::TYPE_OBJECT_DESCRIPTOR));
227
-        }
228
-        return $this->_element;
229
-    }
230
-    
231
-    /**
232
-     * Get the wrapped element as a real type.
233
-     *
234
-     * @throws \UnexpectedValueException If the element is not a real
235
-     * @return \ASN1\Type\Primitive\Real
236
-     */
237
-    public function asReal(): Primitive\Real
238
-    {
239
-        if (!$this->_element instanceof Primitive\Real) {
240
-            throw new \UnexpectedValueException(
241
-                $this->_generateExceptionMessage(Element::TYPE_REAL));
242
-        }
243
-        return $this->_element;
244
-    }
245
-    
246
-    /**
247
-     * Get the wrapped element as an enumerated type.
248
-     *
249
-     * @throws \UnexpectedValueException If the element is not an enumerated
250
-     * @return \ASN1\Type\Primitive\Enumerated
251
-     */
252
-    public function asEnumerated(): Primitive\Enumerated
253
-    {
254
-        if (!$this->_element instanceof Primitive\Enumerated) {
255
-            throw new \UnexpectedValueException(
256
-                $this->_generateExceptionMessage(Element::TYPE_ENUMERATED));
257
-        }
258
-        return $this->_element;
259
-    }
260
-    
261
-    /**
262
-     * Get the wrapped element as a UTF8 string type.
263
-     *
264
-     * @throws \UnexpectedValueException If the element is not a UTF8 string
265
-     * @return \ASN1\Type\Primitive\UTF8String
266
-     */
267
-    public function asUTF8String(): Primitive\UTF8String
268
-    {
269
-        if (!$this->_element instanceof Primitive\UTF8String) {
270
-            throw new \UnexpectedValueException(
271
-                $this->_generateExceptionMessage(Element::TYPE_UTF8_STRING));
272
-        }
273
-        return $this->_element;
274
-    }
275
-    
276
-    /**
277
-     * Get the wrapped element as a relative OID type.
278
-     *
279
-     * @throws \UnexpectedValueException If the element is not a relative OID
280
-     * @return \ASN1\Type\Primitive\RelativeOID
281
-     */
282
-    public function asRelativeOID(): Primitive\RelativeOID
283
-    {
284
-        if (!$this->_element instanceof Primitive\RelativeOID) {
285
-            throw new \UnexpectedValueException(
286
-                $this->_generateExceptionMessage(Element::TYPE_RELATIVE_OID));
287
-        }
288
-        return $this->_element;
289
-    }
290
-    
291
-    /**
292
-     * Get the wrapped element as a sequence type.
293
-     *
294
-     * @throws \UnexpectedValueException If the element is not a sequence
295
-     * @return \ASN1\Type\Constructed\Sequence
296
-     */
297
-    public function asSequence(): Constructed\Sequence
298
-    {
299
-        if (!$this->_element instanceof Constructed\Sequence) {
300
-            throw new \UnexpectedValueException(
301
-                $this->_generateExceptionMessage(Element::TYPE_SEQUENCE));
302
-        }
303
-        return $this->_element;
304
-    }
305
-    
306
-    /**
307
-     * Get the wrapped element as a set type.
308
-     *
309
-     * @throws \UnexpectedValueException If the element is not a set
310
-     * @return \ASN1\Type\Constructed\Set
311
-     */
312
-    public function asSet(): Constructed\Set
313
-    {
314
-        if (!$this->_element instanceof Constructed\Set) {
315
-            throw new \UnexpectedValueException(
316
-                $this->_generateExceptionMessage(Element::TYPE_SET));
317
-        }
318
-        return $this->_element;
319
-    }
320
-    
321
-    /**
322
-     * Get the wrapped element as a numeric string type.
323
-     *
324
-     * @throws \UnexpectedValueException If the element is not a numeric string
325
-     * @return \ASN1\Type\Primitive\NumericString
326
-     */
327
-    public function asNumericString(): Primitive\NumericString
328
-    {
329
-        if (!$this->_element instanceof Primitive\NumericString) {
330
-            throw new \UnexpectedValueException(
331
-                $this->_generateExceptionMessage(Element::TYPE_NUMERIC_STRING));
332
-        }
333
-        return $this->_element;
334
-    }
335
-    
336
-    /**
337
-     * Get the wrapped element as a printable string type.
338
-     *
339
-     * @throws \UnexpectedValueException If the element is not a printable
340
-     *         string
341
-     * @return \ASN1\Type\Primitive\PrintableString
342
-     */
343
-    public function asPrintableString(): Primitive\PrintableString
344
-    {
345
-        if (!$this->_element instanceof Primitive\PrintableString) {
346
-            throw new \UnexpectedValueException(
347
-                $this->_generateExceptionMessage(Element::TYPE_PRINTABLE_STRING));
348
-        }
349
-        return $this->_element;
350
-    }
351
-    
352
-    /**
353
-     * Get the wrapped element as a T61 string type.
354
-     *
355
-     * @throws \UnexpectedValueException If the element is not a T61 string
356
-     * @return \ASN1\Type\Primitive\T61String
357
-     */
358
-    public function asT61String(): Primitive\T61String
359
-    {
360
-        if (!$this->_element instanceof Primitive\T61String) {
361
-            throw new \UnexpectedValueException(
362
-                $this->_generateExceptionMessage(Element::TYPE_T61_STRING));
363
-        }
364
-        return $this->_element;
365
-    }
366
-    
367
-    /**
368
-     * Get the wrapped element as a videotex string type.
369
-     *
370
-     * @throws \UnexpectedValueException If the element is not a videotex string
371
-     * @return \ASN1\Type\Primitive\VideotexString
372
-     */
373
-    public function asVideotexString(): Primitive\VideotexString
374
-    {
375
-        if (!$this->_element instanceof Primitive\VideotexString) {
376
-            throw new \UnexpectedValueException(
377
-                $this->_generateExceptionMessage(Element::TYPE_VIDEOTEX_STRING));
378
-        }
379
-        return $this->_element;
380
-    }
381
-    
382
-    /**
383
-     * Get the wrapped element as a IA5 string type.
384
-     *
385
-     * @throws \UnexpectedValueException If the element is not a IA5 string
386
-     * @return \ASN1\Type\Primitive\IA5String
387
-     */
388
-    public function asIA5String(): Primitive\IA5String
389
-    {
390
-        if (!$this->_element instanceof Primitive\IA5String) {
391
-            throw new \UnexpectedValueException(
392
-                $this->_generateExceptionMessage(Element::TYPE_IA5_STRING));
393
-        }
394
-        return $this->_element;
395
-    }
396
-    
397
-    /**
398
-     * Get the wrapped element as an UTC time type.
399
-     *
400
-     * @throws \UnexpectedValueException If the element is not a UTC time
401
-     * @return \ASN1\Type\Primitive\UTCTime
402
-     */
403
-    public function asUTCTime(): Primitive\UTCTime
404
-    {
405
-        if (!$this->_element instanceof Primitive\UTCTime) {
406
-            throw new \UnexpectedValueException(
407
-                $this->_generateExceptionMessage(Element::TYPE_UTC_TIME));
408
-        }
409
-        return $this->_element;
410
-    }
411
-    
412
-    /**
413
-     * Get the wrapped element as a generalized time type.
414
-     *
415
-     * @throws \UnexpectedValueException If the element is not a generalized
416
-     *         time
417
-     * @return \ASN1\Type\Primitive\GeneralizedTime
418
-     */
419
-    public function asGeneralizedTime(): Primitive\GeneralizedTime
420
-    {
421
-        if (!$this->_element instanceof Primitive\GeneralizedTime) {
422
-            throw new \UnexpectedValueException(
423
-                $this->_generateExceptionMessage(Element::TYPE_GENERALIZED_TIME));
424
-        }
425
-        return $this->_element;
426
-    }
427
-    
428
-    /**
429
-     * Get the wrapped element as a graphic string type.
430
-     *
431
-     * @throws \UnexpectedValueException If the element is not a graphic string
432
-     * @return \ASN1\Type\Primitive\GraphicString
433
-     */
434
-    public function asGraphicString(): Primitive\GraphicString
435
-    {
436
-        if (!$this->_element instanceof Primitive\GraphicString) {
437
-            throw new \UnexpectedValueException(
438
-                $this->_generateExceptionMessage(Element::TYPE_GRAPHIC_STRING));
439
-        }
440
-        return $this->_element;
441
-    }
442
-    
443
-    /**
444
-     * Get the wrapped element as a visible string type.
445
-     *
446
-     * @throws \UnexpectedValueException If the element is not a visible string
447
-     * @return \ASN1\Type\Primitive\VisibleString
448
-     */
449
-    public function asVisibleString(): Primitive\VisibleString
450
-    {
451
-        if (!$this->_element instanceof Primitive\VisibleString) {
452
-            throw new \UnexpectedValueException(
453
-                $this->_generateExceptionMessage(Element::TYPE_VISIBLE_STRING));
454
-        }
455
-        return $this->_element;
456
-    }
457
-    
458
-    /**
459
-     * Get the wrapped element as a general string type.
460
-     *
461
-     * @throws \UnexpectedValueException If the element is not general string
462
-     * @return \ASN1\Type\Primitive\GeneralString
463
-     */
464
-    public function asGeneralString(): Primitive\GeneralString
465
-    {
466
-        if (!$this->_element instanceof Primitive\GeneralString) {
467
-            throw new \UnexpectedValueException(
468
-                $this->_generateExceptionMessage(Element::TYPE_GENERAL_STRING));
469
-        }
470
-        return $this->_element;
471
-    }
472
-    
473
-    /**
474
-     * Get the wrapped element as a universal string type.
475
-     *
476
-     * @throws \UnexpectedValueException If the element is not a universal
477
-     *         string
478
-     * @return \ASN1\Type\Primitive\UniversalString
479
-     */
480
-    public function asUniversalString(): Primitive\UniversalString
481
-    {
482
-        if (!$this->_element instanceof Primitive\UniversalString) {
483
-            throw new \UnexpectedValueException(
484
-                $this->_generateExceptionMessage(Element::TYPE_UNIVERSAL_STRING));
485
-        }
486
-        return $this->_element;
487
-    }
488
-    
489
-    /**
490
-     * Get the wrapped element as a character string type.
491
-     *
492
-     * @throws \UnexpectedValueException If the element is not a character
493
-     *         string
494
-     * @return \ASN1\Type\Primitive\CharacterString
495
-     */
496
-    public function asCharacterString(): Primitive\CharacterString
497
-    {
498
-        if (!$this->_element instanceof Primitive\CharacterString) {
499
-            throw new \UnexpectedValueException(
500
-                $this->_generateExceptionMessage(Element::TYPE_CHARACTER_STRING));
501
-        }
502
-        return $this->_element;
503
-    }
504
-    
505
-    /**
506
-     * Get the wrapped element as a BMP string type.
507
-     *
508
-     * @throws \UnexpectedValueException If the element is not a bmp string
509
-     * @return \ASN1\Type\Primitive\BMPString
510
-     */
511
-    public function asBMPString(): Primitive\BMPString
512
-    {
513
-        if (!$this->_element instanceof Primitive\BMPString) {
514
-            throw new \UnexpectedValueException(
515
-                $this->_generateExceptionMessage(Element::TYPE_BMP_STRING));
516
-        }
517
-        return $this->_element;
518
-    }
519
-    
520
-    /**
521
-     * Get the wrapped element as any string type.
522
-     *
523
-     * @throws \UnexpectedValueException If the element is not a string
524
-     * @return StringType
525
-     */
526
-    public function asString(): StringType
527
-    {
528
-        if (!$this->_element instanceof StringType) {
529
-            throw new \UnexpectedValueException(
530
-                $this->_generateExceptionMessage(Element::TYPE_STRING));
531
-        }
532
-        return $this->_element;
533
-    }
534
-    
535
-    /**
536
-     * Get the wrapped element as any time type.
537
-     *
538
-     * @throws \UnexpectedValueException If the element is not a time
539
-     * @return TimeType
540
-     */
541
-    public function asTime(): TimeType
542
-    {
543
-        if (!$this->_element instanceof TimeType) {
544
-            throw new \UnexpectedValueException(
545
-                $this->_generateExceptionMessage(Element::TYPE_TIME));
546
-        }
547
-        return $this->_element;
548
-    }
549
-    
550
-    /**
551
-     * Generate message for exceptions thrown by <code>as*</code> methods.
552
-     *
553
-     * @param int $tag Type tag of the expected element
554
-     * @return string
555
-     */
556
-    private function _generateExceptionMessage(int $tag): string
557
-    {
558
-        return sprintf("%s expected, got %s.", Element::tagToName($tag),
559
-            $this->_typeDescriptorString());
560
-    }
561
-    
562
-    /**
563
-     * Get textual description of the wrapped element for debugging purposes.
564
-     *
565
-     * @return string
566
-     */
567
-    private function _typeDescriptorString(): string
568
-    {
569
-        $type_cls = $this->_element->typeClass();
570
-        $tag = $this->_element->tag();
571
-        if ($type_cls == Identifier::CLASS_UNIVERSAL) {
572
-            return Element::tagToName($tag);
573
-        }
574
-        return Identifier::classToName($type_cls) . " TAG $tag";
575
-    }
576
-    
577
-    /**
578
-     *
579
-     * @see \ASN1\Feature\Encodable::toDER()
580
-     * @return string
581
-     */
582
-    public function toDER(): string
583
-    {
584
-        return $this->_element->toDER();
585
-    }
586
-    
587
-    /**
588
-     *
589
-     * @see \ASN1\Feature\ElementBase::typeClass()
590
-     * @return int
591
-     */
592
-    public function typeClass(): int
593
-    {
594
-        return $this->_element->typeClass();
595
-    }
596
-    
597
-    /**
598
-     *
599
-     * @see \ASN1\Feature\ElementBase::isConstructed()
600
-     * @return bool
601
-     */
602
-    public function isConstructed(): bool
603
-    {
604
-        return $this->_element->isConstructed();
605
-    }
606
-    
607
-    /**
608
-     *
609
-     * @see \ASN1\Feature\ElementBase::tag()
610
-     * @return int
611
-     */
612
-    public function tag(): int
613
-    {
614
-        return $this->_element->tag();
615
-    }
616
-    
617
-    /**
618
-     *
619
-     * {@inheritdoc}
620
-     * @see \ASN1\Feature\ElementBase::isType()
621
-     * @return bool
622
-     */
623
-    public function isType(int $tag): bool
624
-    {
625
-        return $this->_element->isType($tag);
626
-    }
627
-    
628
-    /**
629
-     *
630
-     * @deprecated Use any <code>as*</code> accessor method first to ensure
631
-     *             type strictness.
632
-     * @see \ASN1\Feature\ElementBase::expectType()
633
-     * @return ElementBase
634
-     */
635
-    public function expectType(int $tag): ElementBase
636
-    {
637
-        return $this->_element->expectType($tag);
638
-    }
639
-    
640
-    /**
641
-     *
642
-     * @see \ASN1\Feature\ElementBase::isTagged()
643
-     * @return bool
644
-     */
645
-    public function isTagged(): bool
646
-    {
647
-        return $this->_element->isTagged();
648
-    }
649
-    
650
-    /**
651
-     *
652
-     * @deprecated Use any <code>as*</code> accessor method first to ensure
653
-     *             type strictness.
654
-     * @see \ASN1\Feature\ElementBase::expectTagged()
655
-     * @return TaggedType
656
-     */
657
-    public function expectTagged($tag = null): TaggedType
658
-    {
659
-        return $this->_element->expectTagged($tag);
660
-    }
661
-    
662
-    /**
663
-     *
664
-     * @see \ASN1\Feature\ElementBase::asElement()
665
-     * @return Element
666
-     */
667
-    public function asElement(): Element
668
-    {
669
-        return $this->_element;
670
-    }
671
-    
672
-    /**
673
-     *
674
-     * {@inheritdoc}
675
-     * @return UnspecifiedType
676
-     */
677
-    public function asUnspecified(): UnspecifiedType
678
-    {
679
-        return $this;
680
-    }
20
+	/**
21
+	 * The wrapped element.
22
+	 *
23
+	 * @var Element
24
+	 */
25
+	private $_element;
26
+    
27
+	/**
28
+	 * Constructor.
29
+	 *
30
+	 * @param Element $el
31
+	 */
32
+	public function __construct(Element $el)
33
+	{
34
+		$this->_element = $el;
35
+	}
36
+    
37
+	/**
38
+	 * Initialize from DER data.
39
+	 *
40
+	 * @param string $data DER encoded data
41
+	 * @return self
42
+	 */
43
+	public static function fromDER(string $data): self
44
+	{
45
+		return Element::fromDER($data)->asUnspecified();
46
+	}
47
+    
48
+	/**
49
+	 * Initialize from ElementBase interface.
50
+	 *
51
+	 * @param ElementBase $el
52
+	 * @return self
53
+	 */
54
+	public static function fromElementBase(ElementBase $el): self
55
+	{
56
+		// if element is already wrapped
57
+		if ($el instanceof self) {
58
+			return $el;
59
+		}
60
+		return new self($el->asElement());
61
+	}
62
+    
63
+	/**
64
+	 * Compatibility method to dispatch calls to the wrapped element.
65
+	 *
66
+	 * @deprecated Use <code>as*</code> accessor methods to ensure strict type
67
+	 * @param string $mtd Method name
68
+	 * @param array $args Arguments
69
+	 * @return mixed
70
+	 */
71
+	public function __call($mtd, array $args)
72
+	{
73
+		return call_user_func_array([$this->_element, $mtd], $args);
74
+	}
75
+    
76
+	/**
77
+	 * Get the wrapped element as a context specific tagged type.
78
+	 *
79
+	 * @throws \UnexpectedValueException If the element is not tagged
80
+	 * @return TaggedType
81
+	 */
82
+	public function asTagged(): TaggedType
83
+	{
84
+		if (!$this->_element instanceof TaggedType) {
85
+			throw new \UnexpectedValueException(
86
+				"Tagged element expected, got " . $this->_typeDescriptorString());
87
+		}
88
+		return $this->_element;
89
+	}
90
+    
91
+	/**
92
+	 * Get the wrapped element as an application specific type.
93
+	 *
94
+	 * @throws \UnexpectedValueException If element is not application specific
95
+	 * @return \ASN1\Type\Tagged\ApplicationType
96
+	 */
97
+	public function asApplication(): Tagged\ApplicationType
98
+	{
99
+		if (!$this->_element instanceof Tagged\ApplicationType) {
100
+			throw new \UnexpectedValueException(
101
+				"Application type expected, got " .
102
+					 $this->_typeDescriptorString());
103
+		}
104
+		return $this->_element;
105
+	}
106
+    
107
+	/**
108
+	 * Get the wrapped element as a private tagged type.
109
+	 *
110
+	 * @throws \UnexpectedValueException If element is not using private tagging
111
+	 * @return \ASN1\Type\Tagged\PrivateType
112
+	 */
113
+	public function asPrivate(): Tagged\PrivateType
114
+	{
115
+		if (!$this->_element instanceof Tagged\PrivateType) {
116
+			throw new \UnexpectedValueException(
117
+				"Private type expected, got " . $this->_typeDescriptorString());
118
+		}
119
+		return $this->_element;
120
+	}
121
+    
122
+	/**
123
+	 * Get the wrapped element as a boolean type.
124
+	 *
125
+	 * @throws \UnexpectedValueException If the element is not a boolean
126
+	 * @return \ASN1\Type\Primitive\Boolean
127
+	 */
128
+	public function asBoolean(): Primitive\Boolean
129
+	{
130
+		if (!$this->_element instanceof Primitive\Boolean) {
131
+			throw new \UnexpectedValueException(
132
+				$this->_generateExceptionMessage(Element::TYPE_BOOLEAN));
133
+		}
134
+		return $this->_element;
135
+	}
136
+    
137
+	/**
138
+	 * Get the wrapped element as an integer type.
139
+	 *
140
+	 * @throws \UnexpectedValueException If the element is not an integer
141
+	 * @return \ASN1\Type\Primitive\Integer
142
+	 */
143
+	public function asInteger(): Primitive\Integer
144
+	{
145
+		if (!$this->_element instanceof Primitive\Integer) {
146
+			throw new \UnexpectedValueException(
147
+				$this->_generateExceptionMessage(Element::TYPE_INTEGER));
148
+		}
149
+		return $this->_element;
150
+	}
151
+    
152
+	/**
153
+	 * Get the wrapped element as a bit string type.
154
+	 *
155
+	 * @throws \UnexpectedValueException If the element is not a bit string
156
+	 * @return \ASN1\Type\Primitive\BitString
157
+	 */
158
+	public function asBitString(): Primitive\BitString
159
+	{
160
+		if (!$this->_element instanceof Primitive\BitString) {
161
+			throw new \UnexpectedValueException(
162
+				$this->_generateExceptionMessage(Element::TYPE_BIT_STRING));
163
+		}
164
+		return $this->_element;
165
+	}
166
+    
167
+	/**
168
+	 * Get the wrapped element as an octet string type.
169
+	 *
170
+	 * @throws \UnexpectedValueException If the element is not an octet string
171
+	 * @return \ASN1\Type\Primitive\OctetString
172
+	 */
173
+	public function asOctetString(): Primitive\OctetString
174
+	{
175
+		if (!$this->_element instanceof Primitive\OctetString) {
176
+			throw new \UnexpectedValueException(
177
+				$this->_generateExceptionMessage(Element::TYPE_OCTET_STRING));
178
+		}
179
+		return $this->_element;
180
+	}
181
+    
182
+	/**
183
+	 * Get the wrapped element as a null type.
184
+	 *
185
+	 * @throws \UnexpectedValueException If the element is not a null
186
+	 * @return \ASN1\Type\Primitive\NullType
187
+	 */
188
+	public function asNull(): Primitive\NullType
189
+	{
190
+		if (!$this->_element instanceof Primitive\NullType) {
191
+			throw new \UnexpectedValueException(
192
+				$this->_generateExceptionMessage(Element::TYPE_NULL));
193
+		}
194
+		return $this->_element;
195
+	}
196
+    
197
+	/**
198
+	 * Get the wrapped element as an object identifier type.
199
+	 *
200
+	 * @throws \UnexpectedValueException If the element is not an object
201
+	 *         identifier
202
+	 * @return \ASN1\Type\Primitive\ObjectIdentifier
203
+	 */
204
+	public function asObjectIdentifier(): Primitive\ObjectIdentifier
205
+	{
206
+		if (!$this->_element instanceof Primitive\ObjectIdentifier) {
207
+			throw new \UnexpectedValueException(
208
+				$this->_generateExceptionMessage(
209
+					Element::TYPE_OBJECT_IDENTIFIER));
210
+		}
211
+		return $this->_element;
212
+	}
213
+    
214
+	/**
215
+	 * Get the wrapped element as an object descriptor type.
216
+	 *
217
+	 * @throws \UnexpectedValueException If the element is not an object
218
+	 *         descriptor
219
+	 * @return \ASN1\Type\Primitive\ObjectDescriptor
220
+	 */
221
+	public function asObjectDescriptor(): Primitive\ObjectDescriptor
222
+	{
223
+		if (!$this->_element instanceof Primitive\ObjectDescriptor) {
224
+			throw new \UnexpectedValueException(
225
+				$this->_generateExceptionMessage(
226
+					Element::TYPE_OBJECT_DESCRIPTOR));
227
+		}
228
+		return $this->_element;
229
+	}
230
+    
231
+	/**
232
+	 * Get the wrapped element as a real type.
233
+	 *
234
+	 * @throws \UnexpectedValueException If the element is not a real
235
+	 * @return \ASN1\Type\Primitive\Real
236
+	 */
237
+	public function asReal(): Primitive\Real
238
+	{
239
+		if (!$this->_element instanceof Primitive\Real) {
240
+			throw new \UnexpectedValueException(
241
+				$this->_generateExceptionMessage(Element::TYPE_REAL));
242
+		}
243
+		return $this->_element;
244
+	}
245
+    
246
+	/**
247
+	 * Get the wrapped element as an enumerated type.
248
+	 *
249
+	 * @throws \UnexpectedValueException If the element is not an enumerated
250
+	 * @return \ASN1\Type\Primitive\Enumerated
251
+	 */
252
+	public function asEnumerated(): Primitive\Enumerated
253
+	{
254
+		if (!$this->_element instanceof Primitive\Enumerated) {
255
+			throw new \UnexpectedValueException(
256
+				$this->_generateExceptionMessage(Element::TYPE_ENUMERATED));
257
+		}
258
+		return $this->_element;
259
+	}
260
+    
261
+	/**
262
+	 * Get the wrapped element as a UTF8 string type.
263
+	 *
264
+	 * @throws \UnexpectedValueException If the element is not a UTF8 string
265
+	 * @return \ASN1\Type\Primitive\UTF8String
266
+	 */
267
+	public function asUTF8String(): Primitive\UTF8String
268
+	{
269
+		if (!$this->_element instanceof Primitive\UTF8String) {
270
+			throw new \UnexpectedValueException(
271
+				$this->_generateExceptionMessage(Element::TYPE_UTF8_STRING));
272
+		}
273
+		return $this->_element;
274
+	}
275
+    
276
+	/**
277
+	 * Get the wrapped element as a relative OID type.
278
+	 *
279
+	 * @throws \UnexpectedValueException If the element is not a relative OID
280
+	 * @return \ASN1\Type\Primitive\RelativeOID
281
+	 */
282
+	public function asRelativeOID(): Primitive\RelativeOID
283
+	{
284
+		if (!$this->_element instanceof Primitive\RelativeOID) {
285
+			throw new \UnexpectedValueException(
286
+				$this->_generateExceptionMessage(Element::TYPE_RELATIVE_OID));
287
+		}
288
+		return $this->_element;
289
+	}
290
+    
291
+	/**
292
+	 * Get the wrapped element as a sequence type.
293
+	 *
294
+	 * @throws \UnexpectedValueException If the element is not a sequence
295
+	 * @return \ASN1\Type\Constructed\Sequence
296
+	 */
297
+	public function asSequence(): Constructed\Sequence
298
+	{
299
+		if (!$this->_element instanceof Constructed\Sequence) {
300
+			throw new \UnexpectedValueException(
301
+				$this->_generateExceptionMessage(Element::TYPE_SEQUENCE));
302
+		}
303
+		return $this->_element;
304
+	}
305
+    
306
+	/**
307
+	 * Get the wrapped element as a set type.
308
+	 *
309
+	 * @throws \UnexpectedValueException If the element is not a set
310
+	 * @return \ASN1\Type\Constructed\Set
311
+	 */
312
+	public function asSet(): Constructed\Set
313
+	{
314
+		if (!$this->_element instanceof Constructed\Set) {
315
+			throw new \UnexpectedValueException(
316
+				$this->_generateExceptionMessage(Element::TYPE_SET));
317
+		}
318
+		return $this->_element;
319
+	}
320
+    
321
+	/**
322
+	 * Get the wrapped element as a numeric string type.
323
+	 *
324
+	 * @throws \UnexpectedValueException If the element is not a numeric string
325
+	 * @return \ASN1\Type\Primitive\NumericString
326
+	 */
327
+	public function asNumericString(): Primitive\NumericString
328
+	{
329
+		if (!$this->_element instanceof Primitive\NumericString) {
330
+			throw new \UnexpectedValueException(
331
+				$this->_generateExceptionMessage(Element::TYPE_NUMERIC_STRING));
332
+		}
333
+		return $this->_element;
334
+	}
335
+    
336
+	/**
337
+	 * Get the wrapped element as a printable string type.
338
+	 *
339
+	 * @throws \UnexpectedValueException If the element is not a printable
340
+	 *         string
341
+	 * @return \ASN1\Type\Primitive\PrintableString
342
+	 */
343
+	public function asPrintableString(): Primitive\PrintableString
344
+	{
345
+		if (!$this->_element instanceof Primitive\PrintableString) {
346
+			throw new \UnexpectedValueException(
347
+				$this->_generateExceptionMessage(Element::TYPE_PRINTABLE_STRING));
348
+		}
349
+		return $this->_element;
350
+	}
351
+    
352
+	/**
353
+	 * Get the wrapped element as a T61 string type.
354
+	 *
355
+	 * @throws \UnexpectedValueException If the element is not a T61 string
356
+	 * @return \ASN1\Type\Primitive\T61String
357
+	 */
358
+	public function asT61String(): Primitive\T61String
359
+	{
360
+		if (!$this->_element instanceof Primitive\T61String) {
361
+			throw new \UnexpectedValueException(
362
+				$this->_generateExceptionMessage(Element::TYPE_T61_STRING));
363
+		}
364
+		return $this->_element;
365
+	}
366
+    
367
+	/**
368
+	 * Get the wrapped element as a videotex string type.
369
+	 *
370
+	 * @throws \UnexpectedValueException If the element is not a videotex string
371
+	 * @return \ASN1\Type\Primitive\VideotexString
372
+	 */
373
+	public function asVideotexString(): Primitive\VideotexString
374
+	{
375
+		if (!$this->_element instanceof Primitive\VideotexString) {
376
+			throw new \UnexpectedValueException(
377
+				$this->_generateExceptionMessage(Element::TYPE_VIDEOTEX_STRING));
378
+		}
379
+		return $this->_element;
380
+	}
381
+    
382
+	/**
383
+	 * Get the wrapped element as a IA5 string type.
384
+	 *
385
+	 * @throws \UnexpectedValueException If the element is not a IA5 string
386
+	 * @return \ASN1\Type\Primitive\IA5String
387
+	 */
388
+	public function asIA5String(): Primitive\IA5String
389
+	{
390
+		if (!$this->_element instanceof Primitive\IA5String) {
391
+			throw new \UnexpectedValueException(
392
+				$this->_generateExceptionMessage(Element::TYPE_IA5_STRING));
393
+		}
394
+		return $this->_element;
395
+	}
396
+    
397
+	/**
398
+	 * Get the wrapped element as an UTC time type.
399
+	 *
400
+	 * @throws \UnexpectedValueException If the element is not a UTC time
401
+	 * @return \ASN1\Type\Primitive\UTCTime
402
+	 */
403
+	public function asUTCTime(): Primitive\UTCTime
404
+	{
405
+		if (!$this->_element instanceof Primitive\UTCTime) {
406
+			throw new \UnexpectedValueException(
407
+				$this->_generateExceptionMessage(Element::TYPE_UTC_TIME));
408
+		}
409
+		return $this->_element;
410
+	}
411
+    
412
+	/**
413
+	 * Get the wrapped element as a generalized time type.
414
+	 *
415
+	 * @throws \UnexpectedValueException If the element is not a generalized
416
+	 *         time
417
+	 * @return \ASN1\Type\Primitive\GeneralizedTime
418
+	 */
419
+	public function asGeneralizedTime(): Primitive\GeneralizedTime
420
+	{
421
+		if (!$this->_element instanceof Primitive\GeneralizedTime) {
422
+			throw new \UnexpectedValueException(
423
+				$this->_generateExceptionMessage(Element::TYPE_GENERALIZED_TIME));
424
+		}
425
+		return $this->_element;
426
+	}
427
+    
428
+	/**
429
+	 * Get the wrapped element as a graphic string type.
430
+	 *
431
+	 * @throws \UnexpectedValueException If the element is not a graphic string
432
+	 * @return \ASN1\Type\Primitive\GraphicString
433
+	 */
434
+	public function asGraphicString(): Primitive\GraphicString
435
+	{
436
+		if (!$this->_element instanceof Primitive\GraphicString) {
437
+			throw new \UnexpectedValueException(
438
+				$this->_generateExceptionMessage(Element::TYPE_GRAPHIC_STRING));
439
+		}
440
+		return $this->_element;
441
+	}
442
+    
443
+	/**
444
+	 * Get the wrapped element as a visible string type.
445
+	 *
446
+	 * @throws \UnexpectedValueException If the element is not a visible string
447
+	 * @return \ASN1\Type\Primitive\VisibleString
448
+	 */
449
+	public function asVisibleString(): Primitive\VisibleString
450
+	{
451
+		if (!$this->_element instanceof Primitive\VisibleString) {
452
+			throw new \UnexpectedValueException(
453
+				$this->_generateExceptionMessage(Element::TYPE_VISIBLE_STRING));
454
+		}
455
+		return $this->_element;
456
+	}
457
+    
458
+	/**
459
+	 * Get the wrapped element as a general string type.
460
+	 *
461
+	 * @throws \UnexpectedValueException If the element is not general string
462
+	 * @return \ASN1\Type\Primitive\GeneralString
463
+	 */
464
+	public function asGeneralString(): Primitive\GeneralString
465
+	{
466
+		if (!$this->_element instanceof Primitive\GeneralString) {
467
+			throw new \UnexpectedValueException(
468
+				$this->_generateExceptionMessage(Element::TYPE_GENERAL_STRING));
469
+		}
470
+		return $this->_element;
471
+	}
472
+    
473
+	/**
474
+	 * Get the wrapped element as a universal string type.
475
+	 *
476
+	 * @throws \UnexpectedValueException If the element is not a universal
477
+	 *         string
478
+	 * @return \ASN1\Type\Primitive\UniversalString
479
+	 */
480
+	public function asUniversalString(): Primitive\UniversalString
481
+	{
482
+		if (!$this->_element instanceof Primitive\UniversalString) {
483
+			throw new \UnexpectedValueException(
484
+				$this->_generateExceptionMessage(Element::TYPE_UNIVERSAL_STRING));
485
+		}
486
+		return $this->_element;
487
+	}
488
+    
489
+	/**
490
+	 * Get the wrapped element as a character string type.
491
+	 *
492
+	 * @throws \UnexpectedValueException If the element is not a character
493
+	 *         string
494
+	 * @return \ASN1\Type\Primitive\CharacterString
495
+	 */
496
+	public function asCharacterString(): Primitive\CharacterString
497
+	{
498
+		if (!$this->_element instanceof Primitive\CharacterString) {
499
+			throw new \UnexpectedValueException(
500
+				$this->_generateExceptionMessage(Element::TYPE_CHARACTER_STRING));
501
+		}
502
+		return $this->_element;
503
+	}
504
+    
505
+	/**
506
+	 * Get the wrapped element as a BMP string type.
507
+	 *
508
+	 * @throws \UnexpectedValueException If the element is not a bmp string
509
+	 * @return \ASN1\Type\Primitive\BMPString
510
+	 */
511
+	public function asBMPString(): Primitive\BMPString
512
+	{
513
+		if (!$this->_element instanceof Primitive\BMPString) {
514
+			throw new \UnexpectedValueException(
515
+				$this->_generateExceptionMessage(Element::TYPE_BMP_STRING));
516
+		}
517
+		return $this->_element;
518
+	}
519
+    
520
+	/**
521
+	 * Get the wrapped element as any string type.
522
+	 *
523
+	 * @throws \UnexpectedValueException If the element is not a string
524
+	 * @return StringType
525
+	 */
526
+	public function asString(): StringType
527
+	{
528
+		if (!$this->_element instanceof StringType) {
529
+			throw new \UnexpectedValueException(
530
+				$this->_generateExceptionMessage(Element::TYPE_STRING));
531
+		}
532
+		return $this->_element;
533
+	}
534
+    
535
+	/**
536
+	 * Get the wrapped element as any time type.
537
+	 *
538
+	 * @throws \UnexpectedValueException If the element is not a time
539
+	 * @return TimeType
540
+	 */
541
+	public function asTime(): TimeType
542
+	{
543
+		if (!$this->_element instanceof TimeType) {
544
+			throw new \UnexpectedValueException(
545
+				$this->_generateExceptionMessage(Element::TYPE_TIME));
546
+		}
547
+		return $this->_element;
548
+	}
549
+    
550
+	/**
551
+	 * Generate message for exceptions thrown by <code>as*</code> methods.
552
+	 *
553
+	 * @param int $tag Type tag of the expected element
554
+	 * @return string
555
+	 */
556
+	private function _generateExceptionMessage(int $tag): string
557
+	{
558
+		return sprintf("%s expected, got %s.", Element::tagToName($tag),
559
+			$this->_typeDescriptorString());
560
+	}
561
+    
562
+	/**
563
+	 * Get textual description of the wrapped element for debugging purposes.
564
+	 *
565
+	 * @return string
566
+	 */
567
+	private function _typeDescriptorString(): string
568
+	{
569
+		$type_cls = $this->_element->typeClass();
570
+		$tag = $this->_element->tag();
571
+		if ($type_cls == Identifier::CLASS_UNIVERSAL) {
572
+			return Element::tagToName($tag);
573
+		}
574
+		return Identifier::classToName($type_cls) . " TAG $tag";
575
+	}
576
+    
577
+	/**
578
+	 *
579
+	 * @see \ASN1\Feature\Encodable::toDER()
580
+	 * @return string
581
+	 */
582
+	public function toDER(): string
583
+	{
584
+		return $this->_element->toDER();
585
+	}
586
+    
587
+	/**
588
+	 *
589
+	 * @see \ASN1\Feature\ElementBase::typeClass()
590
+	 * @return int
591
+	 */
592
+	public function typeClass(): int
593
+	{
594
+		return $this->_element->typeClass();
595
+	}
596
+    
597
+	/**
598
+	 *
599
+	 * @see \ASN1\Feature\ElementBase::isConstructed()
600
+	 * @return bool
601
+	 */
602
+	public function isConstructed(): bool
603
+	{
604
+		return $this->_element->isConstructed();
605
+	}
606
+    
607
+	/**
608
+	 *
609
+	 * @see \ASN1\Feature\ElementBase::tag()
610
+	 * @return int
611
+	 */
612
+	public function tag(): int
613
+	{
614
+		return $this->_element->tag();
615
+	}
616
+    
617
+	/**
618
+	 *
619
+	 * {@inheritdoc}
620
+	 * @see \ASN1\Feature\ElementBase::isType()
621
+	 * @return bool
622
+	 */
623
+	public function isType(int $tag): bool
624
+	{
625
+		return $this->_element->isType($tag);
626
+	}
627
+    
628
+	/**
629
+	 *
630
+	 * @deprecated Use any <code>as*</code> accessor method first to ensure
631
+	 *             type strictness.
632
+	 * @see \ASN1\Feature\ElementBase::expectType()
633
+	 * @return ElementBase
634
+	 */
635
+	public function expectType(int $tag): ElementBase
636
+	{
637
+		return $this->_element->expectType($tag);
638
+	}
639
+    
640
+	/**
641
+	 *
642
+	 * @see \ASN1\Feature\ElementBase::isTagged()
643
+	 * @return bool
644
+	 */
645
+	public function isTagged(): bool
646
+	{
647
+		return $this->_element->isTagged();
648
+	}
649
+    
650
+	/**
651
+	 *
652
+	 * @deprecated Use any <code>as*</code> accessor method first to ensure
653
+	 *             type strictness.
654
+	 * @see \ASN1\Feature\ElementBase::expectTagged()
655
+	 * @return TaggedType
656
+	 */
657
+	public function expectTagged($tag = null): TaggedType
658
+	{
659
+		return $this->_element->expectTagged($tag);
660
+	}
661
+    
662
+	/**
663
+	 *
664
+	 * @see \ASN1\Feature\ElementBase::asElement()
665
+	 * @return Element
666
+	 */
667
+	public function asElement(): Element
668
+	{
669
+		return $this->_element;
670
+	}
671
+    
672
+	/**
673
+	 *
674
+	 * {@inheritdoc}
675
+	 * @return UnspecifiedType
676
+	 */
677
+	public function asUnspecified(): UnspecifiedType
678
+	{
679
+		return $this;
680
+	}
681 681
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace ASN1\Type;
6 6
 
Please login to merge, or discard this patch.
lib/ASN1/Type/PrimitiveType.php 2 patches
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -9,13 +9,13 @@
 block discarded – undo
9 9
  */
10 10
 trait PrimitiveType
11 11
 {
12
-    /**
13
-     *
14
-     * @see \ASN1\Element::isConstructed()
15
-     * @return bool
16
-     */
17
-    public function isConstructed(): bool
18
-    {
19
-        return false;
20
-    }
12
+	/**
13
+	 *
14
+	 * @see \ASN1\Element::isConstructed()
15
+	 * @return bool
16
+	 */
17
+	public function isConstructed(): bool
18
+	{
19
+		return false;
20
+	}
21 21
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace ASN1\Type;
6 6
 
Please login to merge, or discard this patch.
lib/ASN1/Type/PrimitiveString.php 2 patches
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -14,41 +14,41 @@
 block discarded – undo
14 14
  */
15 15
 abstract class PrimitiveString extends StringType
16 16
 {
17
-    use PrimitiveType;
17
+	use PrimitiveType;
18 18
     
19
-    /**
20
-     *
21
-     * @see \ASN1\Element::_encodedContentDER()
22
-     * @return string
23
-     */
24
-    protected function _encodedContentDER(): string
25
-    {
26
-        return $this->_string;
27
-    }
19
+	/**
20
+	 *
21
+	 * @see \ASN1\Element::_encodedContentDER()
22
+	 * @return string
23
+	 */
24
+	protected function _encodedContentDER(): string
25
+	{
26
+		return $this->_string;
27
+	}
28 28
     
29
-    /**
30
-     *
31
-     * {@inheritdoc}
32
-     * @see \ASN1\Element::_decodeFromDER()
33
-     * @return self
34
-     */
35
-    protected static function _decodeFromDER(Identifier $identifier, string $data,
36
-        int &$offset): ElementBase
37
-    {
38
-        $idx = $offset;
39
-        if (!$identifier->isPrimitive()) {
40
-            throw new DecodeException("DER encoded string must be primitive.");
41
-        }
42
-        $length = Length::expectFromDER($data, $idx)->intLength();
43
-        $str = $length ? substr($data, $idx, $length) : "";
44
-        // substr should never return false, since length is
45
-        // checked by Length::expectFromDER.
46
-        assert(is_string($str), new DecodeException("substr"));
47
-        $offset = $idx + $length;
48
-        try {
49
-            return new static($str);
50
-        } catch (\InvalidArgumentException $e) {
51
-            throw new DecodeException($e->getMessage(), 0, $e);
52
-        }
53
-    }
29
+	/**
30
+	 *
31
+	 * {@inheritdoc}
32
+	 * @see \ASN1\Element::_decodeFromDER()
33
+	 * @return self
34
+	 */
35
+	protected static function _decodeFromDER(Identifier $identifier, string $data,
36
+		int &$offset): ElementBase
37
+	{
38
+		$idx = $offset;
39
+		if (!$identifier->isPrimitive()) {
40
+			throw new DecodeException("DER encoded string must be primitive.");
41
+		}
42
+		$length = Length::expectFromDER($data, $idx)->intLength();
43
+		$str = $length ? substr($data, $idx, $length) : "";
44
+		// substr should never return false, since length is
45
+		// checked by Length::expectFromDER.
46
+		assert(is_string($str), new DecodeException("substr"));
47
+		$offset = $idx + $length;
48
+		try {
49
+			return new static($str);
50
+		} catch (\InvalidArgumentException $e) {
51
+			throw new DecodeException($e->getMessage(), 0, $e);
52
+		}
53
+	}
54 54
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace ASN1\Type;
6 6
 
Please login to merge, or discard this patch.
lib/ASN1/Type/Constructed/Sequence.php 2 patches
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -12,14 +12,14 @@
 block discarded – undo
12 12
  */
13 13
 class Sequence extends Structure
14 14
 {
15
-    /**
16
-     * Constructor.
17
-     *
18
-     * @param Element ...$elements Any number of elements
19
-     */
20
-    public function __construct(Element ...$elements)
21
-    {
22
-        $this->_typeTag = self::TYPE_SEQUENCE;
23
-        parent::__construct(...$elements);
24
-    }
15
+	/**
16
+	 * Constructor.
17
+	 *
18
+	 * @param Element ...$elements Any number of elements
19
+	 */
20
+	public function __construct(Element ...$elements)
21
+	{
22
+		$this->_typeTag = self::TYPE_SEQUENCE;
23
+		parent::__construct(...$elements);
24
+	}
25 25
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace ASN1\Type\Constructed;
6 6
 
Please login to merge, or discard this patch.
lib/ASN1/Type/Constructed/Set.php 2 patches
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -12,54 +12,54 @@
 block discarded – undo
12 12
  */
13 13
 class Set extends Structure
14 14
 {
15
-    /**
16
-     * Constructor.
17
-     *
18
-     * @param Element ...$elements Any number of elements
19
-     */
20
-    public function __construct(Element ...$elements)
21
-    {
22
-        $this->_typeTag = self::TYPE_SET;
23
-        parent::__construct(...$elements);
24
-    }
15
+	/**
16
+	 * Constructor.
17
+	 *
18
+	 * @param Element ...$elements Any number of elements
19
+	 */
20
+	public function __construct(Element ...$elements)
21
+	{
22
+		$this->_typeTag = self::TYPE_SET;
23
+		parent::__construct(...$elements);
24
+	}
25 25
     
26
-    /**
27
-     * Sort by canonical ascending order.
28
-     * Used for DER encoding of SET type.
29
-     *
30
-     * @return self
31
-     */
32
-    public function sortedSet(): self
33
-    {
34
-        $obj = clone $this;
35
-        usort($obj->_elements,
36
-            function (Element $a, Element $b) {
37
-                if ($a->typeClass() != $b->typeClass()) {
38
-                    return $a->typeClass() < $b->typeClass() ? -1 : 1;
39
-                }
40
-                if ($a->tag() == $b->tag()) {
41
-                    return 0;
42
-                }
43
-                return $a->tag() < $b->tag() ? -1 : 1;
44
-            });
45
-        return $obj;
46
-    }
26
+	/**
27
+	 * Sort by canonical ascending order.
28
+	 * Used for DER encoding of SET type.
29
+	 *
30
+	 * @return self
31
+	 */
32
+	public function sortedSet(): self
33
+	{
34
+		$obj = clone $this;
35
+		usort($obj->_elements,
36
+			function (Element $a, Element $b) {
37
+				if ($a->typeClass() != $b->typeClass()) {
38
+					return $a->typeClass() < $b->typeClass() ? -1 : 1;
39
+				}
40
+				if ($a->tag() == $b->tag()) {
41
+					return 0;
42
+				}
43
+				return $a->tag() < $b->tag() ? -1 : 1;
44
+			});
45
+		return $obj;
46
+	}
47 47
     
48
-    /**
49
-     * Sort by encoding ascending order.
50
-     * Used for DER encoding of SET OF type.
51
-     *
52
-     * @return self
53
-     */
54
-    public function sortedSetOf(): self
55
-    {
56
-        $obj = clone $this;
57
-        usort($obj->_elements,
58
-            function (Element $a, Element $b) {
59
-                $a_der = $a->toDER();
60
-                $b_der = $b->toDER();
61
-                return strcmp($a_der, $b_der);
62
-            });
63
-        return $obj;
64
-    }
48
+	/**
49
+	 * Sort by encoding ascending order.
50
+	 * Used for DER encoding of SET OF type.
51
+	 *
52
+	 * @return self
53
+	 */
54
+	public function sortedSetOf(): self
55
+	{
56
+		$obj = clone $this;
57
+		usort($obj->_elements,
58
+			function (Element $a, Element $b) {
59
+				$a_der = $a->toDER();
60
+				$b_der = $b->toDER();
61
+				return strcmp($a_der, $b_der);
62
+			});
63
+		return $obj;
64
+	}
65 65
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace ASN1\Type\Constructed;
6 6
 
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
     {
34 34
         $obj = clone $this;
35 35
         usort($obj->_elements,
36
-            function (Element $a, Element $b) {
36
+            function(Element $a, Element $b) {
37 37
                 if ($a->typeClass() != $b->typeClass()) {
38 38
                     return $a->typeClass() < $b->typeClass() ? -1 : 1;
39 39
                 }
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
     {
56 56
         $obj = clone $this;
57 57
         usort($obj->_elements,
58
-            function (Element $a, Element $b) {
58
+            function(Element $a, Element $b) {
59 59
                 $a_der = $a->toDER();
60 60
                 $b_der = $b->toDER();
61 61
                 return strcmp($a_der, $b_der);
Please login to merge, or discard this patch.
lib/ASN1/Element.php 3 patches
Switch Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -332,10 +332,10 @@  discard block
 block discarded – undo
332 332
     private function _isPseudoType(int $tag): bool
333 333
     {
334 334
         switch ($tag) {
335
-            case self::TYPE_STRING:
336
-                return $this instanceof StringType;
337
-            case self::TYPE_TIME:
338
-                return $this instanceof TimeType;
335
+        case self::TYPE_STRING:
336
+            return $this instanceof StringType;
337
+        case self::TYPE_TIME:
338
+            return $this instanceof TimeType;
339 339
         }
340 340
         return false;
341 341
     }
@@ -398,14 +398,14 @@  discard block
 block discarded – undo
398 398
     protected static function _determineImplClass(Identifier $identifier): string
399 399
     {
400 400
         switch ($identifier->typeClass()) {
401
-            case Identifier::CLASS_UNIVERSAL:
402
-                return self::_determineUniversalImplClass($identifier->intTag());
403
-            case Identifier::CLASS_CONTEXT_SPECIFIC:
404
-                return TaggedType::class;
405
-            case Identifier::CLASS_APPLICATION:
406
-                return ApplicationType::class;
407
-            case Identifier::CLASS_PRIVATE:
408
-                return PrivateType::class;
401
+        case Identifier::CLASS_UNIVERSAL:
402
+            return self::_determineUniversalImplClass($identifier->intTag());
403
+        case Identifier::CLASS_CONTEXT_SPECIFIC:
404
+            return TaggedType::class;
405
+        case Identifier::CLASS_APPLICATION:
406
+            return ApplicationType::class;
407
+        case Identifier::CLASS_PRIVATE:
408
+            return PrivateType::class;
409 409
         }
410 410
         throw new \UnexpectedValueException(
411 411
             sprintf("%s %d not implemented.",
Please login to merge, or discard this patch.
Indentation   +410 added lines, -410 removed lines patch added patch discarded remove patch
@@ -22,438 +22,438 @@
 block discarded – undo
22 22
  */
23 23
 abstract class Element implements ElementBase
24 24
 {
25
-    // Universal type tags
26
-    const TYPE_EOC = 0x00;
27
-    const TYPE_BOOLEAN = 0x01;
28
-    const TYPE_INTEGER = 0x02;
29
-    const TYPE_BIT_STRING = 0x03;
30
-    const TYPE_OCTET_STRING = 0x04;
31
-    const TYPE_NULL = 0x05;
32
-    const TYPE_OBJECT_IDENTIFIER = 0x06;
33
-    const TYPE_OBJECT_DESCRIPTOR = 0x07;
34
-    const TYPE_EXTERNAL = 0x08;
35
-    const TYPE_REAL = 0x09;
36
-    const TYPE_ENUMERATED = 0x0a;
37
-    const TYPE_EMBEDDED_PDV = 0x0b;
38
-    const TYPE_UTF8_STRING = 0x0c;
39
-    const TYPE_RELATIVE_OID = 0x0d;
40
-    const TYPE_SEQUENCE = 0x10;
41
-    const TYPE_SET = 0x11;
42
-    const TYPE_NUMERIC_STRING = 0x12;
43
-    const TYPE_PRINTABLE_STRING = 0x13;
44
-    const TYPE_T61_STRING = 0x14;
45
-    const TYPE_VIDEOTEX_STRING = 0x15;
46
-    const TYPE_IA5_STRING = 0x16;
47
-    const TYPE_UTC_TIME = 0x17;
48
-    const TYPE_GENERALIZED_TIME = 0x18;
49
-    const TYPE_GRAPHIC_STRING = 0x19;
50
-    const TYPE_VISIBLE_STRING = 0x1a;
51
-    const TYPE_GENERAL_STRING = 0x1b;
52
-    const TYPE_UNIVERSAL_STRING = 0x1c;
53
-    const TYPE_CHARACTER_STRING = 0x1d;
54
-    const TYPE_BMP_STRING = 0x1e;
25
+	// Universal type tags
26
+	const TYPE_EOC = 0x00;
27
+	const TYPE_BOOLEAN = 0x01;
28
+	const TYPE_INTEGER = 0x02;
29
+	const TYPE_BIT_STRING = 0x03;
30
+	const TYPE_OCTET_STRING = 0x04;
31
+	const TYPE_NULL = 0x05;
32
+	const TYPE_OBJECT_IDENTIFIER = 0x06;
33
+	const TYPE_OBJECT_DESCRIPTOR = 0x07;
34
+	const TYPE_EXTERNAL = 0x08;
35
+	const TYPE_REAL = 0x09;
36
+	const TYPE_ENUMERATED = 0x0a;
37
+	const TYPE_EMBEDDED_PDV = 0x0b;
38
+	const TYPE_UTF8_STRING = 0x0c;
39
+	const TYPE_RELATIVE_OID = 0x0d;
40
+	const TYPE_SEQUENCE = 0x10;
41
+	const TYPE_SET = 0x11;
42
+	const TYPE_NUMERIC_STRING = 0x12;
43
+	const TYPE_PRINTABLE_STRING = 0x13;
44
+	const TYPE_T61_STRING = 0x14;
45
+	const TYPE_VIDEOTEX_STRING = 0x15;
46
+	const TYPE_IA5_STRING = 0x16;
47
+	const TYPE_UTC_TIME = 0x17;
48
+	const TYPE_GENERALIZED_TIME = 0x18;
49
+	const TYPE_GRAPHIC_STRING = 0x19;
50
+	const TYPE_VISIBLE_STRING = 0x1a;
51
+	const TYPE_GENERAL_STRING = 0x1b;
52
+	const TYPE_UNIVERSAL_STRING = 0x1c;
53
+	const TYPE_CHARACTER_STRING = 0x1d;
54
+	const TYPE_BMP_STRING = 0x1e;
55 55
     
56
-    /**
57
-     * Mapping from universal type tag to implementation class name.
58
-     *
59
-     * @internal
60
-     *
61
-     * @var array
62
-     */
63
-    const MAP_TAG_TO_CLASS = [ /* @formatter:off */
64
-        self::TYPE_BOOLEAN => Primitive\Boolean::class,
65
-        self::TYPE_INTEGER => Primitive\Integer::class,
66
-        self::TYPE_BIT_STRING => Primitive\BitString::class,
67
-        self::TYPE_OCTET_STRING => Primitive\OctetString::class,
68
-        self::TYPE_NULL => Primitive\NullType::class,
69
-        self::TYPE_OBJECT_IDENTIFIER => Primitive\ObjectIdentifier::class,
70
-        self::TYPE_OBJECT_DESCRIPTOR => Primitive\ObjectDescriptor::class,
71
-        self::TYPE_REAL => Primitive\Real::class,
72
-        self::TYPE_ENUMERATED => Primitive\Enumerated::class,
73
-        self::TYPE_UTF8_STRING => Primitive\UTF8String::class,
74
-        self::TYPE_RELATIVE_OID => Primitive\RelativeOID::class,
75
-        self::TYPE_SEQUENCE => Constructed\Sequence::class,
76
-        self::TYPE_SET => Constructed\Set::class,
77
-        self::TYPE_NUMERIC_STRING => Primitive\NumericString::class,
78
-        self::TYPE_PRINTABLE_STRING => Primitive\PrintableString::class,
79
-        self::TYPE_T61_STRING => Primitive\T61String::class,
80
-        self::TYPE_VIDEOTEX_STRING => Primitive\VideotexString::class,
81
-        self::TYPE_IA5_STRING => Primitive\IA5String::class,
82
-        self::TYPE_UTC_TIME => Primitive\UTCTime::class,
83
-        self::TYPE_GENERALIZED_TIME => Primitive\GeneralizedTime::class,
84
-        self::TYPE_GRAPHIC_STRING => Primitive\GraphicString::class,
85
-        self::TYPE_VISIBLE_STRING => Primitive\VisibleString::class,
86
-        self::TYPE_GENERAL_STRING => Primitive\GeneralString::class,
87
-        self::TYPE_UNIVERSAL_STRING => Primitive\UniversalString::class,
88
-        self::TYPE_CHARACTER_STRING => Primitive\CharacterString::class,
89
-        self::TYPE_BMP_STRING => Primitive\BMPString::class
90
-        /* @formatter:on */
91
-    ];
56
+	/**
57
+	 * Mapping from universal type tag to implementation class name.
58
+	 *
59
+	 * @internal
60
+	 *
61
+	 * @var array
62
+	 */
63
+	const MAP_TAG_TO_CLASS = [ /* @formatter:off */
64
+		self::TYPE_BOOLEAN => Primitive\Boolean::class,
65
+		self::TYPE_INTEGER => Primitive\Integer::class,
66
+		self::TYPE_BIT_STRING => Primitive\BitString::class,
67
+		self::TYPE_OCTET_STRING => Primitive\OctetString::class,
68
+		self::TYPE_NULL => Primitive\NullType::class,
69
+		self::TYPE_OBJECT_IDENTIFIER => Primitive\ObjectIdentifier::class,
70
+		self::TYPE_OBJECT_DESCRIPTOR => Primitive\ObjectDescriptor::class,
71
+		self::TYPE_REAL => Primitive\Real::class,
72
+		self::TYPE_ENUMERATED => Primitive\Enumerated::class,
73
+		self::TYPE_UTF8_STRING => Primitive\UTF8String::class,
74
+		self::TYPE_RELATIVE_OID => Primitive\RelativeOID::class,
75
+		self::TYPE_SEQUENCE => Constructed\Sequence::class,
76
+		self::TYPE_SET => Constructed\Set::class,
77
+		self::TYPE_NUMERIC_STRING => Primitive\NumericString::class,
78
+		self::TYPE_PRINTABLE_STRING => Primitive\PrintableString::class,
79
+		self::TYPE_T61_STRING => Primitive\T61String::class,
80
+		self::TYPE_VIDEOTEX_STRING => Primitive\VideotexString::class,
81
+		self::TYPE_IA5_STRING => Primitive\IA5String::class,
82
+		self::TYPE_UTC_TIME => Primitive\UTCTime::class,
83
+		self::TYPE_GENERALIZED_TIME => Primitive\GeneralizedTime::class,
84
+		self::TYPE_GRAPHIC_STRING => Primitive\GraphicString::class,
85
+		self::TYPE_VISIBLE_STRING => Primitive\VisibleString::class,
86
+		self::TYPE_GENERAL_STRING => Primitive\GeneralString::class,
87
+		self::TYPE_UNIVERSAL_STRING => Primitive\UniversalString::class,
88
+		self::TYPE_CHARACTER_STRING => Primitive\CharacterString::class,
89
+		self::TYPE_BMP_STRING => Primitive\BMPString::class
90
+		/* @formatter:on */
91
+	];
92 92
     
93
-    /**
94
-     * Pseudotype for all string types.
95
-     *
96
-     * May be used as an expectation parameter.
97
-     *
98
-     * @var int
99
-     */
100
-    const TYPE_STRING = -1;
93
+	/**
94
+	 * Pseudotype for all string types.
95
+	 *
96
+	 * May be used as an expectation parameter.
97
+	 *
98
+	 * @var int
99
+	 */
100
+	const TYPE_STRING = -1;
101 101
     
102
-    /**
103
-     * Pseudotype for all time types.
104
-     *
105
-     * May be used as an expectation parameter.
106
-     *
107
-     * @var int
108
-     */
109
-    const TYPE_TIME = -2;
102
+	/**
103
+	 * Pseudotype for all time types.
104
+	 *
105
+	 * May be used as an expectation parameter.
106
+	 *
107
+	 * @var int
108
+	 */
109
+	const TYPE_TIME = -2;
110 110
     
111
-    /**
112
-     * Mapping from universal type tag to human readable name.
113
-     *
114
-     * @internal
115
-     *
116
-     * @var array
117
-     */
118
-    const MAP_TYPE_TO_NAME = [ /* @formatter:off */
119
-        self::TYPE_EOC => "EOC",
120
-        self::TYPE_BOOLEAN => "BOOLEAN",
121
-        self::TYPE_INTEGER => "INTEGER",
122
-        self::TYPE_BIT_STRING => "BIT STRING",
123
-        self::TYPE_OCTET_STRING => "OCTET STRING",
124
-        self::TYPE_NULL => "NULL",
125
-        self::TYPE_OBJECT_IDENTIFIER => "OBJECT IDENTIFIER",
126
-        self::TYPE_OBJECT_DESCRIPTOR => "ObjectDescriptor",
127
-        self::TYPE_EXTERNAL => "EXTERNAL",
128
-        self::TYPE_REAL => "REAL",
129
-        self::TYPE_ENUMERATED => "ENUMERATED",
130
-        self::TYPE_EMBEDDED_PDV => "EMBEDDED PDV",
131
-        self::TYPE_UTF8_STRING => "UTF8String",
132
-        self::TYPE_RELATIVE_OID => "RELATIVE-OID",
133
-        self::TYPE_SEQUENCE => "SEQUENCE",
134
-        self::TYPE_SET => "SET",
135
-        self::TYPE_NUMERIC_STRING => "NumericString",
136
-        self::TYPE_PRINTABLE_STRING => "PrintableString",
137
-        self::TYPE_T61_STRING => "T61String",
138
-        self::TYPE_VIDEOTEX_STRING => "VideotexString",
139
-        self::TYPE_IA5_STRING => "IA5String",
140
-        self::TYPE_UTC_TIME => "UTCTime",
141
-        self::TYPE_GENERALIZED_TIME => "GeneralizedTime",
142
-        self::TYPE_GRAPHIC_STRING => "GraphicString",
143
-        self::TYPE_VISIBLE_STRING => "VisibleString",
144
-        self::TYPE_GENERAL_STRING => "GeneralString",
145
-        self::TYPE_UNIVERSAL_STRING => "UniversalString",
146
-        self::TYPE_CHARACTER_STRING => "CHARACTER STRING",
147
-        self::TYPE_BMP_STRING => "BMPString",
148
-        self::TYPE_STRING => "Any String",
149
-        self::TYPE_TIME => "Any Time"
150
-        /* @formatter:on */
151
-    ];
111
+	/**
112
+	 * Mapping from universal type tag to human readable name.
113
+	 *
114
+	 * @internal
115
+	 *
116
+	 * @var array
117
+	 */
118
+	const MAP_TYPE_TO_NAME = [ /* @formatter:off */
119
+		self::TYPE_EOC => "EOC",
120
+		self::TYPE_BOOLEAN => "BOOLEAN",
121
+		self::TYPE_INTEGER => "INTEGER",
122
+		self::TYPE_BIT_STRING => "BIT STRING",
123
+		self::TYPE_OCTET_STRING => "OCTET STRING",
124
+		self::TYPE_NULL => "NULL",
125
+		self::TYPE_OBJECT_IDENTIFIER => "OBJECT IDENTIFIER",
126
+		self::TYPE_OBJECT_DESCRIPTOR => "ObjectDescriptor",
127
+		self::TYPE_EXTERNAL => "EXTERNAL",
128
+		self::TYPE_REAL => "REAL",
129
+		self::TYPE_ENUMERATED => "ENUMERATED",
130
+		self::TYPE_EMBEDDED_PDV => "EMBEDDED PDV",
131
+		self::TYPE_UTF8_STRING => "UTF8String",
132
+		self::TYPE_RELATIVE_OID => "RELATIVE-OID",
133
+		self::TYPE_SEQUENCE => "SEQUENCE",
134
+		self::TYPE_SET => "SET",
135
+		self::TYPE_NUMERIC_STRING => "NumericString",
136
+		self::TYPE_PRINTABLE_STRING => "PrintableString",
137
+		self::TYPE_T61_STRING => "T61String",
138
+		self::TYPE_VIDEOTEX_STRING => "VideotexString",
139
+		self::TYPE_IA5_STRING => "IA5String",
140
+		self::TYPE_UTC_TIME => "UTCTime",
141
+		self::TYPE_GENERALIZED_TIME => "GeneralizedTime",
142
+		self::TYPE_GRAPHIC_STRING => "GraphicString",
143
+		self::TYPE_VISIBLE_STRING => "VisibleString",
144
+		self::TYPE_GENERAL_STRING => "GeneralString",
145
+		self::TYPE_UNIVERSAL_STRING => "UniversalString",
146
+		self::TYPE_CHARACTER_STRING => "CHARACTER STRING",
147
+		self::TYPE_BMP_STRING => "BMPString",
148
+		self::TYPE_STRING => "Any String",
149
+		self::TYPE_TIME => "Any Time"
150
+		/* @formatter:on */
151
+	];
152 152
     
153
-    /**
154
-     * Element's type tag.
155
-     *
156
-     * @var int
157
-     */
158
-    protected $_typeTag;
153
+	/**
154
+	 * Element's type tag.
155
+	 *
156
+	 * @var int
157
+	 */
158
+	protected $_typeTag;
159 159
     
160
-    /**
161
-     *
162
-     * @see \ASN1\Feature\ElementBase::typeClass()
163
-     * @return int
164
-     */
165
-    abstract public function typeClass(): int;
160
+	/**
161
+	 *
162
+	 * @see \ASN1\Feature\ElementBase::typeClass()
163
+	 * @return int
164
+	 */
165
+	abstract public function typeClass(): int;
166 166
     
167
-    /**
168
-     *
169
-     * @see \ASN1\Feature\ElementBase::isConstructed()
170
-     * @return bool
171
-     */
172
-    abstract public function isConstructed(): bool;
167
+	/**
168
+	 *
169
+	 * @see \ASN1\Feature\ElementBase::isConstructed()
170
+	 * @return bool
171
+	 */
172
+	abstract public function isConstructed(): bool;
173 173
     
174
-    /**
175
-     * Get the content encoded in DER.
176
-     *
177
-     * Returns the DER encoded content without identifier and length header
178
-     * octets.
179
-     *
180
-     * @return string
181
-     */
182
-    abstract protected function _encodedContentDER(): string;
174
+	/**
175
+	 * Get the content encoded in DER.
176
+	 *
177
+	 * Returns the DER encoded content without identifier and length header
178
+	 * octets.
179
+	 *
180
+	 * @return string
181
+	 */
182
+	abstract protected function _encodedContentDER(): string;
183 183
     
184
-    /**
185
-     * Decode type-specific element from DER.
186
-     *
187
-     * @param Identifier $identifier Pre-parsed identifier
188
-     * @param string $data DER data
189
-     * @param int $offset Offset in data to the next byte after identifier
190
-     * @throws DecodeException If decoding fails
191
-     * @return ElementBase
192
-     */
193
-    protected static function _decodeFromDER(Identifier $identifier, string $data,
194
-        int &$offset): ElementBase
195
-    {
196
-        throw new \BadMethodCallException(
197
-            __METHOD__ . " must be implemented in derived class.");
198
-    }
184
+	/**
185
+	 * Decode type-specific element from DER.
186
+	 *
187
+	 * @param Identifier $identifier Pre-parsed identifier
188
+	 * @param string $data DER data
189
+	 * @param int $offset Offset in data to the next byte after identifier
190
+	 * @throws DecodeException If decoding fails
191
+	 * @return ElementBase
192
+	 */
193
+	protected static function _decodeFromDER(Identifier $identifier, string $data,
194
+		int &$offset): ElementBase
195
+	{
196
+		throw new \BadMethodCallException(
197
+			__METHOD__ . " must be implemented in derived class.");
198
+	}
199 199
     
200
-    /**
201
-     * Decode element from DER data.
202
-     *
203
-     * @param string $data DER encoded data
204
-     * @param int|null $offset Reference to the variable that contains offset
205
-     *        into the data where to start parsing. Variable is updated to
206
-     *        the offset next to the parsed element. If null, start from offset
207
-     *        0.
208
-     * @throws DecodeException If decoding fails
209
-     * @throws \UnexpectedValueException If called in the context of an expected
210
-     *         type, but decoding yields another type
211
-     * @return ElementBase
212
-     */
213
-    public static function fromDER(string $data, int &$offset = null): ElementBase
214
-    {
215
-        // decode identifier
216
-        $idx = $offset ?? 0;
217
-        $identifier = Identifier::fromDER($data, $idx);
218
-        // determine class that implements type specific decoding
219
-        $cls = self::_determineImplClass($identifier);
220
-        try {
221
-            // decode remaining element
222
-            $element = $cls::_decodeFromDER($identifier, $data, $idx);
223
-        } catch (\LogicException $e) {
224
-            // rethrow as a RuntimeException for unified exception handling
225
-            throw new DecodeException(
226
-                sprintf("Error while decoding %s.",
227
-                    self::tagToName($identifier->intTag())), 0, $e);
228
-        }
229
-        // if called in the context of a concrete class, check
230
-        // that decoded type matches the type of a calling class
231
-        $called_class = get_called_class();
232
-        if (self::class != $called_class) {
233
-            if (!$element instanceof $called_class) {
234
-                throw new \UnexpectedValueException(
235
-                    sprintf("%s expected, got %s.", $called_class,
236
-                        get_class($element)));
237
-            }
238
-        }
239
-        // update offset for the caller
240
-        if (isset($offset)) {
241
-            $offset = $idx;
242
-        }
243
-        return $element;
244
-    }
200
+	/**
201
+	 * Decode element from DER data.
202
+	 *
203
+	 * @param string $data DER encoded data
204
+	 * @param int|null $offset Reference to the variable that contains offset
205
+	 *        into the data where to start parsing. Variable is updated to
206
+	 *        the offset next to the parsed element. If null, start from offset
207
+	 *        0.
208
+	 * @throws DecodeException If decoding fails
209
+	 * @throws \UnexpectedValueException If called in the context of an expected
210
+	 *         type, but decoding yields another type
211
+	 * @return ElementBase
212
+	 */
213
+	public static function fromDER(string $data, int &$offset = null): ElementBase
214
+	{
215
+		// decode identifier
216
+		$idx = $offset ?? 0;
217
+		$identifier = Identifier::fromDER($data, $idx);
218
+		// determine class that implements type specific decoding
219
+		$cls = self::_determineImplClass($identifier);
220
+		try {
221
+			// decode remaining element
222
+			$element = $cls::_decodeFromDER($identifier, $data, $idx);
223
+		} catch (\LogicException $e) {
224
+			// rethrow as a RuntimeException for unified exception handling
225
+			throw new DecodeException(
226
+				sprintf("Error while decoding %s.",
227
+					self::tagToName($identifier->intTag())), 0, $e);
228
+		}
229
+		// if called in the context of a concrete class, check
230
+		// that decoded type matches the type of a calling class
231
+		$called_class = get_called_class();
232
+		if (self::class != $called_class) {
233
+			if (!$element instanceof $called_class) {
234
+				throw new \UnexpectedValueException(
235
+					sprintf("%s expected, got %s.", $called_class,
236
+						get_class($element)));
237
+			}
238
+		}
239
+		// update offset for the caller
240
+		if (isset($offset)) {
241
+			$offset = $idx;
242
+		}
243
+		return $element;
244
+	}
245 245
     
246
-    /**
247
-     *
248
-     * @see \ASN1\Feature\Encodable::toDER()
249
-     * @return string
250
-     */
251
-    public function toDER(): string
252
-    {
253
-        $identifier = new Identifier($this->typeClass(),
254
-            $this->isConstructed() ? Identifier::CONSTRUCTED : Identifier::PRIMITIVE,
255
-            $this->_typeTag);
256
-        $content = $this->_encodedContentDER();
257
-        $length = new Length(strlen($content));
258
-        return $identifier->toDER() . $length->toDER() . $content;
259
-    }
246
+	/**
247
+	 *
248
+	 * @see \ASN1\Feature\Encodable::toDER()
249
+	 * @return string
250
+	 */
251
+	public function toDER(): string
252
+	{
253
+		$identifier = new Identifier($this->typeClass(),
254
+			$this->isConstructed() ? Identifier::CONSTRUCTED : Identifier::PRIMITIVE,
255
+			$this->_typeTag);
256
+		$content = $this->_encodedContentDER();
257
+		$length = new Length(strlen($content));
258
+		return $identifier->toDER() . $length->toDER() . $content;
259
+	}
260 260
     
261
-    /**
262
-     *
263
-     * @see \ASN1\Feature\ElementBase::tag()
264
-     * @return int
265
-     */
266
-    public function tag(): int
267
-    {
268
-        return $this->_typeTag;
269
-    }
261
+	/**
262
+	 *
263
+	 * @see \ASN1\Feature\ElementBase::tag()
264
+	 * @return int
265
+	 */
266
+	public function tag(): int
267
+	{
268
+		return $this->_typeTag;
269
+	}
270 270
     
271
-    /**
272
-     *
273
-     * @see \ASN1\Feature\ElementBase::isType()
274
-     * @return bool
275
-     */
276
-    public function isType(int $tag): bool
277
-    {
278
-        // if element is context specific
279
-        if ($this->typeClass() == Identifier::CLASS_CONTEXT_SPECIFIC) {
280
-            return false;
281
-        }
282
-        // negative tags identify an abstract pseudotype
283
-        if ($tag < 0) {
284
-            return $this->_isPseudoType($tag);
285
-        }
286
-        return $this->_isConcreteType($tag);
287
-    }
271
+	/**
272
+	 *
273
+	 * @see \ASN1\Feature\ElementBase::isType()
274
+	 * @return bool
275
+	 */
276
+	public function isType(int $tag): bool
277
+	{
278
+		// if element is context specific
279
+		if ($this->typeClass() == Identifier::CLASS_CONTEXT_SPECIFIC) {
280
+			return false;
281
+		}
282
+		// negative tags identify an abstract pseudotype
283
+		if ($tag < 0) {
284
+			return $this->_isPseudoType($tag);
285
+		}
286
+		return $this->_isConcreteType($tag);
287
+	}
288 288
     
289
-    /**
290
-     *
291
-     * @see \ASN1\Feature\ElementBase::expectType()
292
-     * @return ElementBase
293
-     */
294
-    public function expectType(int $tag): ElementBase
295
-    {
296
-        if (!$this->isType($tag)) {
297
-            throw new \UnexpectedValueException(
298
-                sprintf("%s expected, got %s.", self::tagToName($tag),
299
-                    $this->_typeDescriptorString()));
300
-        }
301
-        return $this;
302
-    }
289
+	/**
290
+	 *
291
+	 * @see \ASN1\Feature\ElementBase::expectType()
292
+	 * @return ElementBase
293
+	 */
294
+	public function expectType(int $tag): ElementBase
295
+	{
296
+		if (!$this->isType($tag)) {
297
+			throw new \UnexpectedValueException(
298
+				sprintf("%s expected, got %s.", self::tagToName($tag),
299
+					$this->_typeDescriptorString()));
300
+		}
301
+		return $this;
302
+	}
303 303
     
304
-    /**
305
-     * Check whether the element is a concrete type of a given tag.
306
-     *
307
-     * @param int $tag
308
-     * @return bool
309
-     */
310
-    private function _isConcreteType(int $tag): bool
311
-    {
312
-        // if tag doesn't match
313
-        if ($this->tag() != $tag) {
314
-            return false;
315
-        }
316
-        // if type is universal check that instance is of a correct class
317
-        if ($this->typeClass() == Identifier::CLASS_UNIVERSAL) {
318
-            $cls = self::_determineUniversalImplClass($tag);
319
-            if (!$this instanceof $cls) {
320
-                return false;
321
-            }
322
-        }
323
-        return true;
324
-    }
304
+	/**
305
+	 * Check whether the element is a concrete type of a given tag.
306
+	 *
307
+	 * @param int $tag
308
+	 * @return bool
309
+	 */
310
+	private function _isConcreteType(int $tag): bool
311
+	{
312
+		// if tag doesn't match
313
+		if ($this->tag() != $tag) {
314
+			return false;
315
+		}
316
+		// if type is universal check that instance is of a correct class
317
+		if ($this->typeClass() == Identifier::CLASS_UNIVERSAL) {
318
+			$cls = self::_determineUniversalImplClass($tag);
319
+			if (!$this instanceof $cls) {
320
+				return false;
321
+			}
322
+		}
323
+		return true;
324
+	}
325 325
     
326
-    /**
327
-     * Check whether the element is a pseudotype.
328
-     *
329
-     * @param int $tag
330
-     * @return bool
331
-     */
332
-    private function _isPseudoType(int $tag): bool
333
-    {
334
-        switch ($tag) {
335
-            case self::TYPE_STRING:
336
-                return $this instanceof StringType;
337
-            case self::TYPE_TIME:
338
-                return $this instanceof TimeType;
339
-        }
340
-        return false;
341
-    }
326
+	/**
327
+	 * Check whether the element is a pseudotype.
328
+	 *
329
+	 * @param int $tag
330
+	 * @return bool
331
+	 */
332
+	private function _isPseudoType(int $tag): bool
333
+	{
334
+		switch ($tag) {
335
+			case self::TYPE_STRING:
336
+				return $this instanceof StringType;
337
+			case self::TYPE_TIME:
338
+				return $this instanceof TimeType;
339
+		}
340
+		return false;
341
+	}
342 342
     
343
-    /**
344
-     *
345
-     * @see \ASN1\Feature\ElementBase::isTagged()
346
-     * @return bool
347
-     */
348
-    public function isTagged(): bool
349
-    {
350
-        return $this instanceof TaggedType;
351
-    }
343
+	/**
344
+	 *
345
+	 * @see \ASN1\Feature\ElementBase::isTagged()
346
+	 * @return bool
347
+	 */
348
+	public function isTagged(): bool
349
+	{
350
+		return $this instanceof TaggedType;
351
+	}
352 352
     
353
-    /**
354
-     *
355
-     * @see \ASN1\Feature\ElementBase::expectTagged()
356
-     * @return TaggedType
357
-     */
358
-    public function expectTagged($tag = null): TaggedType
359
-    {
360
-        if (!$this->isTagged()) {
361
-            throw new \UnexpectedValueException(
362
-                sprintf("Context specific element expected, got %s.",
363
-                    Identifier::classToName($this->typeClass())));
364
-        }
365
-        if (isset($tag) && $this->tag() != $tag) {
366
-            throw new \UnexpectedValueException(
367
-                sprintf("Tag %d expected, got %d.", $tag, $this->tag()));
368
-        }
369
-        return $this;
370
-    }
353
+	/**
354
+	 *
355
+	 * @see \ASN1\Feature\ElementBase::expectTagged()
356
+	 * @return TaggedType
357
+	 */
358
+	public function expectTagged($tag = null): TaggedType
359
+	{
360
+		if (!$this->isTagged()) {
361
+			throw new \UnexpectedValueException(
362
+				sprintf("Context specific element expected, got %s.",
363
+					Identifier::classToName($this->typeClass())));
364
+		}
365
+		if (isset($tag) && $this->tag() != $tag) {
366
+			throw new \UnexpectedValueException(
367
+				sprintf("Tag %d expected, got %d.", $tag, $this->tag()));
368
+		}
369
+		return $this;
370
+	}
371 371
     
372
-    /**
373
-     *
374
-     * @see \ASN1\Feature\ElementBase::asElement()
375
-     * @return Element
376
-     */
377
-    final public function asElement(): Element
378
-    {
379
-        return $this;
380
-    }
372
+	/**
373
+	 *
374
+	 * @see \ASN1\Feature\ElementBase::asElement()
375
+	 * @return Element
376
+	 */
377
+	final public function asElement(): Element
378
+	{
379
+		return $this;
380
+	}
381 381
     
382
-    /**
383
-     * Get element decorated with UnspecifiedType object.
384
-     *
385
-     * @return UnspecifiedType
386
-     */
387
-    public function asUnspecified(): UnspecifiedType
388
-    {
389
-        return new UnspecifiedType($this);
390
-    }
382
+	/**
383
+	 * Get element decorated with UnspecifiedType object.
384
+	 *
385
+	 * @return UnspecifiedType
386
+	 */
387
+	public function asUnspecified(): UnspecifiedType
388
+	{
389
+		return new UnspecifiedType($this);
390
+	}
391 391
     
392
-    /**
393
-     * Determine the class that implements the type.
394
-     *
395
-     * @param Identifier $identifier
396
-     * @return string Class name
397
-     */
398
-    protected static function _determineImplClass(Identifier $identifier): string
399
-    {
400
-        switch ($identifier->typeClass()) {
401
-            case Identifier::CLASS_UNIVERSAL:
402
-                return self::_determineUniversalImplClass($identifier->intTag());
403
-            case Identifier::CLASS_CONTEXT_SPECIFIC:
404
-                return TaggedType::class;
405
-            case Identifier::CLASS_APPLICATION:
406
-                return ApplicationType::class;
407
-            case Identifier::CLASS_PRIVATE:
408
-                return PrivateType::class;
409
-        }
410
-        throw new \UnexpectedValueException(
411
-            sprintf("%s %d not implemented.",
412
-                Identifier::classToName($identifier->typeClass()),
413
-                $identifier->tag()));
414
-    }
392
+	/**
393
+	 * Determine the class that implements the type.
394
+	 *
395
+	 * @param Identifier $identifier
396
+	 * @return string Class name
397
+	 */
398
+	protected static function _determineImplClass(Identifier $identifier): string
399
+	{
400
+		switch ($identifier->typeClass()) {
401
+			case Identifier::CLASS_UNIVERSAL:
402
+				return self::_determineUniversalImplClass($identifier->intTag());
403
+			case Identifier::CLASS_CONTEXT_SPECIFIC:
404
+				return TaggedType::class;
405
+			case Identifier::CLASS_APPLICATION:
406
+				return ApplicationType::class;
407
+			case Identifier::CLASS_PRIVATE:
408
+				return PrivateType::class;
409
+		}
410
+		throw new \UnexpectedValueException(
411
+			sprintf("%s %d not implemented.",
412
+				Identifier::classToName($identifier->typeClass()),
413
+				$identifier->tag()));
414
+	}
415 415
     
416
-    /**
417
-     * Determine the class that implements an universal type of the given tag.
418
-     *
419
-     * @param int $tag
420
-     * @throws \UnexpectedValueException
421
-     * @return string Class name
422
-     */
423
-    protected static function _determineUniversalImplClass(int $tag): string
424
-    {
425
-        if (!array_key_exists($tag, self::MAP_TAG_TO_CLASS)) {
426
-            throw new \UnexpectedValueException(
427
-                "Universal tag $tag not implemented.");
428
-        }
429
-        return self::MAP_TAG_TO_CLASS[$tag];
430
-    }
416
+	/**
417
+	 * Determine the class that implements an universal type of the given tag.
418
+	 *
419
+	 * @param int $tag
420
+	 * @throws \UnexpectedValueException
421
+	 * @return string Class name
422
+	 */
423
+	protected static function _determineUniversalImplClass(int $tag): string
424
+	{
425
+		if (!array_key_exists($tag, self::MAP_TAG_TO_CLASS)) {
426
+			throw new \UnexpectedValueException(
427
+				"Universal tag $tag not implemented.");
428
+		}
429
+		return self::MAP_TAG_TO_CLASS[$tag];
430
+	}
431 431
     
432
-    /**
433
-     * Get textual description of the type for debugging purposes.
434
-     *
435
-     * @return string
436
-     */
437
-    protected function _typeDescriptorString(): string
438
-    {
439
-        if ($this->typeClass() == Identifier::CLASS_UNIVERSAL) {
440
-            return self::tagToName($this->_typeTag);
441
-        }
442
-        return sprintf("%s TAG %d", Identifier::classToName($this->typeClass()),
443
-            $this->_typeTag);
444
-    }
432
+	/**
433
+	 * Get textual description of the type for debugging purposes.
434
+	 *
435
+	 * @return string
436
+	 */
437
+	protected function _typeDescriptorString(): string
438
+	{
439
+		if ($this->typeClass() == Identifier::CLASS_UNIVERSAL) {
440
+			return self::tagToName($this->_typeTag);
441
+		}
442
+		return sprintf("%s TAG %d", Identifier::classToName($this->typeClass()),
443
+			$this->_typeTag);
444
+	}
445 445
     
446
-    /**
447
-     * Get human readable name for an universal tag.
448
-     *
449
-     * @param int $tag
450
-     * @return string
451
-     */
452
-    public static function tagToName(int $tag): string
453
-    {
454
-        if (!array_key_exists($tag, self::MAP_TYPE_TO_NAME)) {
455
-            return "TAG $tag";
456
-        }
457
-        return self::MAP_TYPE_TO_NAME[$tag];
458
-    }
446
+	/**
447
+	 * Get human readable name for an universal tag.
448
+	 *
449
+	 * @param int $tag
450
+	 * @return string
451
+	 */
452
+	public static function tagToName(int $tag): string
453
+	{
454
+		if (!array_key_exists($tag, self::MAP_TYPE_TO_NAME)) {
455
+			return "TAG $tag";
456
+		}
457
+		return self::MAP_TYPE_TO_NAME[$tag];
458
+	}
459 459
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace ASN1;
6 6
 
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
      *
61 61
      * @var array
62 62
      */
63
-    const MAP_TAG_TO_CLASS = [ /* @formatter:off */
63
+    const MAP_TAG_TO_CLASS = [/* @formatter:off */
64 64
         self::TYPE_BOOLEAN => Primitive\Boolean::class,
65 65
         self::TYPE_INTEGER => Primitive\Integer::class,
66 66
         self::TYPE_BIT_STRING => Primitive\BitString::class,
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
      *
116 116
      * @var array
117 117
      */
118
-    const MAP_TYPE_TO_NAME = [ /* @formatter:off */
118
+    const MAP_TYPE_TO_NAME = [/* @formatter:off */
119 119
         self::TYPE_EOC => "EOC",
120 120
         self::TYPE_BOOLEAN => "BOOLEAN",
121 121
         self::TYPE_INTEGER => "INTEGER",
Please login to merge, or discard this patch.
lib/ASN1/Component/Length.php 2 patches
Indentation   +193 added lines, -193 removed lines patch added patch discarded remove patch
@@ -13,206 +13,206 @@
 block discarded – undo
13 13
  */
14 14
 class Length implements Encodable
15 15
 {
16
-    /**
17
-     * Length.
18
-     *
19
-     * @var BigInt
20
-     */
21
-    private $_length;
16
+	/**
17
+	 * Length.
18
+	 *
19
+	 * @var BigInt
20
+	 */
21
+	private $_length;
22 22
     
23
-    /**
24
-     * Whether length is indefinite.
25
-     *
26
-     * @var bool
27
-     */
28
-    private $_indefinite;
23
+	/**
24
+	 * Whether length is indefinite.
25
+	 *
26
+	 * @var bool
27
+	 */
28
+	private $_indefinite;
29 29
     
30
-    /**
31
-     * Constructor.
32
-     *
33
-     * @param int|string $length Length
34
-     * @param bool $indefinite Whether length is indefinite
35
-     */
36
-    public function __construct($length, bool $indefinite = false)
37
-    {
38
-        $this->_length = new BigInt($length);
39
-        $this->_indefinite = $indefinite;
40
-    }
30
+	/**
31
+	 * Constructor.
32
+	 *
33
+	 * @param int|string $length Length
34
+	 * @param bool $indefinite Whether length is indefinite
35
+	 */
36
+	public function __construct($length, bool $indefinite = false)
37
+	{
38
+		$this->_length = new BigInt($length);
39
+		$this->_indefinite = $indefinite;
40
+	}
41 41
     
42
-    /**
43
-     * Decode length component from DER data.
44
-     *
45
-     * @param string $data DER encoded data
46
-     * @param int|null $offset Reference to the variable that contains offset
47
-     *        into the data where to start parsing. Variable is updated to
48
-     *        the offset next to the parsed length component. If null, start
49
-     *        from offset 0.
50
-     * @throws DecodeException If decoding fails
51
-     * @return self
52
-     */
53
-    public static function fromDER(string $data, int &$offset = null): self
54
-    {
55
-        $idx = $offset ?? 0;
56
-        $datalen = strlen($data);
57
-        if ($idx >= $datalen) {
58
-            throw new DecodeException("Invalid offset.");
59
-        }
60
-        $indefinite = false;
61
-        $byte = ord($data[$idx++]);
62
-        // bits 7 to 1
63
-        $length = (0x7f & $byte);
64
-        // long form
65
-        if (0x80 & $byte) {
66
-            if (!$length) {
67
-                $indefinite = true;
68
-            } else {
69
-                if ($idx + $length > $datalen) {
70
-                    throw new DecodeException("Too many length octets.");
71
-                }
72
-                $length = self::_decodeLongFormLength($length, $data, $idx);
73
-            }
74
-        }
75
-        if (isset($offset)) {
76
-            $offset = $idx;
77
-        }
78
-        return new self($length, $indefinite);
79
-    }
42
+	/**
43
+	 * Decode length component from DER data.
44
+	 *
45
+	 * @param string $data DER encoded data
46
+	 * @param int|null $offset Reference to the variable that contains offset
47
+	 *        into the data where to start parsing. Variable is updated to
48
+	 *        the offset next to the parsed length component. If null, start
49
+	 *        from offset 0.
50
+	 * @throws DecodeException If decoding fails
51
+	 * @return self
52
+	 */
53
+	public static function fromDER(string $data, int &$offset = null): self
54
+	{
55
+		$idx = $offset ?? 0;
56
+		$datalen = strlen($data);
57
+		if ($idx >= $datalen) {
58
+			throw new DecodeException("Invalid offset.");
59
+		}
60
+		$indefinite = false;
61
+		$byte = ord($data[$idx++]);
62
+		// bits 7 to 1
63
+		$length = (0x7f & $byte);
64
+		// long form
65
+		if (0x80 & $byte) {
66
+			if (!$length) {
67
+				$indefinite = true;
68
+			} else {
69
+				if ($idx + $length > $datalen) {
70
+					throw new DecodeException("Too many length octets.");
71
+				}
72
+				$length = self::_decodeLongFormLength($length, $data, $idx);
73
+			}
74
+		}
75
+		if (isset($offset)) {
76
+			$offset = $idx;
77
+		}
78
+		return new self($length, $indefinite);
79
+	}
80 80
     
81
-    /**
82
-     * Decode long form length.
83
-     *
84
-     * @param int $length Number of octets
85
-     * @param string $data Data
86
-     * @param int $offset Reference to the variable containing offset to the
87
-     *        data.
88
-     * @throws DecodeException If decoding fails
89
-     * @return string Integer as a string
90
-     */
91
-    private static function _decodeLongFormLength(int $length, string $data,
92
-        int &$offset): string
93
-    {
94
-        // first octet must not be 0xff (spec 8.1.3.5c)
95
-        if ($length == 127) {
96
-            throw new DecodeException("Invalid number of length octets.");
97
-        }
98
-        $num = gmp_init(0, 10);
99
-        while (--$length >= 0) {
100
-            $byte = ord($data[$offset++]);
101
-            $num <<= 8;
102
-            $num |= $byte;
103
-        }
104
-        return gmp_strval($num);
105
-    }
81
+	/**
82
+	 * Decode long form length.
83
+	 *
84
+	 * @param int $length Number of octets
85
+	 * @param string $data Data
86
+	 * @param int $offset Reference to the variable containing offset to the
87
+	 *        data.
88
+	 * @throws DecodeException If decoding fails
89
+	 * @return string Integer as a string
90
+	 */
91
+	private static function _decodeLongFormLength(int $length, string $data,
92
+		int &$offset): string
93
+	{
94
+		// first octet must not be 0xff (spec 8.1.3.5c)
95
+		if ($length == 127) {
96
+			throw new DecodeException("Invalid number of length octets.");
97
+		}
98
+		$num = gmp_init(0, 10);
99
+		while (--$length >= 0) {
100
+			$byte = ord($data[$offset++]);
101
+			$num <<= 8;
102
+			$num |= $byte;
103
+		}
104
+		return gmp_strval($num);
105
+	}
106 106
     
107
-    /**
108
-     * Decode length from DER.
109
-     *
110
-     * Throws an exception if length doesn't match with expected or if data
111
-     * doesn't contain enough bytes.
112
-     *
113
-     * @see self::fromDER
114
-     * @param string $data DER data
115
-     * @param int $offset Reference to the offset variable
116
-     * @param int|null $expected Expected length, null to bypass checking
117
-     * @throws DecodeException If decoding or expectation fails
118
-     * @return self
119
-     */
120
-    public static function expectFromDER(string $data, int &$offset,
121
-        int $expected = null): self
122
-    {
123
-        $idx = $offset;
124
-        $length = self::fromDER($data, $idx);
125
-        // DER encoding must have definite length (spec 10.1)
126
-        if ($length->isIndefinite()) {
127
-            throw new DecodeException("DER encoding must have definite length.");
128
-        }
129
-        // if certain length was expected
130
-        if (isset($expected) && $expected != $length->intLength()) {
131
-            throw new DecodeException(
132
-                sprintf("Expected length %d, got %d.", $expected,
133
-                    $length->intLength()));
134
-        }
135
-        // check that enough data is available
136
-        if (strlen($data) < $idx + $length->intLength()) {
137
-            throw new DecodeException(
138
-                sprintf("Length %d overflows data, %d bytes left.",
139
-                    $length->intLength(), strlen($data) - $idx));
140
-        }
141
-        $offset = $idx;
142
-        return $length;
143
-    }
107
+	/**
108
+	 * Decode length from DER.
109
+	 *
110
+	 * Throws an exception if length doesn't match with expected or if data
111
+	 * doesn't contain enough bytes.
112
+	 *
113
+	 * @see self::fromDER
114
+	 * @param string $data DER data
115
+	 * @param int $offset Reference to the offset variable
116
+	 * @param int|null $expected Expected length, null to bypass checking
117
+	 * @throws DecodeException If decoding or expectation fails
118
+	 * @return self
119
+	 */
120
+	public static function expectFromDER(string $data, int &$offset,
121
+		int $expected = null): self
122
+	{
123
+		$idx = $offset;
124
+		$length = self::fromDER($data, $idx);
125
+		// DER encoding must have definite length (spec 10.1)
126
+		if ($length->isIndefinite()) {
127
+			throw new DecodeException("DER encoding must have definite length.");
128
+		}
129
+		// if certain length was expected
130
+		if (isset($expected) && $expected != $length->intLength()) {
131
+			throw new DecodeException(
132
+				sprintf("Expected length %d, got %d.", $expected,
133
+					$length->intLength()));
134
+		}
135
+		// check that enough data is available
136
+		if (strlen($data) < $idx + $length->intLength()) {
137
+			throw new DecodeException(
138
+				sprintf("Length %d overflows data, %d bytes left.",
139
+					$length->intLength(), strlen($data) - $idx));
140
+		}
141
+		$offset = $idx;
142
+		return $length;
143
+	}
144 144
     
145
-    /**
146
-     *
147
-     * @see Encodable::toDER()
148
-     * @throws \DomainException If length is too large to encode
149
-     * @return string
150
-     */
151
-    public function toDER(): string
152
-    {
153
-        $bytes = [];
154
-        if ($this->_indefinite) {
155
-            $bytes[] = 0x80;
156
-        } else {
157
-            $num = $this->_length->gmpObj();
158
-            // long form
159
-            if ($num > 127) {
160
-                $octets = [];
161
-                for (; $num > 0; $num >>= 8) {
162
-                    $octets[] = gmp_intval(0xff & $num);
163
-                }
164
-                $count = count($octets);
165
-                // first octet must not be 0xff
166
-                if ($count >= 127) {
167
-                    throw new \DomainException("Too many length octets.");
168
-                }
169
-                $bytes[] = 0x80 | $count;
170
-                foreach (array_reverse($octets) as $octet) {
171
-                    $bytes[] = $octet;
172
-                }
173
-            } else { // short form
174
-                $bytes[] = gmp_intval($num);
175
-            }
176
-        }
177
-        return pack("C*", ...$bytes);
178
-    }
145
+	/**
146
+	 *
147
+	 * @see Encodable::toDER()
148
+	 * @throws \DomainException If length is too large to encode
149
+	 * @return string
150
+	 */
151
+	public function toDER(): string
152
+	{
153
+		$bytes = [];
154
+		if ($this->_indefinite) {
155
+			$bytes[] = 0x80;
156
+		} else {
157
+			$num = $this->_length->gmpObj();
158
+			// long form
159
+			if ($num > 127) {
160
+				$octets = [];
161
+				for (; $num > 0; $num >>= 8) {
162
+					$octets[] = gmp_intval(0xff & $num);
163
+				}
164
+				$count = count($octets);
165
+				// first octet must not be 0xff
166
+				if ($count >= 127) {
167
+					throw new \DomainException("Too many length octets.");
168
+				}
169
+				$bytes[] = 0x80 | $count;
170
+				foreach (array_reverse($octets) as $octet) {
171
+					$bytes[] = $octet;
172
+				}
173
+			} else { // short form
174
+				$bytes[] = gmp_intval($num);
175
+			}
176
+		}
177
+		return pack("C*", ...$bytes);
178
+	}
179 179
     
180
-    /**
181
-     * Get the length.
182
-     *
183
-     * @throws \LogicException If length is indefinite
184
-     * @return string Length as an integer string
185
-     */
186
-    public function length(): string
187
-    {
188
-        if ($this->_indefinite) {
189
-            throw new \LogicException("Length is indefinite.");
190
-        }
191
-        return $this->_length->base10();
192
-    }
180
+	/**
181
+	 * Get the length.
182
+	 *
183
+	 * @throws \LogicException If length is indefinite
184
+	 * @return string Length as an integer string
185
+	 */
186
+	public function length(): string
187
+	{
188
+		if ($this->_indefinite) {
189
+			throw new \LogicException("Length is indefinite.");
190
+		}
191
+		return $this->_length->base10();
192
+	}
193 193
     
194
-    /**
195
-     * Get the length as an integer.
196
-     *
197
-     * @throws \LogicException If length is indefinite
198
-     * @throws \RuntimeException If length overflows integer size
199
-     * @return int
200
-     */
201
-    public function intLength(): int
202
-    {
203
-        if ($this->_indefinite) {
204
-            throw new \LogicException("Length is indefinite.");
205
-        }
206
-        return $this->_length->intVal();
207
-    }
194
+	/**
195
+	 * Get the length as an integer.
196
+	 *
197
+	 * @throws \LogicException If length is indefinite
198
+	 * @throws \RuntimeException If length overflows integer size
199
+	 * @return int
200
+	 */
201
+	public function intLength(): int
202
+	{
203
+		if ($this->_indefinite) {
204
+			throw new \LogicException("Length is indefinite.");
205
+		}
206
+		return $this->_length->intVal();
207
+	}
208 208
     
209
-    /**
210
-     * Whether length is indefinite.
211
-     *
212
-     * @return bool
213
-     */
214
-    public function isIndefinite(): bool
215
-    {
216
-        return $this->_indefinite;
217
-    }
209
+	/**
210
+	 * Whether length is indefinite.
211
+	 *
212
+	 * @return bool
213
+	 */
214
+	public function isIndefinite(): bool
215
+	{
216
+		return $this->_indefinite;
217
+	}
218 218
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace ASN1\Component;
6 6
 
Please login to merge, or discard this patch.
lib/ASN1/Component/Identifier.php 2 patches
Indentation   +269 added lines, -269 removed lines patch added patch discarded remove patch
@@ -13,295 +13,295 @@
 block discarded – undo
13 13
  */
14 14
 class Identifier implements Encodable
15 15
 {
16
-    // Type class enumerations
17
-    const CLASS_UNIVERSAL = 0b00;
18
-    const CLASS_APPLICATION = 0b01;
19
-    const CLASS_CONTEXT_SPECIFIC = 0b10;
20
-    const CLASS_PRIVATE = 0b11;
16
+	// Type class enumerations
17
+	const CLASS_UNIVERSAL = 0b00;
18
+	const CLASS_APPLICATION = 0b01;
19
+	const CLASS_CONTEXT_SPECIFIC = 0b10;
20
+	const CLASS_PRIVATE = 0b11;
21 21
     
22
-    /**
23
-     * Mapping from type class to human readable name.
24
-     *
25
-     * @internal
26
-     *
27
-     * @var array
28
-     */
29
-    const MAP_CLASS_TO_NAME = [ /* @formatter:off */
30
-        self::CLASS_UNIVERSAL => "UNIVERSAL", 
31
-        self::CLASS_APPLICATION => "APPLICATION", 
32
-        self::CLASS_CONTEXT_SPECIFIC => "CONTEXT SPECIFIC", 
33
-        self::CLASS_PRIVATE => "PRIVATE",
34
-        /* @formatter:on */
35
-    ];
22
+	/**
23
+	 * Mapping from type class to human readable name.
24
+	 *
25
+	 * @internal
26
+	 *
27
+	 * @var array
28
+	 */
29
+	const MAP_CLASS_TO_NAME = [ /* @formatter:off */
30
+		self::CLASS_UNIVERSAL => "UNIVERSAL", 
31
+		self::CLASS_APPLICATION => "APPLICATION", 
32
+		self::CLASS_CONTEXT_SPECIFIC => "CONTEXT SPECIFIC", 
33
+		self::CLASS_PRIVATE => "PRIVATE",
34
+		/* @formatter:on */
35
+	];
36 36
     
37
-    // P/C enumerations
38
-    const PRIMITIVE = 0b0;
39
-    const CONSTRUCTED = 0b1;
37
+	// P/C enumerations
38
+	const PRIMITIVE = 0b0;
39
+	const CONSTRUCTED = 0b1;
40 40
     
41
-    /**
42
-     * Type class.
43
-     *
44
-     * @var int
45
-     */
46
-    private $_class;
41
+	/**
42
+	 * Type class.
43
+	 *
44
+	 * @var int
45
+	 */
46
+	private $_class;
47 47
     
48
-    /**
49
-     * Primitive or Constructed.
50
-     *
51
-     * @var int
52
-     */
53
-    private $_pc;
48
+	/**
49
+	 * Primitive or Constructed.
50
+	 *
51
+	 * @var int
52
+	 */
53
+	private $_pc;
54 54
     
55
-    /**
56
-     * Content type tag.
57
-     *
58
-     * @var BigInt
59
-     */
60
-    private $_tag;
55
+	/**
56
+	 * Content type tag.
57
+	 *
58
+	 * @var BigInt
59
+	 */
60
+	private $_tag;
61 61
     
62
-    /**
63
-     * Constructor.
64
-     *
65
-     * @param int $class Type class
66
-     * @param int $pc Primitive / Constructed
67
-     * @param int|string $tag Type tag number
68
-     */
69
-    public function __construct(int $class, int $pc, $tag)
70
-    {
71
-        $this->_class = 0b11 & $class;
72
-        $this->_pc = 0b1 & $pc;
73
-        $this->_tag = new BigInt($tag);
74
-    }
62
+	/**
63
+	 * Constructor.
64
+	 *
65
+	 * @param int $class Type class
66
+	 * @param int $pc Primitive / Constructed
67
+	 * @param int|string $tag Type tag number
68
+	 */
69
+	public function __construct(int $class, int $pc, $tag)
70
+	{
71
+		$this->_class = 0b11 & $class;
72
+		$this->_pc = 0b1 & $pc;
73
+		$this->_tag = new BigInt($tag);
74
+	}
75 75
     
76
-    /**
77
-     * Decode identifier component from DER data.
78
-     *
79
-     * @param string $data DER encoded data
80
-     * @param int|null $offset Reference to the variable that contains offset
81
-     *        into the data where to start parsing. Variable is updated to
82
-     *        the offset next to the parsed identifier. If null, start from
83
-     *        offset 0.
84
-     * @throws DecodeException If decoding fails
85
-     * @return self
86
-     */
87
-    public static function fromDER(string $data, int &$offset = null): Identifier
88
-    {
89
-        $idx = $offset ?? 0;
90
-        $datalen = strlen($data);
91
-        if ($idx >= $datalen) {
92
-            throw new DecodeException("Invalid offset.");
93
-        }
94
-        $byte = ord($data[$idx++]);
95
-        // bits 8 and 7 (class)
96
-        // 0 = universal, 1 = application, 2 = context-specific, 3 = private
97
-        $class = (0b11000000 & $byte) >> 6;
98
-        // bit 6 (0 = primitive / 1 = constructed)
99
-        $pc = (0b00100000 & $byte) >> 5;
100
-        // bits 5 to 1 (tag number)
101
-        $tag = (0b00011111 & $byte);
102
-        // long-form identifier
103
-        if (0x1f == $tag) {
104
-            $tag = self::_decodeLongFormTag($data, $idx);
105
-        }
106
-        if (isset($offset)) {
107
-            $offset = $idx;
108
-        }
109
-        return new self($class, $pc, $tag);
110
-    }
76
+	/**
77
+	 * Decode identifier component from DER data.
78
+	 *
79
+	 * @param string $data DER encoded data
80
+	 * @param int|null $offset Reference to the variable that contains offset
81
+	 *        into the data where to start parsing. Variable is updated to
82
+	 *        the offset next to the parsed identifier. If null, start from
83
+	 *        offset 0.
84
+	 * @throws DecodeException If decoding fails
85
+	 * @return self
86
+	 */
87
+	public static function fromDER(string $data, int &$offset = null): Identifier
88
+	{
89
+		$idx = $offset ?? 0;
90
+		$datalen = strlen($data);
91
+		if ($idx >= $datalen) {
92
+			throw new DecodeException("Invalid offset.");
93
+		}
94
+		$byte = ord($data[$idx++]);
95
+		// bits 8 and 7 (class)
96
+		// 0 = universal, 1 = application, 2 = context-specific, 3 = private
97
+		$class = (0b11000000 & $byte) >> 6;
98
+		// bit 6 (0 = primitive / 1 = constructed)
99
+		$pc = (0b00100000 & $byte) >> 5;
100
+		// bits 5 to 1 (tag number)
101
+		$tag = (0b00011111 & $byte);
102
+		// long-form identifier
103
+		if (0x1f == $tag) {
104
+			$tag = self::_decodeLongFormTag($data, $idx);
105
+		}
106
+		if (isset($offset)) {
107
+			$offset = $idx;
108
+		}
109
+		return new self($class, $pc, $tag);
110
+	}
111 111
     
112
-    /**
113
-     * Parse long form tag.
114
-     *
115
-     * @param string $data DER data
116
-     * @param int $offset Reference to the variable containing offset to data
117
-     * @throws DecodeException If decoding fails
118
-     * @return string Tag number
119
-     */
120
-    private static function _decodeLongFormTag(string $data, int &$offset): string
121
-    {
122
-        $datalen = strlen($data);
123
-        $tag = gmp_init(0, 10);
124
-        while (true) {
125
-            if ($offset >= $datalen) {
126
-                throw new DecodeException(
127
-                    "Unexpected end of data while decoding" .
128
-                         " long form identifier.");
129
-            }
130
-            $byte = ord($data[$offset++]);
131
-            $tag <<= 7;
132
-            $tag |= 0x7f & $byte;
133
-            // last byte has bit 8 set to zero
134
-            if (!(0x80 & $byte)) {
135
-                break;
136
-            }
137
-        }
138
-        return gmp_strval($tag, 10);
139
-    }
112
+	/**
113
+	 * Parse long form tag.
114
+	 *
115
+	 * @param string $data DER data
116
+	 * @param int $offset Reference to the variable containing offset to data
117
+	 * @throws DecodeException If decoding fails
118
+	 * @return string Tag number
119
+	 */
120
+	private static function _decodeLongFormTag(string $data, int &$offset): string
121
+	{
122
+		$datalen = strlen($data);
123
+		$tag = gmp_init(0, 10);
124
+		while (true) {
125
+			if ($offset >= $datalen) {
126
+				throw new DecodeException(
127
+					"Unexpected end of data while decoding" .
128
+						 " long form identifier.");
129
+			}
130
+			$byte = ord($data[$offset++]);
131
+			$tag <<= 7;
132
+			$tag |= 0x7f & $byte;
133
+			// last byte has bit 8 set to zero
134
+			if (!(0x80 & $byte)) {
135
+				break;
136
+			}
137
+		}
138
+		return gmp_strval($tag, 10);
139
+	}
140 140
     
141
-    /**
142
-     *
143
-     * @see Encodable::toDER()
144
-     * @return string
145
-     */
146
-    public function toDER(): string
147
-    {
148
-        $bytes = [];
149
-        $byte = $this->_class << 6 | $this->_pc << 5;
150
-        $tag = $this->_tag->gmpObj();
151
-        if ($tag < 0x1f) {
152
-            $bytes[] = $byte | $tag;
153
-        } else { // long-form identifier
154
-            $bytes[] = $byte | 0x1f;
155
-            $octets = [];
156
-            for (; $tag > 0; $tag >>= 7) {
157
-                array_push($octets, gmp_intval(0x80 | ($tag & 0x7f)));
158
-            }
159
-            // last octet has bit 8 set to zero
160
-            $octets[0] &= 0x7f;
161
-            foreach (array_reverse($octets) as $octet) {
162
-                $bytes[] = $octet;
163
-            }
164
-        }
165
-        return pack("C*", ...$bytes);
166
-    }
141
+	/**
142
+	 *
143
+	 * @see Encodable::toDER()
144
+	 * @return string
145
+	 */
146
+	public function toDER(): string
147
+	{
148
+		$bytes = [];
149
+		$byte = $this->_class << 6 | $this->_pc << 5;
150
+		$tag = $this->_tag->gmpObj();
151
+		if ($tag < 0x1f) {
152
+			$bytes[] = $byte | $tag;
153
+		} else { // long-form identifier
154
+			$bytes[] = $byte | 0x1f;
155
+			$octets = [];
156
+			for (; $tag > 0; $tag >>= 7) {
157
+				array_push($octets, gmp_intval(0x80 | ($tag & 0x7f)));
158
+			}
159
+			// last octet has bit 8 set to zero
160
+			$octets[0] &= 0x7f;
161
+			foreach (array_reverse($octets) as $octet) {
162
+				$bytes[] = $octet;
163
+			}
164
+		}
165
+		return pack("C*", ...$bytes);
166
+	}
167 167
     
168
-    /**
169
-     * Get class of the type.
170
-     *
171
-     * @return int
172
-     */
173
-    public function typeClass(): int
174
-    {
175
-        return $this->_class;
176
-    }
168
+	/**
169
+	 * Get class of the type.
170
+	 *
171
+	 * @return int
172
+	 */
173
+	public function typeClass(): int
174
+	{
175
+		return $this->_class;
176
+	}
177 177
     
178
-    /**
179
-     * Get P/C.
180
-     *
181
-     * @return int
182
-     */
183
-    public function pc(): int
184
-    {
185
-        return $this->_pc;
186
-    }
178
+	/**
179
+	 * Get P/C.
180
+	 *
181
+	 * @return int
182
+	 */
183
+	public function pc(): int
184
+	{
185
+		return $this->_pc;
186
+	}
187 187
     
188
-    /**
189
-     * Get the tag number.
190
-     *
191
-     * @return string Base 10 integer string
192
-     */
193
-    public function tag(): string
194
-    {
195
-        return $this->_tag->base10();
196
-    }
188
+	/**
189
+	 * Get the tag number.
190
+	 *
191
+	 * @return string Base 10 integer string
192
+	 */
193
+	public function tag(): string
194
+	{
195
+		return $this->_tag->base10();
196
+	}
197 197
     
198
-    /**
199
-     * Get the tag as an integer.
200
-     *
201
-     * @return int
202
-     */
203
-    public function intTag(): int
204
-    {
205
-        return $this->_tag->intVal();
206
-    }
198
+	/**
199
+	 * Get the tag as an integer.
200
+	 *
201
+	 * @return int
202
+	 */
203
+	public function intTag(): int
204
+	{
205
+		return $this->_tag->intVal();
206
+	}
207 207
     
208
-    /**
209
-     * Check whether type is of an universal class.
210
-     *
211
-     * @return bool
212
-     */
213
-    public function isUniversal(): bool
214
-    {
215
-        return self::CLASS_UNIVERSAL == $this->_class;
216
-    }
208
+	/**
209
+	 * Check whether type is of an universal class.
210
+	 *
211
+	 * @return bool
212
+	 */
213
+	public function isUniversal(): bool
214
+	{
215
+		return self::CLASS_UNIVERSAL == $this->_class;
216
+	}
217 217
     
218
-    /**
219
-     * Check whether type is of an application class.
220
-     *
221
-     * @return bool
222
-     */
223
-    public function isApplication(): bool
224
-    {
225
-        return self::CLASS_APPLICATION == $this->_class;
226
-    }
218
+	/**
219
+	 * Check whether type is of an application class.
220
+	 *
221
+	 * @return bool
222
+	 */
223
+	public function isApplication(): bool
224
+	{
225
+		return self::CLASS_APPLICATION == $this->_class;
226
+	}
227 227
     
228
-    /**
229
-     * Check whether type is of a context specific class.
230
-     *
231
-     * @return bool
232
-     */
233
-    public function isContextSpecific(): bool
234
-    {
235
-        return self::CLASS_CONTEXT_SPECIFIC == $this->_class;
236
-    }
228
+	/**
229
+	 * Check whether type is of a context specific class.
230
+	 *
231
+	 * @return bool
232
+	 */
233
+	public function isContextSpecific(): bool
234
+	{
235
+		return self::CLASS_CONTEXT_SPECIFIC == $this->_class;
236
+	}
237 237
     
238
-    /**
239
-     * Check whether type is of a private class.
240
-     *
241
-     * @return bool
242
-     */
243
-    public function isPrivate(): bool
244
-    {
245
-        return self::CLASS_PRIVATE == $this->_class;
246
-    }
238
+	/**
239
+	 * Check whether type is of a private class.
240
+	 *
241
+	 * @return bool
242
+	 */
243
+	public function isPrivate(): bool
244
+	{
245
+		return self::CLASS_PRIVATE == $this->_class;
246
+	}
247 247
     
248
-    /**
249
-     * Check whether content is primitive type.
250
-     *
251
-     * @return bool
252
-     */
253
-    public function isPrimitive(): bool
254
-    {
255
-        return self::PRIMITIVE == $this->_pc;
256
-    }
248
+	/**
249
+	 * Check whether content is primitive type.
250
+	 *
251
+	 * @return bool
252
+	 */
253
+	public function isPrimitive(): bool
254
+	{
255
+		return self::PRIMITIVE == $this->_pc;
256
+	}
257 257
     
258
-    /**
259
-     * Check hether content is constructed type.
260
-     *
261
-     * @return bool
262
-     */
263
-    public function isConstructed(): bool
264
-    {
265
-        return self::CONSTRUCTED == $this->_pc;
266
-    }
258
+	/**
259
+	 * Check hether content is constructed type.
260
+	 *
261
+	 * @return bool
262
+	 */
263
+	public function isConstructed(): bool
264
+	{
265
+		return self::CONSTRUCTED == $this->_pc;
266
+	}
267 267
     
268
-    /**
269
-     * Get self with given type class.
270
-     *
271
-     * @param int $class One of <code>CLASS_*</code> enumerations
272
-     * @return self
273
-     */
274
-    public function withClass(int $class): Identifier
275
-    {
276
-        $obj = clone $this;
277
-        $obj->_class = 0b11 & $class;
278
-        return $obj;
279
-    }
268
+	/**
269
+	 * Get self with given type class.
270
+	 *
271
+	 * @param int $class One of <code>CLASS_*</code> enumerations
272
+	 * @return self
273
+	 */
274
+	public function withClass(int $class): Identifier
275
+	{
276
+		$obj = clone $this;
277
+		$obj->_class = 0b11 & $class;
278
+		return $obj;
279
+	}
280 280
     
281
-    /**
282
-     * Get self with given type tag.
283
-     *
284
-     * @param int|string $tag Tag number
285
-     * @return self
286
-     */
287
-    public function withTag($tag): Identifier
288
-    {
289
-        $obj = clone $this;
290
-        $obj->_tag = new BigInt($tag);
291
-        return $obj;
292
-    }
281
+	/**
282
+	 * Get self with given type tag.
283
+	 *
284
+	 * @param int|string $tag Tag number
285
+	 * @return self
286
+	 */
287
+	public function withTag($tag): Identifier
288
+	{
289
+		$obj = clone $this;
290
+		$obj->_tag = new BigInt($tag);
291
+		return $obj;
292
+	}
293 293
     
294
-    /**
295
-     * Get human readable name of the type class.
296
-     *
297
-     * @param int $class
298
-     * @return string
299
-     */
300
-    public static function classToName(int $class): string
301
-    {
302
-        if (!array_key_exists($class, self::MAP_CLASS_TO_NAME)) {
303
-            return "CLASS $class";
304
-        }
305
-        return self::MAP_CLASS_TO_NAME[$class];
306
-    }
294
+	/**
295
+	 * Get human readable name of the type class.
296
+	 *
297
+	 * @param int $class
298
+	 * @return string
299
+	 */
300
+	public static function classToName(int $class): string
301
+	{
302
+		if (!array_key_exists($class, self::MAP_CLASS_TO_NAME)) {
303
+			return "CLASS $class";
304
+		}
305
+		return self::MAP_CLASS_TO_NAME[$class];
306
+	}
307 307
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace ASN1\Component;
6 6
 
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
      *
27 27
      * @var array
28 28
      */
29
-    const MAP_CLASS_TO_NAME = [ /* @formatter:off */
29
+    const MAP_CLASS_TO_NAME = [/* @formatter:off */
30 30
         self::CLASS_UNIVERSAL => "UNIVERSAL", 
31 31
         self::CLASS_APPLICATION => "APPLICATION", 
32 32
         self::CLASS_CONTEXT_SPECIFIC => "CONTEXT SPECIFIC", 
Please login to merge, or discard this patch.
lib/ASN1/Feature/ElementBase.php 2 patches
Indentation   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -13,86 +13,86 @@
 block discarded – undo
13 13
  */
14 14
 interface ElementBase extends Encodable
15 15
 {
16
-    /**
17
-     * Get the class of the ASN.1 type.
18
-     *
19
-     * One of <code>Identifier::CLASS_*</code> constants.
20
-     *
21
-     * @return int
22
-     */
23
-    public function typeClass(): int;
16
+	/**
17
+	 * Get the class of the ASN.1 type.
18
+	 *
19
+	 * One of <code>Identifier::CLASS_*</code> constants.
20
+	 *
21
+	 * @return int
22
+	 */
23
+	public function typeClass(): int;
24 24
     
25
-    /**
26
-     * Check whether the element is constructed.
27
-     *
28
-     * Otherwise it's primitive.
29
-     *
30
-     * @return bool
31
-     */
32
-    public function isConstructed(): bool;
25
+	/**
26
+	 * Check whether the element is constructed.
27
+	 *
28
+	 * Otherwise it's primitive.
29
+	 *
30
+	 * @return bool
31
+	 */
32
+	public function isConstructed(): bool;
33 33
     
34
-    /**
35
-     * Get the tag of the element.
36
-     *
37
-     * Interpretation of the tag depends on the context. For example it may
38
-     * represent a universal type tag or a tag of an implicitly or explicitly
39
-     * tagged type.
40
-     *
41
-     * @return int
42
-     */
43
-    public function tag(): int;
34
+	/**
35
+	 * Get the tag of the element.
36
+	 *
37
+	 * Interpretation of the tag depends on the context. For example it may
38
+	 * represent a universal type tag or a tag of an implicitly or explicitly
39
+	 * tagged type.
40
+	 *
41
+	 * @return int
42
+	 */
43
+	public function tag(): int;
44 44
     
45
-    /**
46
-     * Check whether the element is a type of a given tag.
47
-     *
48
-     * @param int $tag Type tag
49
-     * @return bool
50
-     */
51
-    public function isType(int $tag): bool;
45
+	/**
46
+	 * Check whether the element is a type of a given tag.
47
+	 *
48
+	 * @param int $tag Type tag
49
+	 * @return bool
50
+	 */
51
+	public function isType(int $tag): bool;
52 52
     
53
-    /**
54
-     * Check whether the element is a type of a given tag.
55
-     *
56
-     * Throws an exception if expectation fails.
57
-     *
58
-     * @param int $tag Type tag
59
-     * @throws \UnexpectedValueException If the element type differs from the
60
-     *         expected
61
-     * @return ElementBase
62
-     */
63
-    public function expectType(int $tag): ElementBase;
53
+	/**
54
+	 * Check whether the element is a type of a given tag.
55
+	 *
56
+	 * Throws an exception if expectation fails.
57
+	 *
58
+	 * @param int $tag Type tag
59
+	 * @throws \UnexpectedValueException If the element type differs from the
60
+	 *         expected
61
+	 * @return ElementBase
62
+	 */
63
+	public function expectType(int $tag): ElementBase;
64 64
     
65
-    /**
66
-     * Check whether the element is tagged (context specific).
67
-     *
68
-     * @return bool
69
-     */
70
-    public function isTagged(): bool;
65
+	/**
66
+	 * Check whether the element is tagged (context specific).
67
+	 *
68
+	 * @return bool
69
+	 */
70
+	public function isTagged(): bool;
71 71
     
72
-    /**
73
-     * Check whether the element is tagged (context specific) and optionally has
74
-     * a given tag.
75
-     *
76
-     * Throws an exception if the element is not tagged or tag differs from
77
-     * the expected.
78
-     *
79
-     * @param int|null $tag Optional type tag
80
-     * @throws \UnexpectedValueException If expectation fails
81
-     * @return \ASN1\Type\TaggedType
82
-     */
83
-    public function expectTagged($tag = null): TaggedType;
72
+	/**
73
+	 * Check whether the element is tagged (context specific) and optionally has
74
+	 * a given tag.
75
+	 *
76
+	 * Throws an exception if the element is not tagged or tag differs from
77
+	 * the expected.
78
+	 *
79
+	 * @param int|null $tag Optional type tag
80
+	 * @throws \UnexpectedValueException If expectation fails
81
+	 * @return \ASN1\Type\TaggedType
82
+	 */
83
+	public function expectTagged($tag = null): TaggedType;
84 84
     
85
-    /**
86
-     * Get the object as an abstract Element instance.
87
-     *
88
-     * @return \ASN1\Element
89
-     */
90
-    public function asElement(): Element;
85
+	/**
86
+	 * Get the object as an abstract Element instance.
87
+	 *
88
+	 * @return \ASN1\Element
89
+	 */
90
+	public function asElement(): Element;
91 91
     
92
-    /**
93
-     * Get the object as an UnspecifiedType instance.
94
-     *
95
-     * @return UnspecifiedType
96
-     */
97
-    public function asUnspecified(): UnspecifiedType;
92
+	/**
93
+	 * Get the object as an UnspecifiedType instance.
94
+	 *
95
+	 * @return UnspecifiedType
96
+	 */
97
+	public function asUnspecified(): UnspecifiedType;
98 98
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace ASN1\Feature;
6 6
 
Please login to merge, or discard this patch.