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 — php70 ( e15417...9941dc )
by Joni
03:18
created
lib/ASN1/Type/Primitive/UTCTime.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace ASN1\Type\Primitive;
6 6
 
Please login to merge, or discard this patch.
Indentation   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -16,73 +16,73 @@
 block discarded – undo
16 16
  */
17 17
 class UTCTime extends TimeType
18 18
 {
19
-    use UniversalClass;
20
-    use PrimitiveType;
19
+	use UniversalClass;
20
+	use PrimitiveType;
21 21
     
22
-    /**
23
-     * Regular expression to parse date.
24
-     *
25
-     * DER restricts format to UTC timezone (Z suffix).
26
-     *
27
-     * @var string
28
-     */
29
-    const REGEX = /* @formatter:off */ '#^' .
30
-        '(\d\d)' . /* YY */
31
-        '(\d\d)' . /* MM */
32
-        '(\d\d)' . /* DD */
33
-        '(\d\d)' . /* hh */
34
-        '(\d\d)' . /* mm */
35
-        '(\d\d)' . /* ss */
36
-        'Z' . /* TZ */
37
-        '$#' /* @formatter:on */;
22
+	/**
23
+	 * Regular expression to parse date.
24
+	 *
25
+	 * DER restricts format to UTC timezone (Z suffix).
26
+	 *
27
+	 * @var string
28
+	 */
29
+	const REGEX = /* @formatter:off */ '#^' .
30
+		'(\d\d)' . /* YY */
31
+		'(\d\d)' . /* MM */
32
+		'(\d\d)' . /* DD */
33
+		'(\d\d)' . /* hh */
34
+		'(\d\d)' . /* mm */
35
+		'(\d\d)' . /* ss */
36
+		'Z' . /* TZ */
37
+		'$#' /* @formatter:on */;
38 38
     
39
-    /**
40
-     * Constructor.
41
-     *
42
-     * @param \DateTimeImmutable $dt
43
-     */
44
-    public function __construct(\DateTimeImmutable $dt)
45
-    {
46
-        $this->_typeTag = self::TYPE_UTC_TIME;
47
-        parent::__construct($dt);
48
-    }
39
+	/**
40
+	 * Constructor.
41
+	 *
42
+	 * @param \DateTimeImmutable $dt
43
+	 */
44
+	public function __construct(\DateTimeImmutable $dt)
45
+	{
46
+		$this->_typeTag = self::TYPE_UTC_TIME;
47
+		parent::__construct($dt);
48
+	}
49 49
     
50
-    /**
51
-     *
52
-     * {@inheritdoc}
53
-     */
54
-    protected function _encodedContentDER(): string
55
-    {
56
-        $dt = $this->_dateTime->setTimezone(self::_createTimeZone(self::TZ_UTC));
57
-        return $dt->format("ymdHis\Z");
58
-    }
50
+	/**
51
+	 *
52
+	 * {@inheritdoc}
53
+	 */
54
+	protected function _encodedContentDER(): string
55
+	{
56
+		$dt = $this->_dateTime->setTimezone(self::_createTimeZone(self::TZ_UTC));
57
+		return $dt->format("ymdHis\Z");
58
+	}
59 59
     
60
-    /**
61
-     *
62
-     * {@inheritdoc}
63
-     * @return self
64
-     */
65
-    protected static function _decodeFromDER(Identifier $identifier,
66
-        string $data, int &$offset): ElementBase
67
-    {
68
-        $idx = $offset;
69
-        $length = Length::expectFromDER($data, $idx)->intLength();
70
-        $str = substr($data, $idx, $length);
71
-        $idx += $length;
72
-        /** @var $match string[] */
73
-        if (!preg_match(self::REGEX, $str, $match)) {
74
-            throw new DecodeException("Invalid UTCTime format.");
75
-        }
76
-        list(, $year, $month, $day, $hour, $minute, $second) = $match;
77
-        $time = $year . $month . $day . $hour . $minute . $second . self::TZ_UTC;
78
-        $dt = \DateTimeImmutable::createFromFormat("!ymdHisT", $time,
79
-            self::_createTimeZone(self::TZ_UTC));
80
-        if (!$dt) {
81
-            throw new DecodeException(
82
-                "Failed to decode UTCTime: " .
83
-                self::_getLastDateTimeImmutableErrorsStr());
84
-        }
85
-        $offset = $idx;
86
-        return new self($dt);
87
-    }
60
+	/**
61
+	 *
62
+	 * {@inheritdoc}
63
+	 * @return self
64
+	 */
65
+	protected static function _decodeFromDER(Identifier $identifier,
66
+		string $data, int &$offset): ElementBase
67
+	{
68
+		$idx = $offset;
69
+		$length = Length::expectFromDER($data, $idx)->intLength();
70
+		$str = substr($data, $idx, $length);
71
+		$idx += $length;
72
+		/** @var $match string[] */
73
+		if (!preg_match(self::REGEX, $str, $match)) {
74
+			throw new DecodeException("Invalid UTCTime format.");
75
+		}
76
+		list(, $year, $month, $day, $hour, $minute, $second) = $match;
77
+		$time = $year . $month . $day . $hour . $minute . $second . self::TZ_UTC;
78
+		$dt = \DateTimeImmutable::createFromFormat("!ymdHisT", $time,
79
+			self::_createTimeZone(self::TZ_UTC));
80
+		if (!$dt) {
81
+			throw new DecodeException(
82
+				"Failed to decode UTCTime: " .
83
+				self::_getLastDateTimeImmutableErrorsStr());
84
+		}
85
+		$offset = $idx;
86
+		return new self($dt);
87
+	}
88 88
 }
Please login to merge, or discard this patch.
lib/ASN1/Type/Primitive/RelativeOID.php 2 patches
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -12,39 +12,39 @@
 block discarded – undo
12 12
  */
13 13
 class RelativeOID extends ObjectIdentifier
