GitHub Access Token became invalid

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