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.
Completed
Push — master ( 584f81...7e40d7 )
by Joni
02:01
created
lib/ASN1/Type/UnspecifiedType.php 1 patch
Indentation   +630 added lines, -630 removed lines patch added patch discarded remove patch
@@ -17,634 +17,634 @@
 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 new self(Element::fromDER($data));
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 a boolean type.
93
-     *
94
-     * @throws \UnexpectedValueException If the element is not a boolean
95
-     * @return Primitive\Boolean
96
-     */
97
-    public function asBoolean(): Primitive\Boolean
98
-    {
99
-        if (!$this->_element instanceof Primitive\Boolean) {
100
-            throw new \UnexpectedValueException(
101
-                $this->_generateExceptionMessage(Element::TYPE_BOOLEAN));
102
-        }
103
-        return $this->_element;
104
-    }
105
-    
106
-    /**
107
-     * Get the wrapped element as an integer type.
108
-     *
109
-     * @throws \UnexpectedValueException If the element is not an integer
110
-     * @return Primitive\Integer
111
-     */
112
-    public function asInteger(): Primitive\Integer
113
-    {
114
-        if (!$this->_element instanceof Primitive\Integer) {
115
-            throw new \UnexpectedValueException(
116
-                $this->_generateExceptionMessage(Element::TYPE_INTEGER));
117
-        }
118
-        return $this->_element;
119
-    }
120
-    
121
-    /**
122
-     * Get the wrapped element as a bit string type.
123
-     *
124
-     * @throws \UnexpectedValueException If the element is not a bit string
125
-     * @return Primitive\BitString
126
-     */
127
-    public function asBitString(): Primitive\BitString
128
-    {
129
-        if (!$this->_element instanceof Primitive\BitString) {
130
-            throw new \UnexpectedValueException(
131
-                $this->_generateExceptionMessage(Element::TYPE_BIT_STRING));
132
-        }
133
-        return $this->_element;
134
-    }
135
-    
136
-    /**
137
-     * Get the wrapped element as an octet string type.
138
-     *
139
-     * @throws \UnexpectedValueException If the element is not an octet string
140
-     * @return Primitive\OctetString
141
-     */
142
-    public function asOctetString(): Primitive\OctetString
143
-    {
144
-        if (!$this->_element instanceof Primitive\OctetString) {
145
-            throw new \UnexpectedValueException(
146
-                $this->_generateExceptionMessage(Element::TYPE_OCTET_STRING));
147
-        }
148
-        return $this->_element;
149
-    }
150
-    
151
-    /**
152
-     * Get the wrapped element as a null type.
153
-     *
154
-     * @throws \UnexpectedValueException If the element is not a null
155
-     * @return Primitive\NullType
156
-     */
157
-    public function asNull(): Primitive\NullType
158
-    {
159
-        if (!$this->_element instanceof Primitive\NullType) {
160
-            throw new \UnexpectedValueException(
161
-                $this->_generateExceptionMessage(Element::TYPE_NULL));
162
-        }
163
-        return $this->_element;
164
-    }
165
-    
166
-    /**
167
-     * Get the wrapped element as an object identifier type.
168
-     *
169
-     * @throws \UnexpectedValueException If the element is not an object
170
-     *         identifier
171
-     * @return Primitive\ObjectIdentifier
172
-     */
173
-    public function asObjectIdentifier(): Primitive\ObjectIdentifier
174
-    {
175
-        if (!$this->_element instanceof Primitive\ObjectIdentifier) {
176
-            throw new \UnexpectedValueException(
177
-                $this->_generateExceptionMessage(
178
-                    Element::TYPE_OBJECT_IDENTIFIER));
179
-        }
180
-        return $this->_element;
181
-    }
182
-    
183
-    /**
184
-     * Get the wrapped element as an object descriptor type.
185
-     *
186
-     * @throws \UnexpectedValueException If the element is not an object
187
-     *         descriptor
188
-     * @return Primitive\ObjectDescriptor
189
-     */
190
-    public function asObjectDescriptor(): Primitive\ObjectDescriptor
191
-    {
192
-        if (!$this->_element instanceof Primitive\ObjectDescriptor) {
193
-            throw new \UnexpectedValueException(
194
-                $this->_generateExceptionMessage(
195
-                    Element::TYPE_OBJECT_DESCRIPTOR));
196
-        }
197
-        return $this->_element;
198
-    }
199
-    
200
-    /**
201
-     * Get the wrapped element as a real type.
202
-     *
203
-     * @throws \UnexpectedValueException If the element is not a real
204
-     * @return Primitive\Real
205
-     */
206
-    public function asReal(): Primitive\Real
207
-    {
208
-        if (!$this->_element instanceof Primitive\Real) {
209
-            throw new \UnexpectedValueException(
210
-                $this->_generateExceptionMessage(Element::TYPE_REAL));
211
-        }
212
-        return $this->_element;
213
-    }
214
-    
215
-    /**
216
-     * Get the wrapped element as an enumerated type.
217
-     *
218
-     * @throws \UnexpectedValueException If the element is not an enumerated
219
-     * @return Primitive\Enumerated
220
-     */
221
-    public function asEnumerated(): Primitive\Enumerated
222
-    {
223
-        if (!$this->_element instanceof Primitive\Enumerated) {
224
-            throw new \UnexpectedValueException(
225
-                $this->_generateExceptionMessage(Element::TYPE_ENUMERATED));
226
-        }
227
-        return $this->_element;
228
-    }
229
-    
230
-    /**
231
-     * Get the wrapped element as a UTF8 string type.
232
-     *
233
-     * @throws \UnexpectedValueException If the element is not a UTF8 string
234
-     * @return Primitive\UTF8String
235
-     */
236
-    public function asUTF8String(): Primitive\UTF8String
237
-    {
238
-        if (!$this->_element instanceof Primitive\UTF8String) {
239
-            throw new \UnexpectedValueException(
240
-                $this->_generateExceptionMessage(Element::TYPE_UTF8_STRING));
241
-        }
242
-        return $this->_element;
243
-    }
244
-    
245
-    /**
246
-     * Get the wrapped element as a relative OID type.
247
-     *
248
-     * @throws \UnexpectedValueException If the element is not a relative OID
249
-     * @return Primitive\RelativeOID
250
-     */
251
-    public function asRelativeOID(): Primitive\RelativeOID
252
-    {
253
-        if (!$this->_element instanceof Primitive\RelativeOID) {
254
-            throw new \UnexpectedValueException(
255
-                $this->_generateExceptionMessage(Element::TYPE_RELATIVE_OID));
256
-        }
257
-        return $this->_element;
258
-    }
259
-    
260
-    /**
261
-     * Get the wrapped element as a sequence type.
262
-     *
263
-     * @throws \UnexpectedValueException If the element is not a sequence
264
-     * @return Constructed\Sequence
265
-     */
266
-    public function asSequence(): Constructed\Sequence
267
-    {
268
-        if (!$this->_element instanceof Constructed\Sequence) {
269
-            throw new \UnexpectedValueException(
270
-                $this->_generateExceptionMessage(Element::TYPE_SEQUENCE));
271
-        }
272
-        return $this->_element;
273
-    }
274
-    
275
-    /**
276
-     * Get the wrapped element as a set type.
277
-     *
278
-     * @throws \UnexpectedValueException If the element is not a set
279
-     * @return Constructed\Set
280
-     */
281
-    public function asSet(): Constructed\Set
282
-    {
283
-        if (!$this->_element instanceof Constructed\Set) {
284
-            throw new \UnexpectedValueException(
285
-                $this->_generateExceptionMessage(Element::TYPE_SET));
286
-        }
287
-        return $this->_element;
288
-    }
289
-    
290
-    /**
291
-     * Get the wrapped element as a numeric string type.
292
-     *
293
-     * @throws \UnexpectedValueException If the element is not a numeric string
294
-     * @return Primitive\NumericString
295
-     */
296
-    public function asNumericString(): Primitive\NumericString
297
-    {
298
-        if (!$this->_element instanceof Primitive\NumericString) {
299
-            throw new \UnexpectedValueException(
300
-                $this->_generateExceptionMessage(Element::TYPE_NUMERIC_STRING));
301
-        }
302
-        return $this->_element;
303
-    }
304
-    
305
-    /**
306
-     * Get the wrapped element as a printable string type.
307
-     *
308
-     * @throws \UnexpectedValueException If the element is not a printable
309
-     *         string
310
-     * @return Primitive\PrintableString
311
-     */
312
-    public function asPrintableString(): Primitive\PrintableString
313
-    {
314
-        if (!$this->_element instanceof Primitive\PrintableString) {
315
-            throw new \UnexpectedValueException(
316
-                $this->_generateExceptionMessage(Element::TYPE_PRINTABLE_STRING));
317
-        }
318
-        return $this->_element;
319
-    }
320
-    
321
-    /**
322
-     * Get the wrapped element as a T61 string type.
323
-     *
324
-     * @throws \UnexpectedValueException If the element is not a T61 string
325
-     * @return Primitive\T61String
326
-     */
327
-    public function asT61String(): Primitive\T61String
328
-    {
329
-        if (!$this->_element instanceof Primitive\T61String) {
330
-            throw new \UnexpectedValueException(
331
-                $this->_generateExceptionMessage(Element::TYPE_T61_STRING));
332
-        }
333
-        return $this->_element;
334
-    }
335
-    
336
-    /**
337
-     * Get the wrapped element as a videotex string type.
338
-     *
339
-     * @throws \UnexpectedValueException If the element is not a videotex string
340
-     * @return Primitive\VideotexString
341
-     */
342
-    public function asVideotexString(): Primitive\VideotexString
343
-    {
344
-        if (!$this->_element instanceof Primitive\VideotexString) {
345
-            throw new \UnexpectedValueException(
346
-                $this->_generateExceptionMessage(Element::TYPE_VIDEOTEX_STRING));
347
-        }
348
-        return $this->_element;
349
-    }
350
-    
351
-    /**
352
-     * Get the wrapped element as a IA5 string type.
353
-     *
354
-     * @throws \UnexpectedValueException If the element is not a IA5 string
355
-     * @return Primitive\IA5String
356
-     */
357
-    public function asIA5String(): Primitive\IA5String
358
-    {
359
-        if (!$this->_element instanceof Primitive\IA5String) {
360
-            throw new \UnexpectedValueException(
361
-                $this->_generateExceptionMessage(Element::TYPE_IA5_STRING));
362
-        }
363
-        return $this->_element;
364
-    }
365
-    
366
-    /**
367
-     * Get the wrapped element as an UTC time type.
368
-     *
369
-     * @throws \UnexpectedValueException If the element is not a UTC time
370
-     * @return Primitive\UTCTime
371
-     */
372
-    public function asUTCTime(): Primitive\UTCTime
373
-    {
374
-        if (!$this->_element instanceof Primitive\UTCTime) {
375
-            throw new \UnexpectedValueException(
376
-                $this->_generateExceptionMessage(Element::TYPE_UTC_TIME));
377
-        }
378
-        return $this->_element;
379
-    }
380
-    
381
-    /**
382
-     * Get the wrapped element as a generalized time type.
383
-     *
384
-     * @throws \UnexpectedValueException If the element is not a generalized
385
-     *         time
386
-     * @return Primitive\GeneralizedTime
387
-     */
388
-    public function asGeneralizedTime(): Primitive\GeneralizedTime
389
-    {
390
-        if (!$this->_element instanceof Primitive\GeneralizedTime) {
391
-            throw new \UnexpectedValueException(
392
-                $this->_generateExceptionMessage(Element::TYPE_GENERALIZED_TIME));
393
-        }
394
-        return $this->_element;
395
-    }
396
-    
397
-    /**
398
-     * Get the wrapped element as a graphic string type.
399
-     *
400
-     * @throws \UnexpectedValueException If the element is not a graphic string
401
-     * @return Primitive\GraphicString
402
-     */
403
-    public function asGraphicString(): Primitive\GraphicString
404
-    {
405
-        if (!$this->_element instanceof Primitive\GraphicString) {
406
-            throw new \UnexpectedValueException(
407
-                $this->_generateExceptionMessage(Element::TYPE_GRAPHIC_STRING));
408
-        }
409
-        return $this->_element;
410
-    }
411
-    
412
-    /**
413
-     * Get the wrapped element as a visible string type.
414
-     *
415
-     * @throws \UnexpectedValueException If the element is not a visible string
416
-     * @return Primitive\VisibleString
417
-     */
418
-    public function asVisibleString(): Primitive\VisibleString
419
-    {
420
-        if (!$this->_element instanceof Primitive\VisibleString) {
421
-            throw new \UnexpectedValueException(
422
-                $this->_generateExceptionMessage(Element::TYPE_VISIBLE_STRING));
423
-        }
424
-        return $this->_element;
425
-    }
426
-    
427
-    /**
428
-     * Get the wrapped element as a general string type.
429
-     *
430
-     * @throws \UnexpectedValueException If the element is not general string
431
-     * @return Primitive\GeneralString
432
-     */
433
-    public function asGeneralString(): Primitive\GeneralString
434
-    {
435
-        if (!$this->_element instanceof Primitive\GeneralString) {
436
-            throw new \UnexpectedValueException(
437
-                $this->_generateExceptionMessage(Element::TYPE_GENERAL_STRING));
438
-        }
439
-        return $this->_element;
440
-    }
441
-    
442
-    /**
443
-     * Get the wrapped element as a universal string type.
444
-     *
445
-     * @throws \UnexpectedValueException If the element is not a universal
446
-     *         string
447
-     * @return Primitive\UniversalString
448
-     */
449
-    public function asUniversalString(): Primitive\UniversalString
450
-    {
451
-        if (!$this->_element instanceof Primitive\UniversalString) {
452
-            throw new \UnexpectedValueException(
453
-                $this->_generateExceptionMessage(Element::TYPE_UNIVERSAL_STRING));
454
-        }
455
-        return $this->_element;
456
-    }
457
-    
458
-    /**
459
-     * Get the wrapped element as a character string type.
460
-     *
461
-     * @throws \UnexpectedValueException If the element is not a character
462
-     *         string
463
-     * @return Primitive\CharacterString
464
-     */
465
-    public function asCharacterString(): Primitive\CharacterString
466
-    {
467
-        if (!$this->_element instanceof Primitive\CharacterString) {
468
-            throw new \UnexpectedValueException(
469
-                $this->_generateExceptionMessage(Element::TYPE_CHARACTER_STRING));
470
-        }
471
-        return $this->_element;
472
-    }
473
-    
474
-    /**
475
-     * Get the wrapped element as a BMP string type.
476
-     *
477
-     * @throws \UnexpectedValueException If the element is not a bmp string
478
-     * @return Primitive\BMPString
479
-     */
480
-    public function asBMPString(): Primitive\BMPString
481
-    {
482
-        if (!$this->_element instanceof Primitive\BMPString) {
483
-            throw new \UnexpectedValueException(
484
-                $this->_generateExceptionMessage(Element::TYPE_BMP_STRING));
485
-        }
486
-        return $this->_element;
487
-    }
488
-    
489
-    /**
490
-     * Get the wrapped element as any string type.
491
-     *
492
-     * @throws \UnexpectedValueException If the element is not a string
493
-     * @return StringType
494
-     */
495
-    public function asString(): StringType
496
-    {
497
-        if (!$this->_element instanceof StringType) {
498
-            throw new \UnexpectedValueException(
499
-                $this->_generateExceptionMessage(Element::TYPE_STRING));
500
-        }
501
-        return $this->_element;
502
-    }
503
-    
504
-    /**
505
-     * Get the wrapped element as any time type.
506
-     *
507
-     * @throws \UnexpectedValueException If the element is not a time
508
-     * @return TimeType
509
-     */
510
-    public function asTime(): TimeType
511
-    {
512
-        if (!$this->_element instanceof TimeType) {
513
-            throw new \UnexpectedValueException(
514
-                $this->_generateExceptionMessage(Element::TYPE_TIME));
515
-        }
516
-        return $this->_element;
517
-    }
518
-    
519
-    /**
520
-     * Generate message for exceptions thrown by <code>as*</code> methods.
521
-     *
522
-     * @param int $tag Type tag of the expected element
523
-     * @return string
524
-     */
525
-    private function _generateExceptionMessage(int $tag): string
526
-    {
527
-        return sprintf("%s expected, got %s.", Element::tagToName($tag),
528
-            $this->_typeDescriptorString());
529
-    }
530
-    
531
-    /**
532
-     * Get textual description of the wrapped element for debugging purposes.
533
-     *
534
-     * @return string
535
-     */
536
-    private function _typeDescriptorString(): string
537
-    {
538
-        $type_cls = $this->_element->typeClass();
539
-        $tag = $this->_element->tag();
540
-        if ($type_cls == Identifier::CLASS_UNIVERSAL) {
541
-            return Element::tagToName($tag);
542
-        }
543
-        return Identifier::classToName($type_cls) . " TAG $tag";
544
-    }
545
-    
546
-    /**
547
-     *
548
-     * @see \ASN1\Feature\Encodable::toDER()
549
-     * @return string
550
-     */
551
-    public function toDER(): string
552
-    {
553
-        return $this->_element->toDER();
554
-    }
555
-    
556
-    /**
557
-     *
558
-     * @see \ASN1\Feature\ElementBase::typeClass()
559
-     * @return int
560
-     */
561
-    public function typeClass(): int
562
-    {
563
-        return $this->_element->typeClass();
564
-    }
565
-    
566
-    /**
567
-     *
568
-     * @see \ASN1\Feature\ElementBase::isConstructed()
569
-     * @return bool
570
-     */
571
-    public function isConstructed(): bool
572
-    {
573
-        return $this->_element->isConstructed();
574
-    }
575
-    
576
-    /**
577
-     *
578
-     * @see \ASN1\Feature\ElementBase::tag()
579
-     * @return int
580
-     */
581
-    public function tag(): int
582
-    {
583
-        return $this->_element->tag();
584
-    }
585
-    
586
-    /**
587
-     *
588
-     * {@inheritdoc}
589
-     * @see \ASN1\Feature\ElementBase::isType()
590
-     * @return bool
591
-     */
592
-    public function isType(int $tag): bool
593
-    {
594
-        return $this->_element->isType($tag);
595
-    }
596
-    
597
-    /**
598
-     *
599
-     * @deprecated Use any <code>as*</code> accessor method first to ensure
600
-     *             type strictness.
601
-     * @see \ASN1\Feature\ElementBase::expectType()
602
-     * @return ElementBase
603
-     */
604
-    public function expectType(int $tag): ElementBase
605
-    {
606
-        return $this->_element->expectType($tag);
607
-    }
608
-    
609
-    /**
610
-     *
611
-     * @see \ASN1\Feature\ElementBase::isTagged()
612
-     * @return bool
613
-     */
614
-    public function isTagged(): bool
615
-    {
616
-        return $this->_element->isTagged();
617
-    }
618
-    
619
-    /**
620
-     *
621
-     * @deprecated Use any <code>as*</code> accessor method first to ensure
622
-     *             type strictness.
623
-     * @see \ASN1\Feature\ElementBase::expectTagged()
624
-     * @return TaggedType
625
-     */
626
-    public function expectTagged($tag = null): TaggedType
627
-    {
628
-        return $this->_element->expectTagged($tag);
629
-    }
630
-    
631
-    /**
632
-     *
633
-     * @see \ASN1\Feature\ElementBase::asElement()
634
-     * @return Element
635
-     */
636
-    public function asElement(): Element
637
-    {
638
-        return $this->_element;
639
-    }
640
-    
641
-    /**
642
-     *
643
-     * {@inheritdoc}
644
-     * @return UnspecifiedType
645
-     */
646
-    public function asUnspecified(): UnspecifiedType
647
-    {
648
-        return $this;
649
-    }
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 new self(Element::fromDER($data));
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 a boolean type.
93
+	 *
94
+	 * @throws \UnexpectedValueException If the element is not a boolean
95
+	 * @return Primitive\Boolean
96
+	 */
97
+	public function asBoolean(): Primitive\Boolean
98
+	{
99
+		if (!$this->_element instanceof Primitive\Boolean) {
100
+			throw new \UnexpectedValueException(
101
+				$this->_generateExceptionMessage(Element::TYPE_BOOLEAN));
102
+		}
103
+		return $this->_element;
104
+	}
105
+    
106
+	/**
107
+	 * Get the wrapped element as an integer type.
108
+	 *
109
+	 * @throws \UnexpectedValueException If the element is not an integer
110
+	 * @return Primitive\Integer
111
+	 */
112
+	public function asInteger(): Primitive\Integer
113
+	{
114
+		if (!$this->_element instanceof Primitive\Integer) {
115
+			throw new \UnexpectedValueException(
116
+				$this->_generateExceptionMessage(Element::TYPE_INTEGER));
117
+		}
118
+		return $this->_element;
119
+	}
120
+    
121
+	/**
122
+	 * Get the wrapped element as a bit string type.
123
+	 *
124
+	 * @throws \UnexpectedValueException If the element is not a bit string
125
+	 * @return Primitive\BitString
126
+	 */
127
+	public function asBitString(): Primitive\BitString
128
+	{
129
+		if (!$this->_element instanceof Primitive\BitString) {
130
+			throw new \UnexpectedValueException(
131
+				$this->_generateExceptionMessage(Element::TYPE_BIT_STRING));
132
+		}
133
+		return $this->_element;
134
+	}
135
+    
136
+	/**
137
+	 * Get the wrapped element as an octet string type.
138
+	 *
139
+	 * @throws \UnexpectedValueException If the element is not an octet string
140
+	 * @return Primitive\OctetString
141
+	 */
142
+	public function asOctetString(): Primitive\OctetString
143
+	{
144
+		if (!$this->_element instanceof Primitive\OctetString) {
145
+			throw new \UnexpectedValueException(
146
+				$this->_generateExceptionMessage(Element::TYPE_OCTET_STRING));
147
+		}
148
+		return $this->_element;
149
+	}
150
+    
151
+	/**
152
+	 * Get the wrapped element as a null type.
153
+	 *
154
+	 * @throws \UnexpectedValueException If the element is not a null
155
+	 * @return Primitive\NullType
156
+	 */
157
+	public function asNull(): Primitive\NullType
158
+	{
159
+		if (!$this->_element instanceof Primitive\NullType) {
160
+			throw new \UnexpectedValueException(
161
+				$this->_generateExceptionMessage(Element::TYPE_NULL));
162
+		}
163
+		return $this->_element;
164
+	}
165
+    
166
+	/**
167
+	 * Get the wrapped element as an object identifier type.
168
+	 *
169
+	 * @throws \UnexpectedValueException If the element is not an object
170
+	 *         identifier
171
+	 * @return Primitive\ObjectIdentifier
172
+	 */
173
+	public function asObjectIdentifier(): Primitive\ObjectIdentifier
174
+	{
175
+		if (!$this->_element instanceof Primitive\ObjectIdentifier) {
176
+			throw new \UnexpectedValueException(
177
+				$this->_generateExceptionMessage(
178
+					Element::TYPE_OBJECT_IDENTIFIER));
179
+		}
180
+		return $this->_element;
181
+	}
182
+    
183
+	/**
184
+	 * Get the wrapped element as an object descriptor type.
185
+	 *
186
+	 * @throws \UnexpectedValueException If the element is not an object
187
+	 *         descriptor
188
+	 * @return Primitive\ObjectDescriptor
189
+	 */
190
+	public function asObjectDescriptor(): Primitive\ObjectDescriptor
191
+	{
192
+		if (!$this->_element instanceof Primitive\ObjectDescriptor) {
193
+			throw new \UnexpectedValueException(
194
+				$this->_generateExceptionMessage(
195
+					Element::TYPE_OBJECT_DESCRIPTOR));
196
+		}
197
+		return $this->_element;
198
+	}
199
+    
200
+	/**
201
+	 * Get the wrapped element as a real type.
202
+	 *
203
+	 * @throws \UnexpectedValueException If the element is not a real
204
+	 * @return Primitive\Real
205
+	 */
206
+	public function asReal(): Primitive\Real
207
+	{
208
+		if (!$this->_element instanceof Primitive\Real) {
209
+			throw new \UnexpectedValueException(
210
+				$this->_generateExceptionMessage(Element::TYPE_REAL));
211
+		}
212
+		return $this->_element;
213
+	}
214
+    
215
+	/**
216
+	 * Get the wrapped element as an enumerated type.
217
+	 *
218
+	 * @throws \UnexpectedValueException If the element is not an enumerated
219
+	 * @return Primitive\Enumerated
220
+	 */
221
+	public function asEnumerated(): Primitive\Enumerated
222
+	{
223
+		if (!$this->_element instanceof Primitive\Enumerated) {
224
+			throw new \UnexpectedValueException(
225
+				$this->_generateExceptionMessage(Element::TYPE_ENUMERATED));
226
+		}
227
+		return $this->_element;
228
+	}
229
+    
230
+	/**
231
+	 * Get the wrapped element as a UTF8 string type.
232
+	 *
233
+	 * @throws \UnexpectedValueException If the element is not a UTF8 string
234
+	 * @return Primitive\UTF8String
235
+	 */
236
+	public function asUTF8String(): Primitive\UTF8String
237
+	{
238
+		if (!$this->_element instanceof Primitive\UTF8String) {
239
+			throw new \UnexpectedValueException(
240
+				$this->_generateExceptionMessage(Element::TYPE_UTF8_STRING));
241
+		}
242
+		return $this->_element;
243
+	}
244
+    
245
+	/**
246
+	 * Get the wrapped element as a relative OID type.
247
+	 *
248
+	 * @throws \UnexpectedValueException If the element is not a relative OID
249
+	 * @return Primitive\RelativeOID
250
+	 */
251
+	public function asRelativeOID(): Primitive\RelativeOID
252
+	{
253
+		if (!$this->_element instanceof Primitive\RelativeOID) {
254
+			throw new \UnexpectedValueException(
255
+				$this->_generateExceptionMessage(Element::TYPE_RELATIVE_OID));
256
+		}
257
+		return $this->_element;
258
+	}
259
+    
260
+	/**
261
+	 * Get the wrapped element as a sequence type.
262
+	 *
263
+	 * @throws \UnexpectedValueException If the element is not a sequence
264
+	 * @return Constructed\Sequence
265
+	 */
266
+	public function asSequence(): Constructed\Sequence
267
+	{
268
+		if (!$this->_element instanceof Constructed\Sequence) {
269
+			throw new \UnexpectedValueException(
270
+				$this->_generateExceptionMessage(Element::TYPE_SEQUENCE));
271
+		}
272
+		return $this->_element;
273
+	}
274
+    
275
+	/**
276
+	 * Get the wrapped element as a set type.
277
+	 *
278
+	 * @throws \UnexpectedValueException If the element is not a set
279
+	 * @return Constructed\Set
280
+	 */
281
+	public function asSet(): Constructed\Set
282
+	{
283
+		if (!$this->_element instanceof Constructed\Set) {
284
+			throw new \UnexpectedValueException(
285
+				$this->_generateExceptionMessage(Element::TYPE_SET));
286
+		}
287
+		return $this->_element;
288
+	}
289
+    
290
+	/**
291
+	 * Get the wrapped element as a numeric string type.
292
+	 *
293
+	 * @throws \UnexpectedValueException If the element is not a numeric string
294
+	 * @return Primitive\NumericString
295
+	 */
296
+	public function asNumericString(): Primitive\NumericString
297
+	{
298
+		if (!$this->_element instanceof Primitive\NumericString) {
299
+			throw new \UnexpectedValueException(
300
+				$this->_generateExceptionMessage(Element::TYPE_NUMERIC_STRING));
301
+		}
302
+		return $this->_element;
303
+	}
304
+    
305
+	/**
306
+	 * Get the wrapped element as a printable string type.
307
+	 *
308
+	 * @throws \UnexpectedValueException If the element is not a printable
309
+	 *         string
310
+	 * @return Primitive\PrintableString
311
+	 */
312
+	public function asPrintableString(): Primitive\PrintableString
313
+	{
314
+		if (!$this->_element instanceof Primitive\PrintableString) {
315
+			throw new \UnexpectedValueException(
316
+				$this->_generateExceptionMessage(Element::TYPE_PRINTABLE_STRING));
317
+		}
318
+		return $this->_element;
319
+	}
320
+    
321
+	/**
322
+	 * Get the wrapped element as a T61 string type.
323
+	 *
324
+	 * @throws \UnexpectedValueException If the element is not a T61 string
325
+	 * @return Primitive\T61String
326
+	 */
327
+	public function asT61String(): Primitive\T61String
328
+	{
329
+		if (!$this->_element instanceof Primitive\T61String) {
330
+			throw new \UnexpectedValueException(
331
+				$this->_generateExceptionMessage(Element::TYPE_T61_STRING));
332
+		}
333
+		return $this->_element;
334
+	}
335
+    
336
+	/**
337
+	 * Get the wrapped element as a videotex string type.
338
+	 *
339
+	 * @throws \UnexpectedValueException If the element is not a videotex string
340
+	 * @return Primitive\VideotexString
341
+	 */
342
+	public function asVideotexString(): Primitive\VideotexString
343
+	{
344
+		if (!$this->_element instanceof Primitive\VideotexString) {
345
+			throw new \UnexpectedValueException(
346
+				$this->_generateExceptionMessage(Element::TYPE_VIDEOTEX_STRING));
347
+		}
348
+		return $this->_element;
349
+	}
350
+    
351
+	/**
352
+	 * Get the wrapped element as a IA5 string type.
353
+	 *
354
+	 * @throws \UnexpectedValueException If the element is not a IA5 string
355
+	 * @return Primitive\IA5String
356
+	 */
357
+	public function asIA5String(): Primitive\IA5String
358
+	{
359
+		if (!$this->_element instanceof Primitive\IA5String) {
360
+			throw new \UnexpectedValueException(
361
+				$this->_generateExceptionMessage(Element::TYPE_IA5_STRING));
362
+		}
363
+		return $this->_element;
364
+	}
365
+    
366
+	/**
367
+	 * Get the wrapped element as an UTC time type.
368
+	 *
369
+	 * @throws \UnexpectedValueException If the element is not a UTC time
370
+	 * @return Primitive\UTCTime
371
+	 */
372
+	public function asUTCTime(): Primitive\UTCTime
373
+	{
374
+		if (!$this->_element instanceof Primitive\UTCTime) {
375
+			throw new \UnexpectedValueException(
376
+				$this->_generateExceptionMessage(Element::TYPE_UTC_TIME));
377
+		}
378
+		return $this->_element;
379
+	}
380
+    
381
+	/**
382
+	 * Get the wrapped element as a generalized time type.
383
+	 *
384
+	 * @throws \UnexpectedValueException If the element is not a generalized
385
+	 *         time
386
+	 * @return Primitive\GeneralizedTime
387
+	 */
388
+	public function asGeneralizedTime(): Primitive\GeneralizedTime
389
+	{
390
+		if (!$this->_element instanceof Primitive\GeneralizedTime) {
391
+			throw new \UnexpectedValueException(
392
+				$this->_generateExceptionMessage(Element::TYPE_GENERALIZED_TIME));
393
+		}
394
+		return $this->_element;
395
+	}
396
+    
397
+	/**
398
+	 * Get the wrapped element as a graphic string type.
399
+	 *
400
+	 * @throws \UnexpectedValueException If the element is not a graphic string
401
+	 * @return Primitive\GraphicString
402
+	 */
403
+	public function asGraphicString(): Primitive\GraphicString
404
+	{
405
+		if (!$this->_element instanceof Primitive\GraphicString) {
406
+			throw new \UnexpectedValueException(
407
+				$this->_generateExceptionMessage(Element::TYPE_GRAPHIC_STRING));
408
+		}
409
+		return $this->_element;
410
+	}
411
+    
412
+	/**
413
+	 * Get the wrapped element as a visible string type.
414
+	 *
415
+	 * @throws \UnexpectedValueException If the element is not a visible string
416
+	 * @return Primitive\VisibleString
417
+	 */
418
+	public function asVisibleString(): Primitive\VisibleString
419
+	{
420
+		if (!$this->_element instanceof Primitive\VisibleString) {
421
+			throw new \UnexpectedValueException(
422
+				$this->_generateExceptionMessage(Element::TYPE_VISIBLE_STRING));
423
+		}
424
+		return $this->_element;
425
+	}
426
+    
427
+	/**
428
+	 * Get the wrapped element as a general string type.
429
+	 *
430
+	 * @throws \UnexpectedValueException If the element is not general string
431
+	 * @return Primitive\GeneralString
432
+	 */
433
+	public function asGeneralString(): Primitive\GeneralString
434
+	{
435
+		if (!$this->_element instanceof Primitive\GeneralString) {
436
+			throw new \UnexpectedValueException(
437
+				$this->_generateExceptionMessage(Element::TYPE_GENERAL_STRING));
438
+		}
439
+		return $this->_element;
440
+	}
441
+    
442
+	/**
443
+	 * Get the wrapped element as a universal string type.
444
+	 *
445
+	 * @throws \UnexpectedValueException If the element is not a universal
446
+	 *         string
447
+	 * @return Primitive\UniversalString
448
+	 */
449
+	public function asUniversalString(): Primitive\UniversalString
450
+	{
451
+		if (!$this->_element instanceof Primitive\UniversalString) {
452
+			throw new \UnexpectedValueException(
453
+				$this->_generateExceptionMessage(Element::TYPE_UNIVERSAL_STRING));
454
+		}
455
+		return $this->_element;
456
+	}
457
+    
458
+	/**
459
+	 * Get the wrapped element as a character string type.
460
+	 *
461
+	 * @throws \UnexpectedValueException If the element is not a character
462
+	 *         string
463
+	 * @return Primitive\CharacterString
464
+	 */
465
+	public function asCharacterString(): Primitive\CharacterString
466
+	{
467
+		if (!$this->_element instanceof Primitive\CharacterString) {
468
+			throw new \UnexpectedValueException(
469
+				$this->_generateExceptionMessage(Element::TYPE_CHARACTER_STRING));
470
+		}
471
+		return $this->_element;
472
+	}
473
+    
474
+	/**
475
+	 * Get the wrapped element as a BMP string type.
476
+	 *
477
+	 * @throws \UnexpectedValueException If the element is not a bmp string
478
+	 * @return Primitive\BMPString
479
+	 */
480
+	public function asBMPString(): Primitive\BMPString
481
+	{
482
+		if (!$this->_element instanceof Primitive\BMPString) {
483
+			throw new \UnexpectedValueException(
484
+				$this->_generateExceptionMessage(Element::TYPE_BMP_STRING));
485
+		}
486
+		return $this->_element;
487
+	}
488
+    
489
+	/**
490
+	 * Get the wrapped element as any string type.
491
+	 *
492
+	 * @throws \UnexpectedValueException If the element is not a string
493
+	 * @return StringType
494
+	 */
495
+	public function asString(): StringType
496
+	{
497
+		if (!$this->_element instanceof StringType) {
498
+			throw new \UnexpectedValueException(
499
+				$this->_generateExceptionMessage(Element::TYPE_STRING));
500
+		}
501
+		return $this->_element;
502
+	}
503
+    
504
+	/**
505
+	 * Get the wrapped element as any time type.
506
+	 *
507
+	 * @throws \UnexpectedValueException If the element is not a time
508
+	 * @return TimeType
509
+	 */
510
+	public function asTime(): TimeType
511
+	{
512
+		if (!$this->_element instanceof TimeType) {
513
+			throw new \UnexpectedValueException(
514
+				$this->_generateExceptionMessage(Element::TYPE_TIME));
515
+		}
516
+		return $this->_element;
517
+	}
518
+    
519
+	/**
520
+	 * Generate message for exceptions thrown by <code>as*</code> methods.
521
+	 *
522
+	 * @param int $tag Type tag of the expected element
523
+	 * @return string
524
+	 */
525
+	private function _generateExceptionMessage(int $tag): string
526
+	{
527
+		return sprintf("%s expected, got %s.", Element::tagToName($tag),
528
+			$this->_typeDescriptorString());
529
+	}
530
+    
531
+	/**
532
+	 * Get textual description of the wrapped element for debugging purposes.
533
+	 *
534
+	 * @return string
535
+	 */
536
+	private function _typeDescriptorString(): string
537
+	{
538
+		$type_cls = $this->_element->typeClass();
539
+		$tag = $this->_element->tag();
540
+		if ($type_cls == Identifier::CLASS_UNIVERSAL) {
541
+			return Element::tagToName($tag);
542
+		}
543
+		return Identifier::classToName($type_cls) . " TAG $tag";
544
+	}
545
+    
546
+	/**
547
+	 *
548
+	 * @see \ASN1\Feature\Encodable::toDER()
549
+	 * @return string
550
+	 */
551
+	public function toDER(): string
552
+	{
553
+		return $this->_element->toDER();
554
+	}
555
+    
556
+	/**
557
+	 *
558
+	 * @see \ASN1\Feature\ElementBase::typeClass()
559
+	 * @return int
560
+	 */
561
+	public function typeClass(): int
562
+	{
563
+		return $this->_element->typeClass();
564
+	}
565
+    
566
+	/**
567
+	 *
568
+	 * @see \ASN1\Feature\ElementBase::isConstructed()
569
+	 * @return bool
570
+	 */
571
+	public function isConstructed(): bool
572
+	{
573
+		return $this->_element->isConstructed();
574
+	}
575
+    
576
+	/**
577
+	 *
578
+	 * @see \ASN1\Feature\ElementBase::tag()
579
+	 * @return int
580
+	 */
581
+	public function tag(): int
582
+	{
583
+		return $this->_element->tag();
584
+	}
585
+    
586
+	/**
587
+	 *
588
+	 * {@inheritdoc}
589
+	 * @see \ASN1\Feature\ElementBase::isType()
590
+	 * @return bool
591
+	 */
592
+	public function isType(int $tag): bool
593
+	{
594
+		return $this->_element->isType($tag);
595
+	}
596
+    
597
+	/**
598
+	 *
599
+	 * @deprecated Use any <code>as*</code> accessor method first to ensure
600
+	 *             type strictness.
601
+	 * @see \ASN1\Feature\ElementBase::expectType()
602
+	 * @return ElementBase
603
+	 */
604
+	public function expectType(int $tag): ElementBase
605
+	{
606
+		return $this->_element->expectType($tag);
607
+	}
608
+    
609
+	/**
610
+	 *
611
+	 * @see \ASN1\Feature\ElementBase::isTagged()
612
+	 * @return bool
613
+	 */
614
+	public function isTagged(): bool
615
+	{
616
+		return $this->_element->isTagged();
617
+	}
618
+    
619
+	/**
620
+	 *
621
+	 * @deprecated Use any <code>as*</code> accessor method first to ensure
622
+	 *             type strictness.
623
+	 * @see \ASN1\Feature\ElementBase::expectTagged()
624
+	 * @return TaggedType
625
+	 */
626
+	public function expectTagged($tag = null): TaggedType
627
+	{
628
+		return $this->_element->expectTagged($tag);
629
+	}
630
+    
631
+	/**
632
+	 *
633
+	 * @see \ASN1\Feature\ElementBase::asElement()
634
+	 * @return Element
635
+	 */
636
+	public function asElement(): Element
637
+	{
638
+		return $this->_element;
639
+	}
640
+    
641
+	/**
642
+	 *
643
+	 * {@inheritdoc}
644
+	 * @return UnspecifiedType
645
+	 */
646
+	public function asUnspecified(): UnspecifiedType
647
+	{
648
+		return $this;
649
+	}
650 650
 }