14 14
 {
15
-    /**
16
-     * Constructor.
17
-     *
18
-     * @param string $oid OID in dotted format
19
-     */
20
-    public function __construct(string $oid)
21
-    {
22
-        $this->_oid = $oid;
23
-        $this->_subids = self::_explodeDottedOID($oid);
24
-        $this->_typeTag = self::TYPE_RELATIVE_OID;
25
-    }
15
+	/**
16
+	 * Constructor.
17
+	 *
18
+	 * @param string $oid OID in dotted format
19
+	 */
20
+	public function __construct(string $oid)
21
+	{
22
+		$this->_oid = $oid;
23
+		$this->_subids = self::_explodeDottedOID($oid);
24
+		$this->_typeTag = self::TYPE_RELATIVE_OID;
25
+	}
26 26
     
27
-    /**
28
-     *
29
-     * {@inheritdoc}
30
-     */
31
-    protected function _encodedContentDER(): string
32
-    {
33
-        return self::_encodeSubIDs(...$this->_subids);
34
-    }
27
+	/**
28
+	 *
29
+	 * {@inheritdoc}
30
+	 */
31
+	protected function _encodedContentDER(): string
32
+	{
33
+		return self::_encodeSubIDs(...$this->_subids);
34
+	}
35 35
     
36
-    /**
37
-     *
38
-     * {@inheritdoc}
39
-     * @return self
40
-     */
41
-    protected static function _decodeFromDER(Identifier $identifier,
42
-        string $data, int &$offset): ElementBase
43
-    {
44
-        $idx = $offset;
45
-        $len = Length::expectFromDER($data, $idx)->intLength();
46
-        $subids = self::_decodeSubIDs(substr($data, $idx, $len));
47
-        $offset = $idx + $len;
48
-        return new self(self::_implodeSubIDs(...$subids));
49
-    }
36
+	/**
37
+	 *
38
+	 * {@inheritdoc}
39
+	 * @return self
40
+	 */
41
+	protected static function _decodeFromDER(Identifier $identifier,
42
+		string $data, int &$offset): ElementBase
43
+	{
44
+		$idx = $offset;
45
+		$len = Length::expectFromDER($data, $idx)->intLength();
46
+		$subids = self::_decodeSubIDs(substr($data, $idx, $len));
47
+		$offset = $idx + $len;
48
+		return new self(self::_implodeSubIDs(...$subids));
49
+	}
50 50
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace ASN1\Type\Primitive;
6 6
 
Please login to merge, or discard this patch.
lib/ASN1/Type/Primitive/GeneralizedTime.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace ASN1\Type\Primitive;
6 6
 
Please login to merge, or discard this patch.
Indentation   +103 added lines, -103 removed lines patch added patch discarded remove patch
@@ -16,113 +16,113 @@
 block discarded – undo
16 16
  */
17 17
 class GeneralizedTime extends TimeType
18 18
 {
19
-    use UniversalClass;
20
-    use PrimitiveType;
19
+	use UniversalClass;
20
+	use PrimitiveType;
21 21
     
22
-    /**
23
-     * Regular expression to parse date.
24
-     *
25
-     * DER restricts format to UTC timezone (Z suffix).
26
-     *
27
-     * @var string
28
-     */
29
-    const REGEX = /* @formatter:off */ '#^' .
30
-        '(\d\d\d\d)' . /* YYYY */
31
-        '(\d\d)' . /* MM */
32
-        '(\d\d)' . /* DD */
33
-        '(\d\d)' . /* hh */
34
-        '(\d\d)' . /* mm */
35
-        '(\d\d)' . /* ss */
36
-        '(?:\.(\d+))?' . /* frac */
37
-        'Z' . /* TZ */
38
-        '$#' /* @formatter:on */;
22
+	/**
23
+	 * Regular expression to parse date.
24
+	 *
25
+	 * DER restricts format to UTC timezone (Z suffix).
26
+	 *
27
+	 * @var string
28
+	 */
29
+	const REGEX = /* @formatter:off */ '#^' .
30
+		'(\d\d\d\d)' . /* YYYY */
31
+		'(\d\d)' . /* MM */
32
+		'(\d\d)' . /* DD */
33
+		'(\d\d)' . /* hh */
34
+		'(\d\d)' . /* mm */
35
+		'(\d\d)' . /* ss */
36
+		'(?:\.(\d+))?' . /* frac */
37
+		'Z' . /* TZ */
38
+		'$#' /* @formatter:on */;
39 39
     
40
-    /**
41
-     * Cached formatted date.
42
-     *
43
-     * @var string|null
44
-     */
45
-    private $_formatted;
40
+	/**
41
+	 * Cached formatted date.
42
+	 *
43
+	 * @var string|null
44
+	 */
45
+	private $_formatted;
46 46
     
47
-    /**
48
-     * Constructor.
49
-     *
50
-     * @param \DateTimeImmutable $dt
51
-     */
52
-    public function __construct(\DateTimeImmutable $dt)
53
-    {
54
-        $this->_typeTag = self::TYPE_GENERALIZED_TIME;
55
-        parent::__construct($dt);
56
-    }
47
+	/**
48
+	 * Constructor.
49
+	 *
50
+	 * @param \DateTimeImmutable $dt
51
+	 */
52
+	public function __construct(\DateTimeImmutable $dt)
53
+	{
54
+		$this->_typeTag = self::TYPE_GENERALIZED_TIME;
55
+		parent::__construct($dt);
56
+	}
57 57
     
58
-    /**
59
-     * Clear cached variables on clone.
60
-     */
61
-    public function __clone()
62
-    {
63
-        $this->_formatted = null;
64
-    }
58
+	/**
59
+	 * Clear cached variables on clone.
60
+	 */
61
+	public function __clone()
62
+	{
63
+		$this->_formatted = null;
64
+	}
65 65
     
66
-    /**
67
-     *
68
-     * {@inheritdoc}
69
-     */
70
-    protected function _encodedContentDER(): string
71
-    {
72
-        if (!isset($this->_formatted)) {
73
-            $dt = $this->_dateTime->setTimezone(
74
-                self::_createTimeZone(self::TZ_UTC));
75
-            $this->_formatted = $dt->format("YmdHis");
76
-            // if fractions were used
77
-            $frac = $dt->format("u");
78
-            if ($frac != 0) {
79
-                $frac = rtrim($frac, "0");
80
-                $this->_formatted .= ".$frac";
81
-            }
82
-            // timezone
83
-            $this->_formatted .= "Z";
84
-        }
85
-        return $this->_formatted;
86
-    }
66
+	/**
67
+	 *
68
+	 * {@inheritdoc}
69
+	 */
70
+	protected function _encodedContentDER(): string
71
+	{
72
+		if (!isset($this->_formatted)) {
73
+			$dt = $this->_dateTime->setTimezone(
74
+				self::_createTimeZone(self::TZ_UTC));
75
+			$this->_formatted = $dt->format("YmdHis");
76
+			// if fractions were used
77
+			$frac = $dt->format("u");
78
+			if ($frac != 0) {
79
+				$frac = rtrim($frac, "0");
80
+				$this->_formatted .= ".$frac";
81
+			}
82
+			// timezone
83
+			$this->_formatted .= "Z";
84
+		}
85
+		return $this->_formatted;
86
+	}
87 87
     
88
-    /**
89
-     *
90
-     * {@inheritdoc}
91
-     * @return self
92
-     */
93
-    protected static function _decodeFromDER(Identifier $identifier,
94
-        string $data, int &$offset): ElementBase
95
-    {
96
-        $idx = $offset;
97
-        $length = Length::expectFromDER($data, $idx)->intLength();
98
-        $str = substr($data, $idx, $length);
99
-        $idx += $length;
100
-        /** @var $match string[] */
101
-        if (!preg_match(self::REGEX, $str, $match)) {
102
-            throw new DecodeException("Invalid GeneralizedTime format.");
103
-        }
104
-        list(, $year, $month, $day, $hour, $minute, $second) = $match;
105
-        if (isset($match[7])) {
106
-            $frac = $match[7];
107
-            // DER restricts trailing zeroes in fractional seconds component
108
-            if ('0' === $frac[strlen($frac) - 1]) {
109
-                throw new DecodeException(
110
-                    "Fractional seconds must omit trailing zeroes.");
111
-            }
112
-            $frac = (int) $frac;
113
-        } else {
114
-            $frac = 0;
115
-        }
116
-        $time = $year . $month . $day . $hour . $minute . $second . "." . $frac .
117
-            self::TZ_UTC;
118
-        $dt = \DateTimeImmutable::createFromFormat("!YmdHis.uT", $time,
119
-            self::_createTimeZone(self::TZ_UTC));
120
-        if (!$dt) {
121
-            throw new DecodeException(
122
-                "Failed to decode GeneralizedTime: " .
123
-                self::_getLastDateTimeImmutableErrorsStr());
124
-        }
125
-        $offset = $idx;
126
-        return new self($dt);
127
-    }
88
+	/**
89
+	 *
90
+	 * {@inheritdoc}
91
+	 * @return self
92
+	 */
93
+	protected static function _decodeFromDER(Identifier $identifier,
94
+		string $data, int &$offset): ElementBase
95
+	{
96
+		$idx = $offset;
97
+		$length = Length::expectFromDER($data, $idx)->intLength();
98
+		$str = substr($data, $idx, $length);
99
+		$idx += $length;
100
+		/** @var $match string[] */
101
+		if (!preg_match(self::REGEX, $str, $match)) {
102
+			throw new DecodeException("Invalid GeneralizedTime format.");
103
+		}
104
+		list(, $year, $month, $day, $hour, $minute, $second) = $match;
105
+		if (isset($match[7])) {
106
+			$frac = $match[7];
107
+			// DER restricts trailing zeroes in fractional seconds component
108
+			if ('0' === $frac[strlen($frac) - 1]) {
109
+				throw new DecodeException(
110
+					"Fractional seconds must omit trailing zeroes.");
111
+			}
112
+			$frac = (int) $frac;
113
+		} else {
114
+			$frac = 0;
115
+		}
116
+		$time = $year . $month . $day . $hour . $minute . $second . "." . $frac .
117
+			self::TZ_UTC;
118
+		$dt = \DateTimeImmutable::createFromFormat("!YmdHis.uT", $time,
119
+			self::_createTimeZone(self::TZ_UTC));
120
+		if (!$dt) {
121
+			throw new DecodeException(
122
+				"Failed to decode GeneralizedTime: " .
123
+				self::_getLastDateTimeImmutableErrorsStr());
124
+		}
125
+		$offset = $idx;
126
+		return new self($dt);
127
+	}
128 128
 }
Please login to merge, or discard this patch.
lib/ASN1/Type/Tagged/DERTaggedType.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace ASN1\Type\Tagged;
6 6
 
Please login to merge, or discard this patch.
Indentation   +138 added lines, -138 removed lines patch added patch discarded remove patch
@@ -21,154 +21,154 @@
 block discarded – undo
21 21
  * May be encoded back to complete DER encoding.
22 22
  */
23 23
 class DERTaggedType extends TaggedType implements 
24
-    ExplicitTagging,
25
-    ImplicitTagging
24
+	ExplicitTagging,
25
+	ImplicitTagging
26 26
 {
27
-    /**
28
-     * Identifier.
29
-     *
30
-     * @var Identifier
31
-     */
32
-    private $_identifier;
27
+	/**
28
+	 * Identifier.
29
+	 *
30
+	 * @var Identifier
31
+	 */
32
+	private $_identifier;
33 33
     
34
-    /**
35
-     * DER data.
36
-     *
37
-     * @var string
38
-     */
39
-    private $_data;
34
+	/**
35
+	 * DER data.
36
+	 *
37
+	 * @var string
38
+	 */
39
+	private $_data;
40 40
     
41
-    /**
42
-     * Offset to next byte after identifier.
43
-     *
44
-     * @var int
45
-     */
46
-    private $_offset;
41
+	/**
42
+	 * Offset to next byte after identifier.
43
+	 *
44
+	 * @var int
45
+	 */
46
+	private $_offset;
47 47
     
48
-    /**
49
-     * Offset to content.
50
-     *
51
-     * @var int
52
-     */
53
-    private $_valueOffset;
48
+	/**
49
+	 * Offset to content.
50
+	 *
51
+	 * @var int
52
+	 */
53
+	private $_valueOffset;
54 54
     
55
-    /**
56
-     * Length of the content.
57
-     *
58
-     * @var int
59
-     */
60
-    private $_valueLength;
55
+	/**
56
+	 * Length of the content.
57
+	 *
58
+	 * @var int
59
+	 */
60
+	private $_valueLength;
61 61
     
62
-    /**
63
-     * Constructor.
64
-     *
65
-     * @param Identifier $identifier Pre-parsed identifier
66
-     * @param string $data DER data
67
-     * @param int $offset Offset to next byte after identifier
68
-     * @param int $value_offset Offset to content
69
-     * @param int $value_length Content length
70
-     */
71
-    public function __construct(Identifier $identifier, string $data,
72
-        int $offset, int $value_offset, int $value_length,
73
-        bool $indefinite_length)
74
-    {
75
-        $this->_identifier = $identifier;
76
-        $this->_data = $data;
77
-        $this->_offset = $offset;
78
-        $this->_valueOffset = $value_offset;
79
-        $this->_valueLength = $value_length;
80
-        $this->_indefiniteLength = $indefinite_length;
81
-        $this->_typeTag = $identifier->intTag();
82
-    }
62
+	/**
63
+	 * Constructor.
64
+	 *
65
+	 * @param Identifier $identifier Pre-parsed identifier
66
+	 * @param string $data DER data
67
+	 * @param int $offset Offset to next byte after identifier
68
+	 * @param int $value_offset Offset to content
69
+	 * @param int $value_length Content length
70
+	 */
71
+	public function __construct(Identifier $identifier, string $data,
72
+		int $offset, int $value_offset, int $value_length,
73
+		bool $indefinite_length)
74
+	{
75
+		$this->_identifier = $identifier;
76
+		$this->_data = $data;
77
+		$this->_offset = $offset;
78
+		$this->_valueOffset = $value_offset;
79
+		$this->_valueLength = $value_length;
80
+		$this->_indefiniteLength = $indefinite_length;
81
+		$this->_typeTag = $identifier->intTag();
82
+	}
83 83
     
84
-    /**
85
-     *
86
-     * {@inheritdoc}
87
-     */
88
-    protected static function _decodeFromDER(Identifier $identifier,
89
-        string $data, int &$offset): ElementBase
90
-    {
91
-        $idx = $offset;
92
-        $length = Length::expectFromDER($data, $idx);
93
-        // offset to inner value
94
-        $value_offset = $idx;
95
-        if ($length->isIndefinite()) {
96
-            if ($identifier->isPrimitive()) {
97
-                throw new DecodeException(
98
-                    'Primitive type with indefinite length is not supported.');
99
-            }
100
-            while (!Element::fromDER($data, $idx)->isType(self::TYPE_EOC));
101
-            // EOC consists of two octets.
102
-            $value_length = $idx - $value_offset - 2;
103
-        } else {
104
-            $value_length = $length->intLength();
105
-            $idx += $value_length;
106
-        }
107
-        // late static binding since ApplicationType and PrivateType extend this class
108
-        $type = new static($identifier, $data, $offset, $value_offset,
109
-            $value_length, $length->isIndefinite());
110
-        $offset = $idx;
111
-        return $type;
112
-    }
84
+	/**
85
+	 *
86
+	 * {@inheritdoc}
87
+	 */
88
+	protected static function _decodeFromDER(Identifier $identifier,
89
+		string $data, int &$offset): ElementBase
90
+	{
91
+		$idx = $offset;
92
+		$length = Length::expectFromDER($data, $idx);
93
+		// offset to inner value
94
+		$value_offset = $idx;
95
+		if ($length->isIndefinite()) {
96
+			if ($identifier->isPrimitive()) {
97
+				throw new DecodeException(
98
+					'Primitive type with indefinite length is not supported.');
99
+			}
100
+			while (!Element::fromDER($data, $idx)->isType(self::TYPE_EOC));
101
+			// EOC consists of two octets.
102
+			$value_length = $idx - $value_offset - 2;
103
+		} else {
104
+			$value_length = $length->intLength();
105
+			$idx += $value_length;
106
+		}
107
+		// late static binding since ApplicationType and PrivateType extend this class
108
+		$type = new static($identifier, $data, $offset, $value_offset,
109
+			$value_length, $length->isIndefinite());
110
+		$offset = $idx;
111
+		return $type;
112
+	}
113 113
     
114
-    /**
115
-     *
116
-     * @see \ASN1\Element::typeClass()
117
-     * @return int
118
-     */
119
-    public function typeClass(): int
120
-    {
121
-        return $this->_identifier->typeClass();
122
-    }
114
+	/**
115
+	 *
116
+	 * @see \ASN1\Element::typeClass()
117
+	 * @return int
118
+	 */
119
+	public function typeClass(): int
120
+	{
121
+		return $this->_identifier->typeClass();
122
+	}
123 123
     
124
-    /**
125
-     *
126
-     * @see \ASN1\Element::isConstructed()
127
-     * @return bool
128
-     */
129
-    public function isConstructed(): bool
130
-    {
131
-        return $this->_identifier->isConstructed();
132
-    }
124
+	/**
125
+	 *
126
+	 * @see \ASN1\Element::isConstructed()
127
+	 * @return bool
128
+	 */
129
+	public function isConstructed(): bool
130
+	{
131
+		return $this->_identifier->isConstructed();
132
+	}
133 133
     
134
-    /**
135
-     *
136
-     * @see \ASN1\Element::_encodedContentDER()
137
-     * @return string
138
-     */
139
-    protected function _encodedContentDER(): string
140
-    {
141
-        return substr($this->_data, $this->_valueOffset, $this->_valueLength);
142
-    }
134
+	/**
135
+	 *
136
+	 * @see \ASN1\Element::_encodedContentDER()
137
+	 * @return string
138
+	 */
139
+	protected function _encodedContentDER(): string
140
+	{
141
+		return substr($this->_data, $this->_valueOffset, $this->_valueLength);
142
+	}
143 143
     
144
-    /**
145
-     *
146
-     * {@inheritdoc}
147
-     * @see \ASN1\Type\Tagged\ImplicitTagging::implicit()
148
-     * @return UnspecifiedType
149
-     */
150
-    public function implicit(int $tag, int $class = Identifier::CLASS_UNIVERSAL): UnspecifiedType
151
-    {
152
-        $identifier = $this->_identifier->withClass($class)->withTag($tag);
153
-        $cls = self::_determineImplClass($identifier);
154
-        $idx = $this->_offset;
155
-        /** @var \ASN1\Feature\ElementBase $element */
156
-        $element = $cls::_decodeFromDER($identifier, $this->_data, $idx);
157
-        return $element->asUnspecified();
158
-    }
144
+	/**
145
+	 *
146
+	 * {@inheritdoc}
147
+	 * @see \ASN1\Type\Tagged\ImplicitTagging::implicit()
148
+	 * @return UnspecifiedType
149
+	 */
150
+	public function implicit(int $tag, int $class = Identifier::CLASS_UNIVERSAL): UnspecifiedType
151
+	{
152
+		$identifier = $this->_identifier->withClass($class)->withTag($tag);
153
+		$cls = self::_determineImplClass($identifier);
154
+		$idx = $this->_offset;
155
+		/** @var \ASN1\Feature\ElementBase $element */
156
+		$element = $cls::_decodeFromDER($identifier, $this->_data, $idx);
157
+		return $element->asUnspecified();
158
+	}
159 159
     
160
-    /**
161
-     *
162
-     * @see \ASN1\Type\Tagged\ExplicitTagging::explicit()
163
-     * @return UnspecifiedType
164
-     */
165
-    public function explicit($expectedTag = null): UnspecifiedType
166
-    {
167
-        $idx = $this->_valueOffset;
168
-        $element = Element::fromDER($this->_data, $idx);
169
-        if (isset($expectedTag)) {
170
-            $element->expectType($expectedTag);
171
-        }
172
-        return $element->asUnspecified();
173
-    }
160
+	/**
161
+	 *
162
+	 * @see \ASN1\Type\Tagged\ExplicitTagging::explicit()
163
+	 * @return UnspecifiedType
164
+	 */
165
+	public function explicit($expectedTag = null): UnspecifiedType
166
+	{
167
+		$idx = $this->_valueOffset;
168
+		$element = Element::fromDER($this->_data, $idx);
169
+		if (isset($expectedTag)) {
170
+			$element->expectType($expectedTag);
171
+		}
172
+		return $element->asUnspecified();
173
+	}
174 174
 }
Please login to merge, or discard this patch.
lib/ASN1/Type/Tagged/PrivateType.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace ASN1\Type\Tagged;
6 6
 
Please login to merge, or discard this patch.
lib/ASN1/Type/Tagged/ApplicationType.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace ASN1\Type\Tagged;
6 6
 
Please login to merge, or discard this patch.
lib/ASN1/Type/PrimitiveString.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace ASN1\Type;
6 6
 
Please login to merge, or discard this patch.
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -13,41 +13,41 @@
 block discarded – undo
13 13
  */
14 14
 abstract class PrimitiveString extends StringType
15 15
 {
16
-    use PrimitiveType;
16
+	use PrimitiveType;
17 17
     
18
-    /**
19
-     *
20
-     * @see \ASN1\Element::_encodedContentDER()
21
-     * @return string
22
-     */
23
-    protected function _encodedContentDER(): string
24
-    {
25
-        return $this->_string;
26
-    }
18
+	/**
19
+	 *
20
+	 * @see \ASN1\Element::_encodedContentDER()
21
+	 * @return string
22
+	 */
23
+	protected function _encodedContentDER(): string
24
+	{
25
+		return $this->_string;
26
+	}
27 27
     
28
-    /**
29
-     *
30
-     * {@inheritdoc}
31
-     * @see \ASN1\Element::_decodeFromDER()
32
-     * @return self
33
-     */
34
-    protected static function _decodeFromDER(Identifier $identifier,
35
-        string $data, int &$offset): ElementBase
36
-    {
37
-        $idx = $offset;
38
-        if (!$identifier->isPrimitive()) {
39
-            throw new DecodeException("DER encoded string must be primitive.");
40
-        }
41
-        $length = Length::expectFromDER($data, $idx)->intLength();
42
-        $str = $length ? substr($data, $idx, $length) : "";
43
-        // substr should never return false, since length is
44
-        // checked by Length::expectFromDER.
45
-        assert(is_string($str), new DecodeException("substr"));
46
-        $offset = $idx + $length;
47
-        try {
48
-            return new static($str);
49
-        } catch (\InvalidArgumentException $e) {
50
-            throw new DecodeException($e->getMessage(), 0, $e);
51
-        }
52
-    }
28
+	/**
29
+	 *
30
+	 * {@inheritdoc}
31
+	 * @see \ASN1\Element::_decodeFromDER()
32
+	 * @return self
33
+	 */
34
+	protected static function _decodeFromDER(Identifier $identifier,
35
+		string $data, int &$offset): ElementBase
36
+	{
37
+		$idx = $offset;
38
+		if (!$identifier->isPrimitive()) {
39
+			throw new DecodeException("DER encoded string must be primitive.");
40
+		}
41
+		$length = Length::expectFromDER($data, $idx)->intLength();
42
+		$str = $length ? substr($data, $idx, $length) : "";
43
+		// substr should never return false, since length is
44
+		// checked by Length::expectFromDER.
45
+		assert(is_string($str), new DecodeException("substr"));
46
+		$offset = $idx + $length;
47
+		try {
48
+			return new static($str);
49
+		} catch (\InvalidArgumentException $e) {
50
+			throw new DecodeException($e->getMessage(), 0, $e);
51
+		}
52
+	}
53 53
 }
Please login to merge, or discard this patch.
lib/ASN1/Type/UnspecifiedType.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace ASN1\Type;
6 6
 
Please login to merge, or discard this patch.
Indentation   +678 added lines, -678 removed lines patch added patch discarded remove patch
@@ -16,682 +16,682 @@
 block discarded – undo
16 16
  */
17 17
 class UnspecifiedType implements ElementBase
18 18
 {
19
-    /**
20
-     * The wrapped element.
21
-     *
22
-     * @var Element
23
-     */
24
-    private $_element;
25
-    
26
-    /**
27
-     * Constructor.
28
-     *
29
-     * @param Element $el
30
-     */
31
-    public function __construct(Element $el)
32
-    {
33
-        $this->_element = $el;
34
-    }
35
-    
36
-    /**
37
-     * Initialize from DER data.
38
-     *
39
-     * @param string $data DER encoded data
40
-     * @return self
41
-     */
42
-    public static function fromDER(string $data): self
43
-    {
44
-        return Element::fromDER($data)->asUnspecified();
45
-    }
46
-    
47
-    /**
48
-     * Initialize from ElementBase interface.
49
-     *
50
-     * @param ElementBase $el
51
-     * @return self
52
-     */
53
-    public static function fromElementBase(ElementBase $el): self
54
-    {
55
-        // if element is already wrapped
56
-        if ($el instanceof self) {
57
-            return $el;
58
-        }
59
-        return new self($el->asElement());
60
-    }
61
-    
62
-    /**
63
-     * Compatibility method to dispatch calls to the wrapped element.
64
-     *
65
-     * @deprecated Use <code>as*</code> accessor methods to ensure strict type
66
-     * @param string $mtd Method name
67
-     * @param array $args Arguments
68
-     * @return mixed
69
-     */
70
-    public function __call($mtd, array $args)
71
-    {
72
-        return call_user_func_array([$this->_element, $mtd], $args);
73
-    }
74
-    
75
-    /**
76
-     * Get the wrapped element as a context specific tagged type.
77
-     *
78
-     * @throws \UnexpectedValueException If the element is not tagged
79
-     * @return TaggedType
80
-     */
81
-    public function asTagged(): TaggedType
82
-    {
83
-        if (!$this->_element instanceof TaggedType) {
84
-            throw new \UnexpectedValueException(
85
-                "Tagged element expected, got " . $this->_typeDescriptorString());
86
-        }
87
-        return $this->_element;
88
-    }
89
-    
90
-    /**
91
-     * Get the wrapped element as an application specific type.
92
-     *
93
-     * @throws \UnexpectedValueException If element is not application specific
94
-     * @return \ASN1\Type\Tagged\ApplicationType
95
-     */
96
-    public function asApplication(): Tagged\ApplicationType
97
-    {
98
-        if (!$this->_element instanceof Tagged\ApplicationType) {
99
-            throw new \UnexpectedValueException(
100
-                "Application type expected, got " .
101
-                $this->_typeDescriptorString());
102
-        }
103
-        return $this->_element;
104
-    }
105
-    
106
-    /**
107
-     * Get the wrapped element as a private tagged type.
108
-     *
109
-     * @throws \UnexpectedValueException If element is not using private tagging
110
-     * @return \ASN1\Type\Tagged\PrivateType
111
-     */
112
-    public function asPrivate(): Tagged\PrivateType
113
-    {
114
-        if (!$this->_element instanceof Tagged\PrivateType) {
115
-            throw new \UnexpectedValueException(
116
-                "Private type expected, got " . $this->_typeDescriptorString());
117
-        }
118
-        return $this->_element;
119
-    }
120
-    
121
-    /**
122
-     * Get the wrapped element as a boolean type.
123
-     *
124
-     * @throws \UnexpectedValueException If the element is not a boolean
125
-     * @return \ASN1\Type\Primitive\Boolean
126
-     */
127
-    public function asBoolean(): Primitive\Boolean
128
-    {
129
-        if (!$this->_element instanceof Primitive\Boolean) {
130
-            throw new \UnexpectedValueException(
131
-                $this->_generateExceptionMessage(Element::TYPE_BOOLEAN));
132
-        }
133
-        return $this->_element;
134
-    }
135
-    
136
-    /**
137
-     * Get the wrapped element as an integer type.
138
-     *
139
-     * @throws \UnexpectedValueException If the element is not an integer
140
-     * @return \ASN1\Type\Primitive\Integer
141
-     */
142
-    public function asInteger(): Primitive\Integer
143
-    {
144
-        if (!$this->_element instanceof Primitive\Integer) {
145
-            throw new \UnexpectedValueException(
146
-                $this->_generateExceptionMessage(Element::TYPE_INTEGER));
147
-        }
148
-        return $this->_element;
149
-    }
150
-    
151
-    /**
152
-     * Get the wrapped element as a bit string type.
153
-     *
154
-     * @throws \UnexpectedValueException If the element is not a bit string
155
-     * @return \ASN1\Type\Primitive\BitString
156
-     */
157
-    public function asBitString(): Primitive\BitString
158
-    {
159
-        if (!$this->_element instanceof Primitive\BitString) {
160
-            throw new \UnexpectedValueException(
161
-                $this->_generateExceptionMessage(Element::TYPE_BIT_STRING));
162
-        }
163
-        return $this->_element;
164
-    }
165
-    
166
-    /**
167
-     * Get the wrapped element as an octet string type.
168
-     *
169
-     * @throws \UnexpectedValueException If the element is not an octet string
170
-     * @return \ASN1\Type\Primitive\OctetString
171
-     */
172
-    public function asOctetString(): Primitive\OctetString
173
-    {
174
-        if (!$this->_element instanceof Primitive\OctetString) {
175
-            throw new \UnexpectedValueException(
176
-                $this->_generateExceptionMessage(Element::TYPE_OCTET_STRING));
177
-        }
178
-        return $this->_element;
179
-    }
180
-    
181
-    /**
182
-     * Get the wrapped element as a null type.
183
-     *
184
-     * @throws \UnexpectedValueException If the element is not a null
185
-     * @return \ASN1\Type\Primitive\NullType
186
-     */
187
-    public function asNull(): Primitive\NullType
188
-    {
189
-        if (!$this->_element instanceof Primitive\NullType) {
190
-            throw new \UnexpectedValueException(
191
-                $this->_generateExceptionMessage(Element::TYPE_NULL));
192
-        }
193
-        return $this->_element;
194
-    }
195
-    
196
-    /**
197
-     * Get the wrapped element as an object identifier type.
198
-     *
199
-     * @throws \UnexpectedValueException If the element is not an object
200
-     *         identifier
201
-     * @return \ASN1\Type\Primitive\ObjectIdentifier
202
-     */
203
-    public function asObjectIdentifier(): Primitive\ObjectIdentifier
204
-    {
205
-        if (!$this->_element instanceof Primitive\ObjectIdentifier) {
206
-            throw new \UnexpectedValueException(
207
-                $this->_generateExceptionMessage(
208
-                    Element::TYPE_OBJECT_IDENTIFIER));
209
-        }
210
-        return $this->_element;
211
-    }
212
-    
213
-    /**
214
-     * Get the wrapped element as an object descriptor type.
215
-     *
216
-     * @throws \UnexpectedValueException If the element is not an object
217
-     *         descriptor
218
-     * @return \ASN1\Type\Primitive\ObjectDescriptor
219
-     */
220
-    public function asObjectDescriptor(): Primitive\ObjectDescriptor
221
-    {
222
-        if (!$this->_element instanceof Primitive\ObjectDescriptor) {
223
-            throw new \UnexpectedValueException(
224
-                $this->_generateExceptionMessage(
225
-                    Element::TYPE_OBJECT_DESCRIPTOR));
226
-        }
227
-        return $this->_element;
228
-    }
229
-    
230
-    /**
231
-     * Get the wrapped element as a real type.
232
-     *
233
-     * @throws \UnexpectedValueException If the element is not a real
234
-     * @return \ASN1\Type\Primitive\Real
235
-     */
236
-    public function asReal(): Primitive\Real
237
-    {
238
-        if (!$this->_element instanceof Primitive\Real) {
239
-            throw new \UnexpectedValueException(
240
-                $this->_generateExceptionMessage(Element::TYPE_REAL));
241
-        }
242
-        return $this->_element;
243
-    }
244
-    
245
-    /**
246
-     * Get the wrapped element as an enumerated type.
247
-     *
248
-     * @throws \UnexpectedValueException If the element is not an enumerated
249
-     * @return \ASN1\Type\Primitive\Enumerated
250
-     */
251
-    public function asEnumerated(): Primitive\Enumerated
252
-    {
253
-        if (!$this->_element instanceof Primitive\Enumerated) {
254
-            throw new \UnexpectedValueException(
255
-                $this->_generateExceptionMessage(Element::TYPE_ENUMERATED));
256
-        }
257
-        return $this->_element;
258
-    }
259
-    
260
-    /**
261
-     * Get the wrapped element as a UTF8 string type.
262
-     *
263
-     * @throws \UnexpectedValueException If the element is not a UTF8 string
264
-     * @return \ASN1\Type\Primitive\UTF8String
265
-     */
266
-    public function asUTF8String(): Primitive\UTF8String
267
-    {
268
-        if (!$this->_element instanceof Primitive\UTF8String) {
269
-            throw new \UnexpectedValueException(
270
-                $this->_generateExceptionMessage(Element::TYPE_UTF8_STRING));
271
-        }
272
-        return $this->_element;
273
-    }
274
-    
275
-    /**
276
-     * Get the wrapped element as a relative OID type.
277
-     *
278
-     * @throws \UnexpectedValueException If the element is not a relative OID
279
-     * @return \ASN1\Type\Primitive\RelativeOID
280
-     */
281
-    public function asRelativeOID(): Primitive\RelativeOID
282
-    {
283
-        if (!$this->_element instanceof Primitive\RelativeOID) {
284
-            throw new \UnexpectedValueException(
285
-                $this->_generateExceptionMessage(Element::TYPE_RELATIVE_OID));
286
-        }
287
-        return $this->_element;
288
-    }
289
-    
290
-    /**
291
-     * Get the wrapped element as a sequence type.
292
-     *
293
-     * @throws \UnexpectedValueException If the element is not a sequence
294
-     * @return \ASN1\Type\Constructed\Sequence
295
-     */
296
-    public function asSequence(): Constructed\Sequence
297
-    {
298
-        if (!$this->_element instanceof Constructed\Sequence) {
299
-            throw new \UnexpectedValueException(
300
-                $this->_generateExceptionMessage(Element::TYPE_SEQUENCE));
301
-        }
302
-        return $this->_element;
303
-    }
304
-    
305
-    /**
306
-     * Get the wrapped element as a set type.
307
-     *
308
-     * @throws \UnexpectedValueException If the element is not a set
309
-     * @return \ASN1\Type\Constructed\Set
310
-     */
311
-    public function asSet(): Constructed\Set
312
-    {
313
-        if (!$this->_element instanceof Constructed\Set) {
314
-            throw new \UnexpectedValueException(
315
-                $this->_generateExceptionMessage(Element::TYPE_SET));
316
-        }
317
-        return $this->_element;
318
-    }
319
-    
320
-    /**
321
-     * Get the wrapped element as a numeric string type.
322
-     *
323
-     * @throws \UnexpectedValueException If the element is not a numeric string
324
-     * @return \ASN1\Type\Primitive\NumericString
325
-     */
326
-    public function asNumericString(): Primitive\NumericString
327
-    {
328
-        if (!$this->_element instanceof Primitive\NumericString) {
329
-            throw new \UnexpectedValueException(
330
-                $this->_generateExceptionMessage(Element::TYPE_NUMERIC_STRING));
331
-        }
332
-        return $this->_element;
333
-    }
334
-    
335
-    /**
336
-     * Get the wrapped element as a printable string type.
337
-     *
338
-     * @throws \UnexpectedValueException If the element is not a printable
339
-     *         string
340
-     * @return \ASN1\Type\Primitive\PrintableString
341
-     */
342
-    public function asPrintableString(): Primitive\PrintableString
343
-    {
344
-        if (!$this->_element instanceof Primitive\PrintableString) {
345
-            throw new \UnexpectedValueException(
346
-                $this->_generateExceptionMessage(Element::TYPE_PRINTABLE_STRING));
347
-        }
348
-        return $this->_element;
349
-    }
350
-    
351
-    /**
352
-     * Get the wrapped element as a T61 string type.
353
-     *
354
-     * @throws \UnexpectedValueException If the element is not a T61 string
355
-     * @return \ASN1\Type\Primitive\T61String
356
-     */
357
-    public function asT61String(): Primitive\T61String
358
-    {
359
-        if (!$this->_element instanceof Primitive\T61String) {
360
-            throw new \UnexpectedValueException(
361
-                $this->_generateExceptionMessage(Element::TYPE_T61_STRING));
362
-        }
363
-        return $this->_element;
364
-    }
365
-    
366
-    /**
367
-     * Get the wrapped element as a videotex string type.
368
-     *
369
-     * @throws \UnexpectedValueException If the element is not a videotex string
370
-     * @return \ASN1\Type\Primitive\VideotexString
371
-     */
372
-    public function asVideotexString(): Primitive\VideotexString
373
-    {
374
-        if (!$this->_element instanceof Primitive\VideotexString) {
375
-            throw new \UnexpectedValueException(
376
-                $this->_generateExceptionMessage(Element::TYPE_VIDEOTEX_STRING));
377
-        }
378
-        return $this->_element;
379
-    }
380
-    
381
-    /**
382
-     * Get the wrapped element as a IA5 string type.
383
-     *
384
-     * @throws \UnexpectedValueException If the element is not a IA5 string
385
-     * @return \ASN1\Type\Primitive\IA5String
386
-     */
387
-    public function asIA5String(): Primitive\IA5String
388
-    {
389
-        if (!$this->_element instanceof Primitive\IA5String) {
390
-            throw new \UnexpectedValueException(
391
-                $this->_generateExceptionMessage(Element::TYPE_IA5_STRING));
392
-        }
393
-        return $this->_element;
394
-    }
395
-    
396
-    /**
397
-     * Get the wrapped element as an UTC time type.
398
-     *
399
-     * @throws \UnexpectedValueException If the element is not a UTC time
400
-     * @return \ASN1\Type\Primitive\UTCTime
401
-     */
402
-    public function asUTCTime(): Primitive\UTCTime
403
-    {
404
-        if (!$this->_element instanceof Primitive\UTCTime) {
405
-            throw new \UnexpectedValueException(
406
-                $this->_generateExceptionMessage(Element::TYPE_UTC_TIME));
407
-        }
408
-        return $this->_element;
409
-    }
410
-    
411
-    /**
412
-     * Get the wrapped element as a generalized time type.
413
-     *
414
-     * @throws \UnexpectedValueException If the element is not a generalized
415
-     *         time
416
-     * @return \ASN1\Type\Primitive\GeneralizedTime
417
-     */
418
-    public function asGeneralizedTime(): Primitive\GeneralizedTime
419
-    {
420
-        if (!$this->_element instanceof Primitive\GeneralizedTime) {
421
-            throw new \UnexpectedValueException(
422
-                $this->_generateExceptionMessage(Element::TYPE_GENERALIZED_TIME));
423
-        }
424
-        return $this->_element;
425
-    }
426
-    
427
-    /**
428
-     * Get the wrapped element as a graphic string type.
429
-     *
430
-     * @throws \UnexpectedValueException If the element is not a graphic string
431
-     * @return \ASN1\Type\Primitive\GraphicString
432
-     */
433
-    public function asGraphicString(): Primitive\GraphicString
434
-    {
435
-        if (!$this->_element instanceof Primitive\GraphicString) {
436
-            throw new \UnexpectedValueException(
437
-                $this->_generateExceptionMessage(Element::TYPE_GRAPHIC_STRING));
438
-        }
439
-        return $this->_element;
440
-    }
441
-    
442
-    /**
443
-     * Get the wrapped element as a visible string type.
444
-     *
445
-     * @throws \UnexpectedValueException If the element is not a visible string
446
-     * @return \ASN1\Type\Primitive\VisibleString
447
-     */
448
-    public function asVisibleString(): Primitive\VisibleString
449
-    {
450
-        if (!$this->_element instanceof Primitive\VisibleString) {
451
-            throw new \UnexpectedValueException(
452
-                $this->_generateExceptionMessage(Element::TYPE_VISIBLE_STRING));
453
-        }
454
-        return $this->_element;
455
-    }
456
-    
457
-    /**
458
-     * Get the wrapped element as a general string type.
459
-     *
460
-     * @throws \UnexpectedValueException If the element is not general string
461
-     * @return \ASN1\Type\Primitive\GeneralString
462
-     */
463
-    public function asGeneralString(): Primitive\GeneralString
464
-    {
465
-        if (!$this->_element instanceof Primitive\GeneralString) {
466
-            throw new \UnexpectedValueException(
467
-                $this->_generateExceptionMessage(Element::TYPE_GENERAL_STRING));
468
-        }
469
-        return $this->_element;
470
-    }
471
-    
472
-    /**
473
-     * Get the wrapped element as a universal string type.
474
-     *
475
-     * @throws \UnexpectedValueException If the element is not a universal
476
-     *         string
477
-     * @return \ASN1\Type\Primitive\UniversalString
478
-     */
479
-    public function asUniversalString(): Primitive\UniversalString
480
-    {
481
-        if (!$this->_element instanceof Primitive\UniversalString) {
482
-            throw new \UnexpectedValueException(
483
-                $this->_generateExceptionMessage(Element::TYPE_UNIVERSAL_STRING));
484
-        }
485
-        return $this->_element;
486
-    }
487
-    
488
-    /**
489
-     * Get the wrapped element as a character string type.
490
-     *
491
-     * @throws \UnexpectedValueException If the element is not a character
492
-     *         string
493
-     * @return \ASN1\Type\Primitive\CharacterString
494
-     */
495
-    public function asCharacterString(): Primitive\CharacterString
496
-    {
497
-        if (!$this->_element instanceof Primitive\CharacterString) {
498
-            throw new \UnexpectedValueException(
499
-                $this->_generateExceptionMessage(Element::TYPE_CHARACTER_STRING));
500
-        }
501
-        return $this->_element;
502
-    }
503
-    
504
-    /**
505
-     * Get the wrapped element as a BMP string type.
506
-     *
507
-     * @throws \UnexpectedValueException If the element is not a bmp string
508
-     * @return \ASN1\Type\Primitive\BMPString
509
-     */
510
-    public function asBMPString(): Primitive\BMPString
511
-    {
512
-        if (!$this->_element instanceof Primitive\BMPString) {
513
-            throw new \UnexpectedValueException(
514
-                $this->_generateExceptionMessage(Element::TYPE_BMP_STRING));
515
-        }
516
-        return $this->_element;
517
-    }
518
-    
519
-    /**
520
-     * Get the wrapped element as a constructed string type.
521
-     *
522
-     * @throws \UnexpectedValueException If the element is not a constructed
523
-     *         string
524
-     * @return Constructed\ConstructedString
525
-     */
526
-    public function asConstructedString(): Constructed\ConstructedString
527
-    {
528
-        if (!$this->_element instanceof Constructed\ConstructedString) {
529
-            throw new \UnexpectedValueException(
530
-                $this->_generateExceptionMessage(
531
-                    Element::TYPE_CONSTRUCTED_STRING));
532
-        }
533
-        return $this->_element;
534
-    }
535
-    
536
-    /**
537
-     * Get the wrapped element as any string type.
538
-     *
539
-     * @throws \UnexpectedValueException If the element is not a string
540
-     * @return StringType
541
-     */
542
-    public function asString(): StringType
543
-    {
544
-        if (!$this->_element instanceof StringType) {
545
-            throw new \UnexpectedValueException(
546
-                $this->_generateExceptionMessage(Element::TYPE_STRING));
547
-        }
548
-        return $this->_element;
549
-    }
550
-    
551
-    /**
552
-     * Get the wrapped element as any time type.
553
-     *
554
-     * @throws \UnexpectedValueException If the element is not a time
555
-     * @return TimeType
556
-     */
557
-    public function asTime(): TimeType
558
-    {
559
-        if (!$this->_element instanceof TimeType) {
560
-            throw new \UnexpectedValueException(
561
-                $this->_generateExceptionMessage(Element::TYPE_TIME));
562
-        }
563
-        return $this->_element;
564
-    }
565
-    
566
-    /**
567
-     * Generate message for exceptions thrown by <code>as*</code> methods.
568
-     *
569
-     * @param int $tag Type tag of the expected element
570
-     * @return string
571
-     */
572
-    private function _generateExceptionMessage(int $tag): string
573
-    {
574
-        return sprintf("%s expected, got %s.", Element::tagToName($tag),
575
-            $this->_typeDescriptorString());
576
-    }
577
-    
578
-    /**
579
-     * Get textual description of the wrapped element for debugging purposes.
580
-     *
581
-     * @return string
582
-     */
583
-    private function _typeDescriptorString(): string
584
-    {
585
-        $type_cls = $this->_element->typeClass();
586
-        $tag = $this->_element->tag();
587
-        if ($type_cls == Identifier::CLASS_UNIVERSAL) {
588
-            return Element::tagToName($tag);
589
-        }
590
-        return Identifier::classToName($type_cls) . " TAG $tag";
591
-    }
592
-    
593
-    /**
594
-     *
595
-     * @see \ASN1\Feature\Encodable::toDER()
596
-     * @return string
597
-     */
598
-    public function toDER(): string
599
-    {
600
-        return $this->_element->toDER();
601
-    }
602
-    
603
-    /**
604
-     *
605
-     * @see \ASN1\Feature\ElementBase::typeClass()
606
-     * @return int
607
-     */
608
-    public function typeClass(): int
609
-    {
610
-        return $this->_element->typeClass();
611
-    }
612
-    
613
-    /**
614
-     *
615
-     * @see \ASN1\Feature\ElementBase::isConstructed()
616
-     * @return bool
617
-     */
618
-    public function isConstructed(): bool
619
-    {
620
-        return $this->_element->isConstructed();
621
-    }
622
-    
623
-    /**
624
-     *
625
-     * @see \ASN1\Feature\ElementBase::tag()
626
-     * @return int
627
-     */
628
-    public function tag(): int
629
-    {
630
-        return $this->_element->tag();
631
-    }
632
-    
633
-    /**
634
-     *
635
-     * {@inheritdoc}
636
-     * @see \ASN1\Feature\ElementBase::isType()
637
-     * @return bool
638
-     */
639
-    public function isType(int $tag): bool
640
-    {
641
-        return $this->_element->isType($tag);
642
-    }
643
-    
644
-    /**
645
-     *
646
-     * @deprecated Use any <code>as*</code> accessor method first to ensure
647
-     *             type strictness.
648
-     * @see \ASN1\Feature\ElementBase::expectType()
649
-     * @return ElementBase
650
-     */
651
-    public function expectType(int $tag): ElementBase
652
-    {
653
-        return $this->_element->expectType($tag);
654
-    }
655
-    
656
-    /**
657
-     *
658
-     * @see \ASN1\Feature\ElementBase::isTagged()
659
-     * @return bool
660
-     */
661
-    public function isTagged(): bool
662
-    {
663
-        return $this->_element->isTagged();
664
-    }
665
-    
666
-    /**
667
-     *
668
-     * @deprecated Use any <code>as*</code> accessor method first to ensure
669
-     *             type strictness.
670
-     * @see \ASN1\Feature\ElementBase::expectTagged()
671
-     * @return TaggedType
672
-     */
673
-    public function expectTagged($tag = null): TaggedType
674
-    {
675
-        return $this->_element->expectTagged($tag);
676
-    }
677
-    
678
-    /**
679
-     *
680
-     * @see \ASN1\Feature\ElementBase::asElement()
681
-     * @return Element
682
-     */
683
-    public function asElement(): Element
684
-    {
685
-        return $this->_element;
686
-    }
687
-    
688
-    /**
689
-     *
690
-     * {@inheritdoc}
691
-     * @return UnspecifiedType
692
-     */
693
-    public function asUnspecified(): UnspecifiedType
694
-    {
695
-        return $this;
696
-    }
19
+	/**
20
+	 * The wrapped element.
21
+	 *
22
+	 * @var Element
23
+	 */
24
+	private $_element;
25
+    
26
+	/**
27
+	 * Constructor.
28
+	 *
29
+	 * @param Element $el
30
+	 */
31
+	public function __construct(Element $el)
32
+	{
33
+		$this->_element = $el;
34
+	}
35
+    
36
+	/**
37
+	 * Initialize from DER data.
38
+	 *
39
+	 * @param string $data DER encoded data
40
+	 * @return self
41
+	 */
42
+	public static function fromDER(string $data): self
43
+	{
44
+		return Element::fromDER($data)->asUnspecified();
45
+	}
46
+    
47
+	/**
48
+	 * Initialize from ElementBase interface.
49
+	 *
50
+	 * @param ElementBase $el
51
+	 * @return self
52
+	 */
53
+	public static function fromElementBase(ElementBase $el): self
54
+	{
55
+		// if element is already wrapped
56
+		if ($el instanceof self) {
57
+			return $el;
58
+		}
59
+		return new self($el->asElement());
60
+	}
61
+    
62
+	/**
63
+	 * Compatibility method to dispatch calls to the wrapped element.
64
+	 *
65
+	 * @deprecated Use <code>as*</code> accessor methods to ensure strict type
66
+	 * @param string $mtd Method name
67
+	 * @param array $args Arguments
68
+	 * @return mixed
69
+	 */
70
+	public function __call($mtd, array $args)
71
+	{
72
+		return call_user_func_array([$this->_element, $mtd], $args);
73
+	}
74
+    
75
+	/**
76
+	 * Get the wrapped element as a context specific tagged type.
77
+	 *
78
+	 * @throws \UnexpectedValueException If the element is not tagged
79
+	 * @return TaggedType
80
+	 */
81
+	public function asTagged(): TaggedType
82
+	{
83
+		if (!$this->_element instanceof TaggedType) {
84
+			throw new \UnexpectedValueException(
85
+				"Tagged element expected, got " . $this->_typeDescriptorString());
86
+		}
87
+		return $this->_element;
88
+	}
89
+    
90
+	/**
91
+	 * Get the wrapped element as an application specific type.
92
+	 *
93
+	 * @throws \UnexpectedValueException If element is not application specific
94
+	 * @return \ASN1\Type\Tagged\ApplicationType
95
+	 */
96
+	public function asApplication(): Tagged\ApplicationType
97
+	{
98
+		if (!$this->_element instanceof Tagged\ApplicationType) {
99
+			throw new \UnexpectedValueException(
100
+				"Application type expected, got " .
101
+				$this->_typeDescriptorString());
102
+		}
103
+		return $this->_element;
104
+	}
105
+    
106
+	/**
107
+	 * Get the wrapped element as a private tagged type.
108
+	 *
109
+	 * @throws \UnexpectedValueException If element is not using private tagging
110
+	 * @return \ASN1\Type\Tagged\PrivateType
111
+	 */
112
+	public function asPrivate(): Tagged\PrivateType
113
+	{
114
+		if (!$this->_element instanceof Tagged\PrivateType) {
115
+			throw new \UnexpectedValueException(
116
+				"Private type expected, got " . $this->_typeDescriptorString());
117
+		}
118
+		return $this->_element;
119
+	}
120
+    
121
+	/**
122
+	 * Get the wrapped element as a boolean type.
123
+	 *
124
+	 * @throws \UnexpectedValueException If the element is not a boolean
125
+	 * @return \ASN1\Type\Primitive\Boolean
126
+	 */
127
+	public function asBoolean(): Primitive\Boolean
128
+	{
129
+		if (!$this->_element instanceof Primitive\Boolean) {
130
+			throw new \UnexpectedValueException(
131
+				$this->_generateExceptionMessage(Element::TYPE_BOOLEAN));
132
+		}
133
+		return $this->_element;
134
+	}
135
+    
136
+	/**
137
+	 * Get the wrapped element as an integer type.
138
+	 *
139
+	 * @throws \UnexpectedValueException If the element is not an integer
140
+	 * @return \ASN1\Type\Primitive\Integer
141
+	 */
142
+	public function asInteger(): Primitive\Integer
143
+	{
144
+		if (!$this->_element instanceof Primitive\Integer) {
145
+			throw new \UnexpectedValueException(
146
+				$this->_generateExceptionMessage(Element::TYPE_INTEGER));
147
+		}
148
+		return $this->_element;
149
+	}
150
+    
151
+	/**
152
+	 * Get the wrapped element as a bit string type.
153
+	 *
154
+	 * @throws \UnexpectedValueException If the element is not a bit string
155
+	 * @return \ASN1\Type\Primitive\BitString
156
+	 */
157
+	public function asBitString(): Primitive\BitString
158
+	{
159
+		if (!$this->_element instanceof Primitive\BitString) {
160
+			throw new \UnexpectedValueException(
161
+				$this->_generateExceptionMessage(Element::TYPE_BIT_STRING));
162
+		}
163
+		return $this->_element;
164
+	}
165
+    
166
+	/**
167
+	 * Get the wrapped element as an octet string type.
168
+	 *
169
+	 * @throws \UnexpectedValueException If the element is not an octet string
170
+	 * @return \ASN1\Type\Primitive\OctetString
171
+	 */
172
+	public function asOctetString(): Primitive\OctetString
173
+	{
174
+		if (!$this->_element instanceof Primitive\OctetString) {
175
+			throw new \UnexpectedValueException(
176
+				$this->_generateExceptionMessage(Element::TYPE_OCTET_STRING));
177
+		}
178
+		return $this->_element;
179
+	}
180
+    
181
+	/**
182
+	 * Get the wrapped element as a null type.
183
+	 *
184
+	 * @throws \UnexpectedValueException If the element is not a null
185
+	 * @return \ASN1\Type\Primitive\NullType
186
+	 */
187
+	public function asNull(): Primitive\NullType
188
+	{
189
+		if (!$this->_element instanceof Primitive\NullType) {
190
+			throw new \UnexpectedValueException(
191
+				$this->_generateExceptionMessage(Element::TYPE_NULL));
192
+		}
193
+		return $this->_element;
194
+	}
195
+    
196
+	/**
197
+	 * Get the wrapped element as an object identifier type.
198
+	 *
199
+	 * @throws \UnexpectedValueException If the element is not an object
200
+	 *         identifier
201
+	 * @return \ASN1\Type\Primitive\ObjectIdentifier
202
+	 */
203
+	public function asObjectIdentifier(): Primitive\ObjectIdentifier
204
+	{
205
+		if (!$this->_element instanceof Primitive\ObjectIdentifier) {
206
+			throw new \UnexpectedValueException(
207
+				$this->_generateExceptionMessage(
208
+					Element::TYPE_OBJECT_IDENTIFIER));
209
+		}
210
+		return $this->_element;
211
+	}
212
+    
213
+	/**
214
+	 * Get the wrapped element as an object descriptor type.
215
+	 *
216
+	 * @throws \UnexpectedValueException If the element is not an object
217
+	 *         descriptor
218
+	 * @return \ASN1\Type\Primitive\ObjectDescriptor
219
+	 */
220
+	public function asObjectDescriptor(): Primitive\ObjectDescriptor
221
+	{
222
+		if (!$this->_element instanceof Primitive\ObjectDescriptor) {
223
+			throw new \UnexpectedValueException(
224
+				$this->_generateExceptionMessage(
225
+					Element::TYPE_OBJECT_DESCRIPTOR));
226
+		}
227
+		return $this->_element;
228
+	}
229
+    
230
+	/**
231
+	 * Get the wrapped element as a real type.
232
+	 *
233
+	 * @throws \UnexpectedValueException If the element is not a real
234
+	 * @return \ASN1\Type\Primitive\Real
235
+	 */
236
+	public function asReal(): Primitive\Real
237
+	{
238
+		if (!$this->_element instanceof Primitive\Real) {
239
+			throw new \UnexpectedValueException(
240
+				$this->_generateExceptionMessage(Element::TYPE_REAL));
241
+		}
242
+		return $this->_element;
243
+	}
244
+    
245
+	/**
246
+	 * Get the wrapped element as an enumerated type.
247
+	 *
248
+	 * @throws \UnexpectedValueException If the element is not an enumerated
249
+	 * @return \ASN1\Type\Primitive\Enumerated
250
+	 */
251
+	public function asEnumerated(): Primitive\Enumerated
252
+	{
253
+		if (!$this->_element instanceof Primitive\Enumerated) {
254
+			throw new \UnexpectedValueException(
255
+				$this->_generateExceptionMessage(Element::TYPE_ENUMERATED));
256
+		}
257
+		return $this->_element;
258
+	}
259
+    
260
+	/**
261
+	 * Get the wrapped element as a UTF8 string type.
262
+	 *
263
+	 * @throws \UnexpectedValueException If the element is not a UTF8 string
264
+	 * @return \ASN1\Type\Primitive\UTF8String
265
+	 */
266
+	public function asUTF8String(): Primitive\UTF8String
267
+	{
268
+		if (!$this->_element instanceof Primitive\UTF8String) {
269
+			throw new \UnexpectedValueException(
270
+				$this->_generateExceptionMessage(Element::TYPE_UTF8_STRING));
271
+		}
272
+		return $this->_element;
273
+	}
274
+    
275
+	/**
276
+	 * Get the wrapped element as a relative OID type.
277
+	 *
278
+	 * @throws \UnexpectedValueException If the element is not a relative OID
279
+	 * @return \ASN1\Type\Primitive\RelativeOID
280
+	 */
281
+	public function asRelativeOID(): Primitive\RelativeOID
282
+	{
283
+		if (!$this->_element instanceof Primitive\RelativeOID) {
284
+			throw new \UnexpectedValueException(
285
+				$this->_generateExceptionMessage(Element::TYPE_RELATIVE_OID));
286
+		}
287
+		return $this->_element;
288
+	}
289
+    
290
+	/**
291
+	 * Get the wrapped element as a sequence type.
292
+	 *
293
+	 * @throws \UnexpectedValueException If the element is not a sequence
294
+	 * @return \ASN1\Type\Constructed\Sequence
295
+	 */
296
+	public function asSequence(): Constructed\Sequence
297
+	{
298
+		if (!$this->_element instanceof Constructed\Sequence) {
299
+			throw new \UnexpectedValueException(
300
+				$this->_generateExceptionMessage(Element::TYPE_SEQUENCE));
301
+		}
302
+		return $this->_element;
303
+	}
304
+    
305
+	/**
306
+	 * Get the wrapped element as a set type.
307
+	 *
308
+	 * @throws \UnexpectedValueException If the element is not a set
309
+	 * @return \ASN1\Type\Constructed\Set
310
+	 */
311
+	public function asSet(): Constructed\Set
312
+	{
313
+		if (!$this->_element instanceof Constructed\Set) {
314
+			throw new \UnexpectedValueException(
315
+				$this->_generateExceptionMessage(Element::TYPE_SET));
316
+		}
317
+		return $this->_element;
318
+	}
319
+    
320
+	/**
321
+	 * Get the wrapped element as a numeric string type.
322
+	 *
323
+	 * @throws \UnexpectedValueException If the element is not a numeric string
324
+	 * @return \ASN1\Type\Primitive\NumericString
325
+	 */
326
+	public function asNumericString(): Primitive\NumericString
327
+	{
328
+		if (!$this->_element instanceof Primitive\NumericString) {
329
+			throw new \UnexpectedValueException(
330
+				$this->_generateExceptionMessage(Element::TYPE_NUMERIC_STRING));
331
+		}
332
+		return $this->_element;
333
+	}
334
+    
335
+	/**
336
+	 * Get the wrapped element as a printable string type.
337
+	 *
338
+	 * @throws \UnexpectedValueException If the element is not a printable
339
+	 *         string
340
+	 * @return \ASN1\Type\Primitive\PrintableString
341
+	 */
342
+	public function asPrintableString(): Primitive\PrintableString
343
+	{
344
+		if (!$this->_element instanceof Primitive\PrintableString) {
345
+			throw new \UnexpectedValueException(
346
+				$this->_generateExceptionMessage(Element::TYPE_PRINTABLE_STRING));
347
+		}
348
+		return $this->_element;
349
+	}
350
+    
351
+	/**
352
+	 * Get the wrapped element as a T61 string type.
353
+	 *
354
+	 * @throws \UnexpectedValueException If the element is not a T61 string
355
+	 * @return \ASN1\Type\Primitive\T61String
356
+	 */
357
+	public function asT61String(): Primitive\T61String
358
+	{
359
+		if (!$this->_element instanceof Primitive\T61String) {
360
+			throw new \UnexpectedValueException(
361
+				$this->_generateExceptionMessage(Element::TYPE_T61_STRING));
362
+		}
363
+		return $this->_element;
364
+	}
365
+    
366
+	/**
367
+	 * Get the wrapped element as a videotex string type.
368
+	 *
369
+	 * @throws \UnexpectedValueException If the element is not a videotex string
370
+	 * @return \ASN1\Type\Primitive\VideotexString
371
+	 */
372
+	public function asVideotexString(): Primitive\VideotexString
373
+	{
374
+		if (!$this->_element instanceof Primitive\VideotexString) {
375
+			throw new \UnexpectedValueException(
376
+				$this->_generateExceptionMessage(Element::TYPE_VIDEOTEX_STRING));
377
+		}
378
+		return $this->_element;
379
+	}
380
+    
381
+	/**
382
+	 * Get the wrapped element as a IA5 string type.
383
+	 *
384
+	 * @throws \UnexpectedValueException If the element is not a IA5 string
385
+	 * @return \ASN1\Type\Primitive\IA5String
386
+	 */
387
+	public function asIA5String(): Primitive\IA5String
388
+	{
389
+		if (!$this->_element instanceof Primitive\IA5String) {
390
+			throw new \UnexpectedValueException(
391
+				$this->_generateExceptionMessage(Element::TYPE_IA5_STRING));
392
+		}
393
+		return $this->_element;
394
+	}
395
+    
396
+	/**
397
+	 * Get the wrapped element as an UTC time type.
398
+	 *
399
+	 * @throws \UnexpectedValueException If the element is not a UTC time
400
+	 * @return \ASN1\Type\Primitive\UTCTime
401
+	 */
402
+	public function asUTCTime(): Primitive\UTCTime
403
+	{
404
+		if (!$this->_element instanceof Primitive\UTCTime) {
405
+			throw new \UnexpectedValueException(
406
+				$this->_generateExceptionMessage(Element::TYPE_UTC_TIME));
407
+		}
408
+		return $this->_element;
409
+	}
410
+    
411
+	/**
412
+	 * Get the wrapped element as a generalized time type.
413
+	 *
414
+	 * @throws \UnexpectedValueException If the element is not a generalized
415
+	 *         time
416
+	 * @return \ASN1\Type\Primitive\GeneralizedTime
417
+	 */
418
+	public function asGeneralizedTime(): Primitive\GeneralizedTime
419
+	{
420
+		if (!$this->_element instanceof Primitive\GeneralizedTime) {
421
+			throw new \UnexpectedValueException(
422
+				$this->_generateExceptionMessage(Element::TYPE_GENERALIZED_TIME));
423
+		}
424
+		return $this->_element;
425
+	}
426
+    
427
+	/**
428
+	 * Get the wrapped element as a graphic string type.
429
+	 *
430
+	 * @throws \UnexpectedValueException If the element is not a graphic string
431
+	 * @return \ASN1\Type\Primitive\GraphicString
432
+	 */
433
+	public function asGraphicString(): Primitive\GraphicString
434
+	{
435
+		if (!$this->_element instanceof Primitive\GraphicString) {
436
+			throw new \UnexpectedValueException(
437
+				$this->_generateExceptionMessage(Element::TYPE_GRAPHIC_STRING));
438
+		}
439
+		return $this->_element;
440
+	}
441
+    
442
+	/**
443
+	 * Get the wrapped element as a visible string type.
444
+	 *
445
+	 * @throws \UnexpectedValueException If the element is not a visible string
446
+	 * @return \ASN1\Type\Primitive\VisibleString
447
+	 */
448
+	public function asVisibleString(): Primitive\VisibleString
449
+	{
450
+		if (!$this->_element instanceof Primitive\VisibleString) {
451
+			throw new \UnexpectedValueException(
452
+				$this->_generateExceptionMessage(Element::TYPE_VISIBLE_STRING));
453
+		}
454
+		return $this->_element;
455
+	}
456
+    
457
+	/**
458
+	 * Get the wrapped element as a general string type.
459
+	 *
460
+	 * @throws \UnexpectedValueException If the element is not general string
461
+	 * @return \ASN1\Type\Primitive\GeneralString
462
+	 */
463
+	public function asGeneralString(): Primitive\GeneralString
464
+	{
465
+		if (!$this->_element instanceof Primitive\GeneralString) {
466
+			throw new \UnexpectedValueException(
467
+				$this->_generateExceptionMessage(Element::TYPE_GENERAL_STRING));
468
+		}
469
+		return $this->_element;
470
+	}
471
+    
472
+	/**
473
+	 * Get the wrapped element as a universal string type.
474
+	 *
475
+	 * @throws \UnexpectedValueException If the element is not a universal
476
+	 *         string
477
+	 * @return \ASN1\Type\Primitive\UniversalString
478
+	 */
479
+	public function asUniversalString(): Primitive\UniversalString
480
+	{
481
+		if (!$this->_element instanceof Primitive\UniversalString) {
482
+			throw new \UnexpectedValueException(
483
+				$this->_generateExceptionMessage(Element::TYPE_UNIVERSAL_STRING));
484
+		}
485
+		return $this->_element;
486
+	}
487
+    
488
+	/**
489
+	 * Get the wrapped element as a character string type.
490
+	 *
491
+	 * @throws \UnexpectedValueException If the element is not a character
492
+	 *         string
493
+	 * @return \ASN1\Type\Primitive\CharacterString
494
+	 */
495
+	public function asCharacterString(): Primitive\CharacterString
496
+	{
497
+		if (!$this->_element instanceof Primitive\CharacterString) {
498
+			throw new \UnexpectedValueException(
499
+				$this->_generateExceptionMessage(Element::TYPE_CHARACTER_STRING));
500
+		}
501
+		return $this->_element;
502
+	}
503
+    
504
+	/**
505
+	 * Get the wrapped element as a BMP string type.
506
+	 *
507
+	 * @throws \UnexpectedValueException If the element is not a bmp string
508
+	 * @return \ASN1\Type\Primitive\BMPString
509
+	 */
510
+	public function asBMPString(): Primitive\BMPString
511
+	{
512
+		if (!$this->_element instanceof Primitive\BMPString) {
513
+			throw new \UnexpectedValueException(
514
+				$this->_generateExceptionMessage(Element::TYPE_BMP_STRING));
515
+		}
516
+		return $this->_element;
517
+	}
518
+    
519
+	/**
520
+	 * Get the wrapped element as a constructed string type.
521
+	 *
522
+	 * @throws \UnexpectedValueException If the element is not a constructed
523
+	 *         string
524
+	 * @return Constructed\ConstructedString
525
+	 */
526
+	public function asConstructedString(): Constructed\ConstructedString
527
+	{
528
+		if (!$this->_element instanceof Constructed\ConstructedString) {
529
+			throw new \UnexpectedValueException(
530
+				$this->_generateExceptionMessage(
531
+					Element::TYPE_CONSTRUCTED_STRING));
532
+		}
533
+		return $this->_element;
534
+	}
535
+    
536
+	/**
537
+	 * Get the wrapped element as any string type.
538
+	 *
539
+	 * @throws \UnexpectedValueException If the element is not a string
540
+	 * @return StringType
541
+	 */
542
+	public function asString(): StringType
543
+	{
544
+		if (!$this->_element instanceof StringType) {
545
+			throw new \UnexpectedValueException(
546
+				$this->_generateExceptionMessage(Element::TYPE_STRING));
547
+		}
548
+		return $this->_element;
549
+	}
550
+    
551
+	/**
552
+	 * Get the wrapped element as any time type.
553
+	 *
554
+	 * @throws \UnexpectedValueException If the element is not a time
555
+	 * @return TimeType
556
+	 */
557
+	public function asTime(): TimeType
558
+	{
559
+		if (!$this->_element instanceof TimeType) {
560
+			throw new \UnexpectedValueException(
561
+				$this->_generateExceptionMessage(Element::TYPE_TIME));
562
+		}
563
+		return $this->_element;
564
+	}
565
+    
566
+	/**
567
+	 * Generate message for exceptions thrown by <code>as*</code> methods.
568
+	 *
569
+	 * @param int $tag Type tag of the expected element
570
+	 * @return string
571
+	 */
572
+	private function _generateExceptionMessage(int $tag): string
573
+	{
574
+		return sprintf("%s expected, got %s.", Element::tagToName($tag),
575
+			$this->_typeDescriptorString());
576
+	}
577
+    
578
+	/**
579
+	 * Get textual description of the wrapped element for debugging purposes.
580
+	 *
581
+	 * @return string
582
+	 */
583
+	private function _typeDescriptorString(): string
584
+	{
585
+		$type_cls = $this->_element->typeClass();
586
+		$tag = $this->_element->tag();
587
+		if ($type_cls == Identifier::CLASS_UNIVERSAL) {
588
+			return Element::tagToName($tag);
589
+		}
590
+		return Identifier::classToName($type_cls) . " TAG $tag";
591
+	}
592
+    
593
+	/**
594
+	 *
595
+	 * @see \ASN1\Feature\Encodable::toDER()
596
+	 * @return string
597
+	 */
598
+	public function toDER(): string
599
+	{
600
+		return $this->_element->toDER();
601
+	}
602
+    
603
+	/**
604
+	 *
605
+	 * @see \ASN1\Feature\ElementBase::typeClass()
606
+	 * @return int
607
+	 */
608
+	public function typeClass(): int
609
+	{
610
+		return $this->_element->typeClass();
611
+	}
612
+    
613
+	/**
614
+	 *
615
+	 * @see \ASN1\Feature\ElementBase::isConstructed()
616
+	 * @return bool
617
+	 */
618
+	public function isConstructed(): bool
619
+	{
620
+		return $this->_element->isConstructed();
621
+	}
622
+    
623
+	/**
624
+	 *
625
+	 * @see \ASN1\Feature\ElementBase::tag()
626
+	 * @return int
627
+	 */
628
+	public function tag(): int
629
+	{
630
+		return $this->_element->tag();
631
+	}
632
+    
633
+	/**
634
+	 *
635
+	 * {@inheritdoc}
636
+	 * @see \ASN1\Feature\ElementBase::isType()
637
+	 * @return bool
638
+	 */
639
+	public function isType(int $tag): bool
640
+	{
641
+		return $this->_element->isType($tag);
642
+	}
643
+    
644
+	/**
645
+	 *
646
+	 * @deprecated Use any <code>as*</code> accessor method first to ensure
647
+	 *             type strictness.
648
+	 * @see \ASN1\Feature\ElementBase::expectType()
649
+	 * @return ElementBase
650
+	 */
651
+	public function expectType(int $tag): ElementBase
652
+	{
653
+		return $this->_element->expectType($tag);
654
+	}
655
+    
656
+	/**
657
+	 *
658
+	 * @see \ASN1\Feature\ElementBase::isTagged()
659
+	 * @return bool
660
+	 */
661
+	public function isTagged(): bool
662
+	{
663
+		return $this->_element->isTagged();
664
+	}
665
+    
666
+	/**
667
+	 *
668
+	 * @deprecated Use any <code>as*</code> accessor method first to ensure
669
+	 *             type strictness.
670
+	 * @see \ASN1\Feature\ElementBase::expectTagged()
671
+	 * @return TaggedType
672
+	 */
673
+	public function expectTagged($tag = null): TaggedType
674
+	{
675
+		return $this->_element->expectTagged($tag);
676
+	}
677
+    
678
+	/**
679
+	 *
680
+	 * @see \ASN1\Feature\ElementBase::asElement()
681
+	 * @return Element
682
+	 */
683
+	public function asElement(): Element
684
+	{
685
+		return $this->_element;
686
+	}
687
+    
688
+	/**
689
+	 *
690
+	 * {@inheritdoc}
691
+	 * @return UnspecifiedType
692
+	 */
693
+	public function asUnspecified(): UnspecifiedType
694
+	{
695
+		return $this;
696
+	}
697 697
 }
Please login to merge, or discard this patch.
lib/ASN1/Type/TimeType.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace ASN1\Type;
6 6
 
Please login to merge, or discard this patch.
Indentation   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -10,88 +10,88 @@
 block discarded – undo
10 10
  */
11 11
 abstract class TimeType extends Element
12 12
 {
13
-    /**
14
-     * UTC timezone.
15
-     *
16
-     * @var string
17
-     */
18
-    const TZ_UTC = "UTC";
13
+	/**
14
+	 * UTC timezone.
15
+	 *
16
+	 * @var string
17
+	 */
18
+	const TZ_UTC = "UTC";
19 19
     
20
-    /**
21
-     * Date and time.
22
-     *
23
-     * @var \DateTimeImmutable $_dateTime
24
-     */
25
-    protected $_dateTime;
20
+	/**
21
+	 * Date and time.
22
+	 *
23
+	 * @var \DateTimeImmutable $_dateTime
24
+	 */
25
+	protected $_dateTime;
26 26
     
27
-    /**
28
-     * Constructor.
29
-     *
30
-     * @param \DateTimeImmutable $dt
31
-     */
32
-    public function __construct(\DateTimeImmutable $dt)
33
-    {
34
-        $this->_dateTime = $dt;
35
-    }
27
+	/**
28
+	 * Constructor.
29
+	 *
30
+	 * @param \DateTimeImmutable $dt
31
+	 */
32
+	public function __construct(\DateTimeImmutable $dt)
33
+	{
34
+		$this->_dateTime = $dt;
35
+	}
36 36
     
37
-    /**
38
-     * Initialize from datetime string.
39
-     *
40
-     * @link http://php.net/manual/en/datetime.formats.php
41
-     * @param string $time Time string
42
-     * @param string|null $tz Timezone, if null use default.
43
-     * @throws \RuntimeException
44
-     * @return self
45
-     */
46
-    public static function fromString(string $time, string $tz = null): self
47
-    {
48
-        try {
49
-            if (!isset($tz)) {
50
-                $tz = date_default_timezone_get();
51
-            }
52
-            return new static(
53
-                new \DateTimeImmutable($time, self::_createTimeZone($tz)));
54
-        } catch (\Exception $e) {
55
-            throw new \RuntimeException(
56
-                "Failed to create DateTime: " .
57
-                self::_getLastDateTimeImmutableErrorsStr(), 0, $e);
58
-        }
59
-    }
37
+	/**
38
+	 * Initialize from datetime string.
39
+	 *
40
+	 * @link http://php.net/manual/en/datetime.formats.php
41
+	 * @param string $time Time string
42
+	 * @param string|null $tz Timezone, if null use default.
43
+	 * @throws \RuntimeException
44
+	 * @return self
45
+	 */
46
+	public static function fromString(string $time, string $tz = null): self
47
+	{
48
+		try {
49
+			if (!isset($tz)) {
50
+				$tz = date_default_timezone_get();
51
+			}
52
+			return new static(
53
+				new \DateTimeImmutable($time, self::_createTimeZone($tz)));
54
+		} catch (\Exception $e) {
55
+			throw new \RuntimeException(
56
+				"Failed to create DateTime: " .
57
+				self::_getLastDateTimeImmutableErrorsStr(), 0, $e);
58
+		}
59
+	}
60 60
     
61
-    /**
62
-     * Get the date and time.
63
-     *
64
-     * @return \DateTimeImmutable
65
-     */
66
-    public function dateTime(): \DateTimeImmutable
67
-    {
68
-        return $this->_dateTime;
69
-    }
61
+	/**
62
+	 * Get the date and time.
63
+	 *
64
+	 * @return \DateTimeImmutable
65
+	 */
66
+	public function dateTime(): \DateTimeImmutable
67
+	{
68
+		return $this->_dateTime;
69
+	}
70 70
     
71
-    /**
72
-     * Create DateTimeZone object from string.
73
-     *
74
-     * @param string $tz
75
-     * @throws \UnexpectedValueException If timezone is invalid
76
-     * @return \DateTimeZone
77
-     */
78
-    protected static function _createTimeZone(string $tz): \DateTimeZone
79
-    {
80
-        try {
81
-            return new \DateTimeZone($tz);
82
-        } catch (\Exception $e) {
83
-            throw new \UnexpectedValueException("Invalid timezone.", 0, $e);
84
-        }
85
-    }
71
+	/**
72
+	 * Create DateTimeZone object from string.
73
+	 *
74
+	 * @param string $tz
75
+	 * @throws \UnexpectedValueException If timezone is invalid
76
+	 * @return \DateTimeZone
77
+	 */
78
+	protected static function _createTimeZone(string $tz): \DateTimeZone
79
+	{
80
+		try {
81
+			return new \DateTimeZone($tz);
82
+		} catch (\Exception $e) {
83
+			throw new \UnexpectedValueException("Invalid timezone.", 0, $e);
84
+		}
85
+	}
86 86
     
87
-    /**
88
-     * Get last error caused by DateTimeImmutable.
89
-     *
90
-     * @return string
91
-     */
92
-    protected static function _getLastDateTimeImmutableErrorsStr(): string
93
-    {
94
-        $errors = \DateTimeImmutable::getLastErrors()["errors"];
95
-        return implode(", ", $errors);
96
-    }
87
+	/**
88
+	 * Get last error caused by DateTimeImmutable.
89
+	 *
90
+	 * @return string
91
+	 */
92
+	protected static function _getLastDateTimeImmutableErrorsStr(): string
93
+	{
94
+		$errors = \DateTimeImmutable::getLastErrors()["errors"];
95
+		return implode(", ", $errors);
96
+	}
97 97
 }
Please login to merge, or discard this patch.