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 ( e378f0...516cbf )
by Joni
01:59
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 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 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 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 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.