Please login to merge, or discard this patch.
lib/ASN1/Feature/ElementBase.php 1 patch
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 boolean
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 boolean
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.
lib/ASN1/Element.php 2 patches
Indentation   +408 added lines, -408 removed lines patch added patch discarded remove patch
@@ -20,436 +20,436 @@
 block discarded – undo
20 20
  */
21 21
 abstract class Element implements ElementBase
22 22
 {
23
-    // Universal type tags
24
-    const TYPE_EOC = 0x00;
25
-    const TYPE_BOOLEAN = 0x01;
26
-    const TYPE_INTEGER = 0x02;
27
-    const TYPE_BIT_STRING = 0x03;
28
-    const TYPE_OCTET_STRING = 0x04;
29
-    const TYPE_NULL = 0x05;
30
-    const TYPE_OBJECT_IDENTIFIER = 0x06;
31
-    const TYPE_OBJECT_DESCRIPTOR = 0x07;
32
-    const TYPE_EXTERNAL = 0x08;
33
-    const TYPE_REAL = 0x09;
34
-    const TYPE_ENUMERATED = 0x0a;
35
-    const TYPE_EMBEDDED_PDV = 0x0b;
36
-    const TYPE_UTF8_STRING = 0x0c;
37
-    const TYPE_RELATIVE_OID = 0x0d;
38
-    const TYPE_SEQUENCE = 0x10;
39
-    const TYPE_SET = 0x11;
40
-    const TYPE_NUMERIC_STRING = 0x12;
41
-    const TYPE_PRINTABLE_STRING = 0x13;
42
-    const TYPE_T61_STRING = 0x14;
43
-    const TYPE_VIDEOTEX_STRING = 0x15;
44
-    const TYPE_IA5_STRING = 0x16;
45
-    const TYPE_UTC_TIME = 0x17;
46
-    const TYPE_GENERALIZED_TIME = 0x18;
47
-    const TYPE_GRAPHIC_STRING = 0x19;
48
-    const TYPE_VISIBLE_STRING = 0x1a;
49
-    const TYPE_GENERAL_STRING = 0x1b;
50
-    const TYPE_UNIVERSAL_STRING = 0x1c;
51
-    const TYPE_CHARACTER_STRING = 0x1d;
52
-    const TYPE_BMP_STRING = 0x1e;
23
+	// Universal type tags
24
+	const TYPE_EOC = 0x00;
25
+	const TYPE_BOOLEAN = 0x01;
26
+	const TYPE_INTEGER = 0x02;
27
+	const TYPE_BIT_STRING = 0x03;
28
+	const TYPE_OCTET_STRING = 0x04;
29
+	const TYPE_NULL = 0x05;
30
+	const TYPE_OBJECT_IDENTIFIER = 0x06;
31
+	const TYPE_OBJECT_DESCRIPTOR = 0x07;
32
+	const TYPE_EXTERNAL = 0x08;
33
+	const TYPE_REAL = 0x09;
34
+	const TYPE_ENUMERATED = 0x0a;
35
+	const TYPE_EMBEDDED_PDV = 0x0b;
36
+	const TYPE_UTF8_STRING = 0x0c;
37
+	const TYPE_RELATIVE_OID = 0x0d;
38
+	const TYPE_SEQUENCE = 0x10;
39
+	const TYPE_SET = 0x11;
40
+	const TYPE_NUMERIC_STRING = 0x12;
41
+	const TYPE_PRINTABLE_STRING = 0x13;
42
+	const TYPE_T61_STRING = 0x14;
43
+	const TYPE_VIDEOTEX_STRING = 0x15;
44
+	const TYPE_IA5_STRING = 0x16;
45
+	const TYPE_UTC_TIME = 0x17;
46
+	const TYPE_GENERALIZED_TIME = 0x18;
47
+	const TYPE_GRAPHIC_STRING = 0x19;
48
+	const TYPE_VISIBLE_STRING = 0x1a;
49
+	const TYPE_GENERAL_STRING = 0x1b;
50
+	const TYPE_UNIVERSAL_STRING = 0x1c;
51
+	const TYPE_CHARACTER_STRING = 0x1d;
52
+	const TYPE_BMP_STRING = 0x1e;
53 53
     
54
-    /**
55
-     * Mapping from universal type tag to implementation class name.
56
-     *
57
-     * @internal
58
-     *
59
-     * @var array
60
-     */
61
-    const MAP_TAG_TO_CLASS = [ /* @formatter:off */
62
-        self::TYPE_BOOLEAN => Primitive\Boolean::class,
63
-        self::TYPE_INTEGER => Primitive\Integer::class,
64
-        self::TYPE_BIT_STRING => Primitive\BitString::class,
65
-        self::TYPE_OCTET_STRING => Primitive\OctetString::class,
66
-        self::TYPE_NULL => Primitive\NullType::class,
67
-        self::TYPE_OBJECT_IDENTIFIER => Primitive\ObjectIdentifier::class,
68
-        self::TYPE_OBJECT_DESCRIPTOR => Primitive\ObjectDescriptor::class,
69
-        self::TYPE_REAL => Primitive\Real::class,
70
-        self::TYPE_ENUMERATED => Primitive\Enumerated::class,
71
-        self::TYPE_UTF8_STRING => Primitive\UTF8String::class,
72
-        self::TYPE_RELATIVE_OID => Primitive\RelativeOID::class,
73
-        self::TYPE_SEQUENCE => Constructed\Sequence::class,
74
-        self::TYPE_SET => Constructed\Set::class,
75
-        self::TYPE_NUMERIC_STRING => Primitive\NumericString::class,
76
-        self::TYPE_PRINTABLE_STRING => Primitive\PrintableString::class,
77
-        self::TYPE_T61_STRING => Primitive\T61String::class,
78
-        self::TYPE_VIDEOTEX_STRING => Primitive\VideotexString::class,
79
-        self::TYPE_IA5_STRING => Primitive\IA5String::class,
80
-        self::TYPE_UTC_TIME => Primitive\UTCTime::class,
81
-        self::TYPE_GENERALIZED_TIME => Primitive\GeneralizedTime::class,
82
-        self::TYPE_GRAPHIC_STRING => Primitive\GraphicString::class,
83
-        self::TYPE_VISIBLE_STRING => Primitive\VisibleString::class,
84
-        self::TYPE_GENERAL_STRING => Primitive\GeneralString::class,
85
-        self::TYPE_UNIVERSAL_STRING => Primitive\UniversalString::class,
86
-        self::TYPE_CHARACTER_STRING => Primitive\CharacterString::class,
87
-        self::TYPE_BMP_STRING => Primitive\BMPString::class
88
-        /* @formatter:on */
89
-    ];
54
+	/**
55
+	 * Mapping from universal type tag to implementation class name.
56
+	 *
57
+	 * @internal
58
+	 *
59
+	 * @var array
60
+	 */
61
+	const MAP_TAG_TO_CLASS = [ /* @formatter:off */
62
+		self::TYPE_BOOLEAN => Primitive\Boolean::class,
63
+		self::TYPE_INTEGER => Primitive\Integer::class,
64
+		self::TYPE_BIT_STRING => Primitive\BitString::class,
65
+		self::TYPE_OCTET_STRING => Primitive\OctetString::class,
66
+		self::TYPE_NULL => Primitive\NullType::class,
67
+		self::TYPE_OBJECT_IDENTIFIER => Primitive\ObjectIdentifier::class,
68
+		self::TYPE_OBJECT_DESCRIPTOR => Primitive\ObjectDescriptor::class,
69
+		self::TYPE_REAL => Primitive\Real::class,
70
+		self::TYPE_ENUMERATED => Primitive\Enumerated::class,
71
+		self::TYPE_UTF8_STRING => Primitive\UTF8String::class,
72
+		self::TYPE_RELATIVE_OID => Primitive\RelativeOID::class,
73
+		self::TYPE_SEQUENCE => Constructed\Sequence::class,
74
+		self::TYPE_SET => Constructed\Set::class,
75
+		self::TYPE_NUMERIC_STRING => Primitive\NumericString::class,
76
+		self::TYPE_PRINTABLE_STRING => Primitive\PrintableString::class,
77
+		self::TYPE_T61_STRING => Primitive\T61String::class,
78
+		self::TYPE_VIDEOTEX_STRING => Primitive\VideotexString::class,
79
+		self::TYPE_IA5_STRING => Primitive\IA5String::class,
80
+		self::TYPE_UTC_TIME => Primitive\UTCTime::class,
81
+		self::TYPE_GENERALIZED_TIME => Primitive\GeneralizedTime::class,
82
+		self::TYPE_GRAPHIC_STRING => Primitive\GraphicString::class,
83
+		self::TYPE_VISIBLE_STRING => Primitive\VisibleString::class,
84
+		self::TYPE_GENERAL_STRING => Primitive\GeneralString::class,
85
+		self::TYPE_UNIVERSAL_STRING => Primitive\UniversalString::class,
86
+		self::TYPE_CHARACTER_STRING => Primitive\CharacterString::class,
87
+		self::TYPE_BMP_STRING => Primitive\BMPString::class
88
+		/* @formatter:on */
89
+	];
90 90
     
91
-    /**
92
-     * Pseudotype for all string types.
93
-     *
94
-     * May be used as an expectation parameter.
95
-     *
96
-     * @var int
97
-     */
98
-    const TYPE_STRING = -1;
91
+	/**
92
+	 * Pseudotype for all string types.
93
+	 *
94
+	 * May be used as an expectation parameter.
95
+	 *
96
+	 * @var int
97
+	 */
98
+	const TYPE_STRING = -1;
99 99
     
100
-    /**
101
-     * Pseudotype for all time types.
102
-     *
103
-     * May be used as an expectation parameter.
104
-     *
105
-     * @var int
106
-     */
107
-    const TYPE_TIME = -2;
100
+	/**
101
+	 * Pseudotype for all time types.
102
+	 *
103
+	 * May be used as an expectation parameter.
104
+	 *
105
+	 * @var int
106
+	 */
107
+	const TYPE_TIME = -2;
108 108
     
109
-    /**
110
-     * Mapping from universal type tag to human readable name.
111
-     *
112
-     * @internal
113
-     *
114
-     * @var array
115
-     */
116
-    const MAP_TYPE_TO_NAME = [ /* @formatter:off */
117
-        self::TYPE_EOC => "EOC",
118
-        self::TYPE_BOOLEAN => "BOOLEAN",
119
-        self::TYPE_INTEGER => "INTEGER",
120
-        self::TYPE_BIT_STRING => "BIT STRING",
121
-        self::TYPE_OCTET_STRING => "OCTET STRING",
122
-        self::TYPE_NULL => "NULL",
123
-        self::TYPE_OBJECT_IDENTIFIER => "OBJECT IDENTIFIER",
124
-        self::TYPE_OBJECT_DESCRIPTOR => "ObjectDescriptor",
125
-        self::TYPE_EXTERNAL => "EXTERNAL",
126
-        self::TYPE_REAL => "REAL",
127
-        self::TYPE_ENUMERATED => "ENUMERATED",
128
-        self::TYPE_EMBEDDED_PDV => "EMBEDDED PDV",
129
-        self::TYPE_UTF8_STRING => "UTF8String",
130
-        self::TYPE_RELATIVE_OID => "RELATIVE-OID",
131
-        self::TYPE_SEQUENCE => "SEQUENCE",
132
-        self::TYPE_SET => "SET",
133
-        self::TYPE_NUMERIC_STRING => "NumericString",
134
-        self::TYPE_PRINTABLE_STRING => "PrintableString",
135
-        self::TYPE_T61_STRING => "T61String",
136
-        self::TYPE_VIDEOTEX_STRING => "VideotexString",
137
-        self::TYPE_IA5_STRING => "IA5String",
138
-        self::TYPE_UTC_TIME => "UTCTime",
139
-        self::TYPE_GENERALIZED_TIME => "GeneralizedTime",
140
-        self::TYPE_GRAPHIC_STRING => "GraphicString",
141
-        self::TYPE_VISIBLE_STRING => "VisibleString",
142
-        self::TYPE_GENERAL_STRING => "GeneralString",
143
-        self::TYPE_UNIVERSAL_STRING => "UniversalString",
144
-        self::TYPE_CHARACTER_STRING => "CHARACTER STRING",
145
-        self::TYPE_BMP_STRING => "BMPString",
146
-        self::TYPE_STRING => "Any String",
147
-        self::TYPE_TIME => "Any Time"
148
-        /* @formatter:on */
149
-    ];
109
+	/**
110
+	 * Mapping from universal type tag to human readable name.
111
+	 *
112
+	 * @internal
113
+	 *
114
+	 * @var array
115
+	 */
116
+	const MAP_TYPE_TO_NAME = [ /* @formatter:off */
117
+		self::TYPE_EOC => "EOC",
118
+		self::TYPE_BOOLEAN => "BOOLEAN",
119
+		self::TYPE_INTEGER => "INTEGER",
120
+		self::TYPE_BIT_STRING => "BIT STRING",
121
+		self::TYPE_OCTET_STRING => "OCTET STRING",
122
+		self::TYPE_NULL => "NULL",
123
+		self::TYPE_OBJECT_IDENTIFIER => "OBJECT IDENTIFIER",
124
+		self::TYPE_OBJECT_DESCRIPTOR => "ObjectDescriptor",
125
+		self::TYPE_EXTERNAL => "EXTERNAL",
126
+		self::TYPE_REAL => "REAL",
127
+		self::TYPE_ENUMERATED => "ENUMERATED",
128
+		self::TYPE_EMBEDDED_PDV => "EMBEDDED PDV",
129
+		self::TYPE_UTF8_STRING => "UTF8String",
130
+		self::TYPE_RELATIVE_OID => "RELATIVE-OID",
131
+		self::TYPE_SEQUENCE => "SEQUENCE",
132
+		self::TYPE_SET => "SET",
133
+		self::TYPE_NUMERIC_STRING => "NumericString",
134
+		self::TYPE_PRINTABLE_STRING => "PrintableString",
135
+		self::TYPE_T61_STRING => "T61String",
136
+		self::TYPE_VIDEOTEX_STRING => "VideotexString",
137
+		self::TYPE_IA5_STRING => "IA5String",
138
+		self::TYPE_UTC_TIME => "UTCTime",
139
+		self::TYPE_GENERALIZED_TIME => "GeneralizedTime",
140
+		self::TYPE_GRAPHIC_STRING => "GraphicString",
141
+		self::TYPE_VISIBLE_STRING => "VisibleString",
142
+		self::TYPE_GENERAL_STRING => "GeneralString",
143
+		self::TYPE_UNIVERSAL_STRING => "UniversalString",
144
+		self::TYPE_CHARACTER_STRING => "CHARACTER STRING",
145
+		self::TYPE_BMP_STRING => "BMPString",
146
+		self::TYPE_STRING => "Any String",
147
+		self::TYPE_TIME => "Any Time"
148
+		/* @formatter:on */
149
+	];
150 150
     
151
-    /**
152
-     * Element's type tag.
153
-     *
154
-     * @var int
155
-     */
156
-    protected $_typeTag;
151
+	/**
152
+	 * Element's type tag.
153
+	 *
154
+	 * @var int
155
+	 */
156
+	protected $_typeTag;
157 157
     
158
-    /**
159
-     *
160
-     * @see \ASN1\Feature\ElementBase::typeClass()
161
-     * @return int
162
-     */
163
-    abstract public function typeClass(): int;
158
+	/**
159
+	 *
160
+	 * @see \ASN1\Feature\ElementBase::typeClass()
161
+	 * @return int
162
+	 */
163
+	abstract public function typeClass(): int;
164 164
     
165
-    /**
166
-     *
167
-     * @see \ASN1\Feature\ElementBase::isConstructed()
168
-     * @return bool
169
-     */
170
-    abstract public function isConstructed(): bool;
165
+	/**
166
+	 *
167
+	 * @see \ASN1\Feature\ElementBase::isConstructed()
168
+	 * @return bool
169
+	 */
170
+	abstract public function isConstructed(): bool;
171 171
     
172
-    /**
173
-     * Get the content encoded in DER.
174
-     *
175
-     * Returns the DER encoded content without identifier and length header
176
-     * octets.
177
-     *
178
-     * @return string
179
-     */
180
-    abstract protected function _encodedContentDER(): string;
172
+	/**
173
+	 * Get the content encoded in DER.
174
+	 *
175
+	 * Returns the DER encoded content without identifier and length header
176
+	 * octets.
177
+	 *
178
+	 * @return string
179
+	 */
180
+	abstract protected function _encodedContentDER(): string;
181 181
     
182
-    /**
183
-     * Decode type-specific element from DER.
184
-     *
185
-     * @param Identifier $identifier Pre-parsed identifier
186
-     * @param string $data DER data
187
-     * @param int $offset Offset in data to the next byte after identifier
188
-     * @throws DecodeException If decoding fails
189
-     * @return self
190
-     */
191
-    protected static function _decodeFromDER(Identifier $identifier, string $data,
192
-        int &$offset): ElementBase
193
-    {
194
-        throw new \BadMethodCallException(
195
-            __METHOD__ . " must be implemented in derived class.");
196
-    }
182
+	/**
183
+	 * Decode type-specific element from DER.
184
+	 *
185
+	 * @param Identifier $identifier Pre-parsed identifier
186
+	 * @param string $data DER data
187
+	 * @param int $offset Offset in data to the next byte after identifier
188
+	 * @throws DecodeException If decoding fails
189
+	 * @return self
190
+	 */
191
+	protected static function _decodeFromDER(Identifier $identifier, string $data,
192
+		int &$offset): ElementBase
193
+	{
194
+		throw new \BadMethodCallException(
195
+			__METHOD__ . " must be implemented in derived class.");
196
+	}
197 197
     
198
-    /**
199
-     * Decode element from DER data.
200
-     *
201
-     * @param string $data DER encoded data
202
-     * @param int|null $offset Reference to the variable that contains offset
203
-     *        into the data where to start parsing. Variable is updated to
204
-     *        the offset next to the parsed element. If null, start from offset
205
-     *        0.
206
-     * @throws DecodeException If decoding fails
207
-     * @throws \UnexpectedValueException If called in the context of an expected
208
-     *         type, but decoding yields another type
209
-     * @return ElementBase
210
-     */
211
-    public static function fromDER(string $data, int &$offset = null): ElementBase
212
-    {
213
-        // decode identifier
214
-        $idx = $offset ? $offset : 0;
215
-        $identifier = Identifier::fromDER($data, $idx);
216
-        // determine class that implements type specific decoding
217
-        $cls = self::_determineImplClass($identifier);
218
-        try {
219
-            // decode remaining element
220
-            $element = $cls::_decodeFromDER($identifier, $data, $idx);
221
-        } catch (\LogicException $e) {
222
-            // rethrow as a RuntimeException for unified exception handling
223
-            throw new DecodeException(
224
-                sprintf("Error while decoding %s.",
225
-                    self::tagToName($identifier->intTag())), 0, $e);
226
-        }
227
-        // if called in the context of a concrete class, check
228
-        // that decoded type matches the type of a calling class
229
-        $called_class = get_called_class();
230
-        if (self::class != $called_class) {
231
-            if (!$element instanceof $called_class) {
232
-                throw new \UnexpectedValueException(
233
-                    sprintf("%s expected, got %s.", $called_class,
234
-                        get_class($element)));
235
-            }
236
-        }
237
-        // update offset for the caller
238
-        if (isset($offset)) {
239
-            $offset = $idx;
240
-        }
241
-        return $element;
242
-    }
198
+	/**
199
+	 * Decode element from DER data.
200
+	 *
201
+	 * @param string $data DER encoded data
202
+	 * @param int|null $offset Reference to the variable that contains offset
203
+	 *        into the data where to start parsing. Variable is updated to
204
+	 *        the offset next to the parsed element. If null, start from offset
205
+	 *        0.
206
+	 * @throws DecodeException If decoding fails
207
+	 * @throws \UnexpectedValueException If called in the context of an expected
208
+	 *         type, but decoding yields another type
209
+	 * @return ElementBase
210
+	 */
211
+	public static function fromDER(string $data, int &$offset = null): ElementBase
212
+	{
213
+		// decode identifier
214
+		$idx = $offset ? $offset : 0;
215
+		$identifier = Identifier::fromDER($data, $idx);
216
+		// determine class that implements type specific decoding
217
+		$cls = self::_determineImplClass($identifier);
218
+		try {
219
+			// decode remaining element
220
+			$element = $cls::_decodeFromDER($identifier, $data, $idx);
221
+		} catch (\LogicException $e) {
222
+			// rethrow as a RuntimeException for unified exception handling
223
+			throw new DecodeException(
224
+				sprintf("Error while decoding %s.",
225
+					self::tagToName($identifier->intTag())), 0, $e);
226
+		}
227
+		// if called in the context of a concrete class, check
228
+		// that decoded type matches the type of a calling class
229
+		$called_class = get_called_class();
230
+		if (self::class != $called_class) {
231
+			if (!$element instanceof $called_class) {
232
+				throw new \UnexpectedValueException(
233
+					sprintf("%s expected, got %s.", $called_class,
234
+						get_class($element)));
235
+			}
236
+		}
237
+		// update offset for the caller
238
+		if (isset($offset)) {
239
+			$offset = $idx;
240
+		}
241
+		return $element;
242
+	}
243 243
     
244
-    /**
245
-     *
246
-     * @see \ASN1\Feature\Encodable::toDER()
247
-     * @return string
248
-     */
249
-    public function toDER(): string
250
-    {
251
-        $identifier = new Identifier($this->typeClass(),
252
-            $this->isConstructed() ? Identifier::CONSTRUCTED : Identifier::PRIMITIVE,
253
-            $this->_typeTag);
254
-        $content = $this->_encodedContentDER();
255
-        $length = new Length(strlen($content));
256
-        return $identifier->toDER() . $length->toDER() . $content;
257
-    }
244
+	/**
245
+	 *
246
+	 * @see \ASN1\Feature\Encodable::toDER()
247
+	 * @return string
248
+	 */
249
+	public function toDER(): string
250
+	{
251
+		$identifier = new Identifier($this->typeClass(),
252
+			$this->isConstructed() ? Identifier::CONSTRUCTED : Identifier::PRIMITIVE,
253
+			$this->_typeTag);
254
+		$content = $this->_encodedContentDER();
255
+		$length = new Length(strlen($content));
256
+		return $identifier->toDER() . $length->toDER() . $content;
257
+	}
258 258
     
259
-    /**
260
-     *
261
-     * @see \ASN1\Feature\ElementBase::tag()
262
-     * @return int
263
-     */
264
-    public function tag(): int
265
-    {
266
-        return $this->_typeTag;
267
-    }
259
+	/**
260
+	 *
261
+	 * @see \ASN1\Feature\ElementBase::tag()
262
+	 * @return int
263
+	 */
264
+	public function tag(): int
265
+	{
266
+		return $this->_typeTag;
267
+	}
268 268
     
269
-    /**
270
-     *
271
-     * @see \ASN1\Feature\ElementBase::isType()
272
-     * @return bool
273
-     */
274
-    public function isType(int $tag): bool
275
-    {
276
-        // if element is context specific
277
-        if ($this->typeClass() == Identifier::CLASS_CONTEXT_SPECIFIC) {
278
-            return false;
279
-        }
280
-        // negative tags identify an abstract pseudotype
281
-        if ($tag < 0) {
282
-            return $this->_isPseudoType($tag);
283
-        }
284
-        return $this->_isConcreteType($tag);
285
-    }
269
+	/**
270
+	 *
271
+	 * @see \ASN1\Feature\ElementBase::isType()
272
+	 * @return bool
273
+	 */
274
+	public function isType(int $tag): bool
275
+	{
276
+		// if element is context specific
277
+		if ($this->typeClass() == Identifier::CLASS_CONTEXT_SPECIFIC) {
278
+			return false;
279
+		}
280
+		// negative tags identify an abstract pseudotype
281
+		if ($tag < 0) {
282
+			return $this->_isPseudoType($tag);
283
+		}
284
+		return $this->_isConcreteType($tag);
285
+	}
286 286
     
287
-    /**
288
-     *
289
-     * @see \ASN1\Feature\ElementBase::expectType()
290
-     * @return ElementBase
291
-     */
292
-    public function expectType(int $tag): ElementBase
293
-    {
294
-        if (!$this->isType($tag)) {
295
-            throw new \UnexpectedValueException(
296
-                sprintf("%s expected, got %s.", self::tagToName($tag),
297
-                    $this->_typeDescriptorString()));
298
-        }
299
-        return $this;
300
-    }
287
+	/**
288
+	 *
289
+	 * @see \ASN1\Feature\ElementBase::expectType()
290
+	 * @return ElementBase
291
+	 */
292
+	public function expectType(int $tag): ElementBase
293
+	{
294
+		if (!$this->isType($tag)) {
295
+			throw new \UnexpectedValueException(
296
+				sprintf("%s expected, got %s.", self::tagToName($tag),
297
+					$this->_typeDescriptorString()));
298
+		}
299
+		return $this;
300
+	}
301 301
     
302
-    /**
303
-     * Check whether the element is a concrete type of a given tag.
304
-     *
305
-     * @param int $tag
306
-     * @return bool
307
-     */
308
-    private function _isConcreteType(int $tag): bool
309
-    {
310
-        // if tag doesn't match
311
-        if ($this->tag() != $tag) {
312
-            return false;
313
-        }
314
-        // if type is universal check that instance is of a correct class
315
-        if ($this->typeClass() == Identifier::CLASS_UNIVERSAL) {
316
-            $cls = self::_determineUniversalImplClass($tag);
317
-            if (!$this instanceof $cls) {
318
-                return false;
319
-            }
320
-        }
321
-        return true;
322
-    }
302
+	/**
303
+	 * Check whether the element is a concrete type of a given tag.
304
+	 *
305
+	 * @param int $tag
306
+	 * @return bool
307
+	 */
308
+	private function _isConcreteType(int $tag): bool
309
+	{
310
+		// if tag doesn't match
311
+		if ($this->tag() != $tag) {
312
+			return false;
313
+		}
314
+		// if type is universal check that instance is of a correct class
315
+		if ($this->typeClass() == Identifier::CLASS_UNIVERSAL) {
316
+			$cls = self::_determineUniversalImplClass($tag);
317
+			if (!$this instanceof $cls) {
318
+				return false;
319
+			}
320
+		}
321
+		return true;
322
+	}
323 323
     
324
-    /**
325
-     * Check whether the element is a pseudotype.
326
-     *
327
-     * @param int $tag
328
-     * @return bool
329
-     */
330
-    private function _isPseudoType(int $tag): bool
331
-    {
332
-        switch ($tag) {
333
-            case self::TYPE_STRING:
334
-                return $this instanceof StringType;
335
-            case self::TYPE_TIME:
336
-                return $this instanceof TimeType;
337
-        }
338
-        return false;
339
-    }
324
+	/**
325
+	 * Check whether the element is a pseudotype.
326
+	 *
327
+	 * @param int $tag
328
+	 * @return bool
329
+	 */
330
+	private function _isPseudoType(int $tag): bool
331
+	{
332
+		switch ($tag) {
333
+			case self::TYPE_STRING:
334
+				return $this instanceof StringType;
335
+			case self::TYPE_TIME:
336
+				return $this instanceof TimeType;
337
+		}
338
+		return false;
339
+	}
340 340
     
341
-    /**
342
-     *
343
-     * @see \ASN1\Feature\ElementBase::isTagged()
344
-     * @return bool
345
-     */
346
-    public function isTagged(): bool
347
-    {
348
-        return $this instanceof TaggedType;
349
-    }
341
+	/**
342
+	 *
343
+	 * @see \ASN1\Feature\ElementBase::isTagged()
344
+	 * @return bool
345
+	 */
346
+	public function isTagged(): bool
347
+	{
348
+		return $this instanceof TaggedType;
349
+	}
350 350
     
351
-    /**
352
-     *
353
-     * @see \ASN1\Feature\ElementBase::expectTagged()
354
-     * @return TaggedType
355
-     */
356
-    public function expectTagged($tag = null): TaggedType
357
-    {
358
-        if (!$this->isTagged()) {
359
-            throw new \UnexpectedValueException(
360
-                sprintf("Context specific element expected, got %s.",
361
-                    Identifier::classToName($this->typeClass())));
362
-        }
363
-        if (isset($tag) && $this->tag() != $tag) {
364
-            throw new \UnexpectedValueException(
365
-                sprintf("Tag %d expected, got %d.", $tag, $this->tag()));
366
-        }
367
-        return $this;
368
-    }
351
+	/**
352
+	 *
353
+	 * @see \ASN1\Feature\ElementBase::expectTagged()
354
+	 * @return TaggedType
355
+	 */
356
+	public function expectTagged($tag = null): TaggedType
357
+	{
358
+		if (!$this->isTagged()) {
359
+			throw new \UnexpectedValueException(
360
+				sprintf("Context specific element expected, got %s.",
361
+					Identifier::classToName($this->typeClass())));
362
+		}
363
+		if (isset($tag) && $this->tag() != $tag) {
364
+			throw new \UnexpectedValueException(
365
+				sprintf("Tag %d expected, got %d.", $tag, $this->tag()));
366
+		}
367
+		return $this;
368
+	}
369 369
     
370
-    /**
371
-     *
372
-     * @see \ASN1\Feature\ElementBase::asElement()
373
-     * @return Element
374
-     */
375
-    final public function asElement(): Element
376
-    {
377
-        return $this;
378
-    }
370
+	/**
371
+	 *
372
+	 * @see \ASN1\Feature\ElementBase::asElement()
373
+	 * @return Element
374
+	 */
375
+	final public function asElement(): Element
376
+	{
377
+		return $this;
378
+	}
379 379
     
380
-    /**
381
-     * Get element decorated with UnspecifiedType object.
382
-     *
383
-     * @return UnspecifiedType
384
-     */
385
-    public function asUnspecified(): UnspecifiedType
386
-    {
387
-        return new UnspecifiedType($this);
388
-    }
380
+	/**
381
+	 * Get element decorated with UnspecifiedType object.
382
+	 *
383
+	 * @return UnspecifiedType
384
+	 */
385
+	public function asUnspecified(): UnspecifiedType
386
+	{
387
+		return new UnspecifiedType($this);
388
+	}
389 389
     
390
-    /**
391
-     * Determine the class that implements the type.
392
-     *
393
-     * @param Identifier $identifier
394
-     * @return string Class name
395
-     */
396
-    protected static function _determineImplClass(Identifier $identifier): string
397
-    {
398
-        // tagged type
399
-        if ($identifier->isContextSpecific()) {
400
-            return TaggedType::class;
401
-        }
402
-        // universal class
403
-        if ($identifier->isUniversal()) {
404
-            return self::_determineUniversalImplClass($identifier->intTag());
405
-        }
406
-        throw new \UnexpectedValueException(
407
-            sprintf("%s %d not implemented.",
408
-                Identifier::classToName($identifier->typeClass()),
409
-                $identifier->tag()));
410
-    }
390
+	/**
391
+	 * Determine the class that implements the type.
392
+	 *
393
+	 * @param Identifier $identifier
394
+	 * @return string Class name
395
+	 */
396
+	protected static function _determineImplClass(Identifier $identifier): string
397
+	{
398
+		// tagged type
399
+		if ($identifier->isContextSpecific()) {
400
+			return TaggedType::class;
401
+		}
402
+		// universal class
403
+		if ($identifier->isUniversal()) {
404
+			return self::_determineUniversalImplClass($identifier->intTag());
405
+		}
406
+		throw new \UnexpectedValueException(
407
+			sprintf("%s %d not implemented.",
408
+				Identifier::classToName($identifier->typeClass()),
409
+				$identifier->tag()));
410
+	}
411 411
     
412
-    /**
413
-     * Determine the class that implements an universal type of the given tag.
414
-     *
415
-     * @param int $tag
416
-     * @throws \UnexpectedValueException
417
-     * @return string Class name
418
-     */
419
-    protected static function _determineUniversalImplClass(int $tag): string
420
-    {
421
-        if (!array_key_exists($tag, self::MAP_TAG_TO_CLASS)) {
422
-            throw new \UnexpectedValueException(
423
-                "Universal tag $tag not implemented.");
424
-        }
425
-        return self::MAP_TAG_TO_CLASS[$tag];
426
-    }
412
+	/**
413
+	 * Determine the class that implements an universal type of the given tag.
414
+	 *
415
+	 * @param int $tag
416
+	 * @throws \UnexpectedValueException
417
+	 * @return string Class name
418
+	 */
419
+	protected static function _determineUniversalImplClass(int $tag): string
420
+	{
421
+		if (!array_key_exists($tag, self::MAP_TAG_TO_CLASS)) {
422
+			throw new \UnexpectedValueException(
423
+				"Universal tag $tag not implemented.");
424
+		}
425
+		return self::MAP_TAG_TO_CLASS[$tag];
426
+	}
427 427
     
428
-    /**
429
-     * Get textual description of the type for debugging purposes.
430
-     *
431
-     * @return string
432
-     */
433
-    protected function _typeDescriptorString(): string
434
-    {
435
-        if ($this->typeClass() == Identifier::CLASS_UNIVERSAL) {
436
-            return self::tagToName($this->_typeTag);
437
-        }
438
-        return sprintf("%s TAG %d", Identifier::classToName($this->typeClass()),
439
-            $this->_typeTag);
440
-    }
428
+	/**
429
+	 * Get textual description of the type for debugging purposes.
430
+	 *
431
+	 * @return string
432
+	 */
433
+	protected function _typeDescriptorString(): string
434
+	{
435
+		if ($this->typeClass() == Identifier::CLASS_UNIVERSAL) {
436
+			return self::tagToName($this->_typeTag);
437
+		}
438
+		return sprintf("%s TAG %d", Identifier::classToName($this->typeClass()),
439
+			$this->_typeTag);
440
+	}
441 441
     
442
-    /**
443
-     * Get human readable name for an universal tag.
444
-     *
445
-     * @param int $tag
446
-     * @return string
447
-     */
448
-    public static function tagToName(int $tag): string
449
-    {
450
-        if (!array_key_exists($tag, self::MAP_TYPE_TO_NAME)) {
451
-            return "TAG $tag";
452
-        }
453
-        return self::MAP_TYPE_TO_NAME[$tag];
454
-    }
442
+	/**
443
+	 * Get human readable name for an universal tag.
444
+	 *
445
+	 * @param int $tag
446
+	 * @return string
447
+	 */
448
+	public static function tagToName(int $tag): string
449
+	{
450
+		if (!array_key_exists($tag, self::MAP_TYPE_TO_NAME)) {
451
+			return "TAG $tag";
452
+		}
453
+		return self::MAP_TYPE_TO_NAME[$tag];
454
+	}
455 455
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
      *
59 59
      * @var array
60 60
      */
61
-    const MAP_TAG_TO_CLASS = [ /* @formatter:off */
61
+    const MAP_TAG_TO_CLASS = [/* @formatter:off */
62 62
         self::TYPE_BOOLEAN => Primitive\Boolean::class,
63 63
         self::TYPE_INTEGER => Primitive\Integer::class,
64 64
         self::TYPE_BIT_STRING => Primitive\BitString::class,
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
      *
114 114
      * @var array
115 115
      */
116
-    const MAP_TYPE_TO_NAME = [ /* @formatter:off */
116
+    const MAP_TYPE_TO_NAME = [/* @formatter:off */
117 117
         self::TYPE_EOC => "EOC",
118 118
         self::TYPE_BOOLEAN => "BOOLEAN",
119 119
         self::TYPE_INTEGER => "INTEGER",
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
      * @return self
190 190
      */
191 191
     protected static function _decodeFromDER(Identifier $identifier, string $data,
192
-        int &$offset): ElementBase
192
+        int & $offset): ElementBase
193 193
     {
194 194
         throw new \BadMethodCallException(
195 195
             __METHOD__ . " must be implemented in derived class.");
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
      *         type, but decoding yields another type
209 209
      * @return ElementBase
210 210
      */
211
-    public static function fromDER(string $data, int &$offset = null): ElementBase
211
+    public static function fromDER(string $data, int & $offset = null): ElementBase
212 212
     {
213 213
         // decode identifier
214 214
         $idx = $offset ? $offset : 0;
Please login to merge, or discard this patch.