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