GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( bbf871...0c2b8c )
by Joni
16:54
created
lib/ASN1/Type/PrimitiveString.php 2 patches
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -14,41 +14,41 @@
 block discarded – undo
14 14
  */
15 15
 abstract class PrimitiveString extends StringType
16 16
 {
17
-    use PrimitiveType;
17
+	use PrimitiveType;
18 18
     
19
-    /**
20
-     *
21
-     * @see \ASN1\Element::_encodedContentDER()
22
-     * @return string
23
-     */
24
-    protected function _encodedContentDER(): string
25
-    {
26
-        return $this->_string;
27
-    }
19
+	/**
20
+	 *
21
+	 * @see \ASN1\Element::_encodedContentDER()
22
+	 * @return string
23
+	 */
24
+	protected function _encodedContentDER(): string
25
+	{
26
+		return $this->_string;
27
+	}
28 28
     
29
-    /**
30
-     *
31
-     * {@inheritdoc}
32
-     * @see \ASN1\Element::_decodeFromDER()
33
-     * @return self
34
-     */
35
-    protected static function _decodeFromDER(Identifier $identifier, string $data,
36
-        int &$offset): ElementBase
37
-    {
38
-        $idx = $offset;
39
-        if (!$identifier->isPrimitive()) {
40
-            throw new DecodeException("DER encoded string must be primitive.");
41
-        }
42
-        $length = Length::expectFromDER($data, $idx)->intLength();
43
-        $str = $length ? substr($data, $idx, $length) : "";
44
-        // substr should never return false, since length is
45
-        // checked by Length::expectFromDER.
46
-        assert(is_string($str), new DecodeException("substr"));
47
-        $offset = $idx + $length;
48
-        try {
49
-            return new static($str);
50
-        } catch (\InvalidArgumentException $e) {
51
-            throw new DecodeException($e->getMessage(), 0, $e);
52
-        }
53
-    }
29
+	/**
30
+	 *
31
+	 * {@inheritdoc}
32
+	 * @see \ASN1\Element::_decodeFromDER()
33
+	 * @return self
34
+	 */
35
+	protected static function _decodeFromDER(Identifier $identifier, string $data,
36
+		int &$offset): ElementBase
37
+	{
38
+		$idx = $offset;
39
+		if (!$identifier->isPrimitive()) {
40
+			throw new DecodeException("DER encoded string must be primitive.");
41
+		}
42
+		$length = Length::expectFromDER($data, $idx)->intLength();
43
+		$str = $length ? substr($data, $idx, $length) : "";
44
+		// substr should never return false, since length is
45
+		// checked by Length::expectFromDER.
46
+		assert(is_string($str), new DecodeException("substr"));
47
+		$offset = $idx + $length;
48
+		try {
49
+			return new static($str);
50
+		} catch (\InvalidArgumentException $e) {
51
+			throw new DecodeException($e->getMessage(), 0, $e);
52
+		}
53
+	}
54 54
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace ASN1\Type;
6 6
 
Please login to merge, or discard this patch.
lib/ASN1/Type/Constructed/Sequence.php 2 patches
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -12,14 +12,14 @@
 block discarded – undo
12 12
  */
13 13
 class Sequence extends Structure
14 14
 {
15
-    /**
16
-     * Constructor.
17
-     *
18
-     * @param Element ...$elements Any number of elements
19
-     */
20
-    public function __construct(Element ...$elements)
21
-    {
22
-        $this->_typeTag = self::TYPE_SEQUENCE;
23
-        parent::__construct(...$elements);
24
-    }
15
+	/**
16
+	 * Constructor.
17
+	 *
18
+	 * @param Element ...$elements Any number of elements
19
+	 */
20
+	public function __construct(Element ...$elements)
21
+	{
22
+		$this->_typeTag = self::TYPE_SEQUENCE;
23
+		parent::__construct(...$elements);
24
+	}
25 25
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace ASN1\Type\Constructed;
6 6
 
Please login to merge, or discard this patch.
lib/ASN1/Type/Constructed/Set.php 2 patches
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -12,54 +12,54 @@
 block discarded – undo
12 12
  */
13 13
 class Set extends Structure
14 14
 {
15
-    /**
16
-     * Constructor.
17
-     *
18
-     * @param Element ...$elements Any number of elements
19
-     */
20
-    public function __construct(Element ...$elements)
21
-    {
22
-        $this->_typeTag = self::TYPE_SET;
23
-        parent::__construct(...$elements);
24
-    }
15
+	/**
16
+	 * Constructor.
17
+	 *
18
+	 * @param Element ...$elements Any number of elements
19
+	 */
20
+	public function __construct(Element ...$elements)
21
+	{
22
+		$this->_typeTag = self::TYPE_SET;
23
+		parent::__construct(...$elements);
24
+	}
25 25
     
26
-    /**
27
-     * Sort by canonical ascending order.
28
-     * Used for DER encoding of SET type.
29
-     *
30
-     * @return self
31
-     */
32
-    public function sortedSet(): self
33
-    {
34
-        $obj = clone $this;
35
-        usort($obj->_elements,
36
-            function (Element $a, Element $b) {
37
-                if ($a->typeClass() != $b->typeClass()) {
38
-                    return $a->typeClass() < $b->typeClass() ? -1 : 1;
39
-                }
40
-                if ($a->tag() == $b->tag()) {
41
-                    return 0;
42
-                }
43
-                return $a->tag() < $b->tag() ? -1 : 1;
44
-            });
45
-        return $obj;
46
-    }
26
+	/**
27
+	 * Sort by canonical ascending order.
28
+	 * Used for DER encoding of SET type.
29
+	 *
30
+	 * @return self
31
+	 */
32
+	public function sortedSet(): self
33
+	{
34
+		$obj = clone $this;
35
+		usort($obj->_elements,
36
+			function (Element $a, Element $b) {
37
+				if ($a->typeClass() != $b->typeClass()) {
38
+					return $a->typeClass() < $b->typeClass() ? -1 : 1;
39
+				}
40
+				if ($a->tag() == $b->tag()) {
41
+					return 0;
42
+				}
43
+				return $a->tag() < $b->tag() ? -1 : 1;
44
+			});
45
+		return $obj;
46
+	}
47 47
     
48
-    /**
49
-     * Sort by encoding ascending order.
50
-     * Used for DER encoding of SET OF type.
51
-     *
52
-     * @return self
53
-     */
54
-    public function sortedSetOf(): self
55
-    {
56
-        $obj = clone $this;
57
-        usort($obj->_elements,
58
-            function (Element $a, Element $b) {
59
-                $a_der = $a->toDER();
60
-                $b_der = $b->toDER();
61
-                return strcmp($a_der, $b_der);
62
-            });
63
-        return $obj;
64
-    }
48
+	/**
49
+	 * Sort by encoding ascending order.
50
+	 * Used for DER encoding of SET OF type.
51
+	 *
52
+	 * @return self
53
+	 */
54
+	public function sortedSetOf(): self
55
+	{
56
+		$obj = clone $this;
57
+		usort($obj->_elements,
58
+			function (Element $a, Element $b) {
59
+				$a_der = $a->toDER();
60
+				$b_der = $b->toDER();
61
+				return strcmp($a_der, $b_der);
62
+			});
63
+		return $obj;
64
+	}
65 65
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace ASN1\Type\Constructed;
6 6
 
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
     {
34 34
         $obj = clone $this;
35 35
         usort($obj->_elements,
36
-            function (Element $a, Element $b) {
36
+            function(Element $a, Element $b) {
37 37
                 if ($a->typeClass() != $b->typeClass()) {
38 38
                     return $a->typeClass() < $b->typeClass() ? -1 : 1;
39 39
                 }
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
     {
56 56
         $obj = clone $this;
57 57
         usort($obj->_elements,
58
-            function (Element $a, Element $b) {
58
+            function(Element $a, Element $b) {
59 59
                 $a_der = $a->toDER();
60 60
                 $b_der = $b->toDER();
61 61
                 return strcmp($a_der, $b_der);
Please login to merge, or discard this patch.
lib/ASN1/Element.php 3 patches
Switch Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -332,10 +332,10 @@  discard block
 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
     }
@@ -398,14 +398,14 @@  discard block
 block discarded – undo
398 398
     protected static function _determineImplClass(Identifier $identifier): string
399 399
     {
400 400
         switch ($identifier->typeClass()) {
401
-            case Identifier::CLASS_UNIVERSAL:
402
-                return self::_determineUniversalImplClass($identifier->intTag());
403
-            case Identifier::CLASS_CONTEXT_SPECIFIC:
404
-                return TaggedType::class;
405
-            case Identifier::CLASS_APPLICATION:
406
-                return ApplicationType::class;
407
-            case Identifier::CLASS_PRIVATE:
408
-                return PrivateType::class;
401
+        case Identifier::CLASS_UNIVERSAL:
402
+            return self::_determineUniversalImplClass($identifier->intTag());
403
+        case Identifier::CLASS_CONTEXT_SPECIFIC:
404
+            return TaggedType::class;
405
+        case Identifier::CLASS_APPLICATION:
406
+            return ApplicationType::class;
407
+        case Identifier::CLASS_PRIVATE:
408
+            return PrivateType::class;
409 409
         }
410 410
         throw new \UnexpectedValueException(
411 411
             sprintf("%s %d not implemented.",
Please login to merge, or discard this patch.
Indentation   +410 added lines, -410 removed lines patch added patch discarded remove patch
@@ -22,438 +22,438 @@
 block discarded – undo
22 22
  */
23 23
 abstract class Element implements ElementBase
24 24
 {
25
-    // Universal type tags
26
-    const TYPE_EOC = 0x00;
27
-    const TYPE_BOOLEAN = 0x01;
28
-    const TYPE_INTEGER = 0x02;
29
-    const TYPE_BIT_STRING = 0x03;
30
-    const TYPE_OCTET_STRING = 0x04;
31
-    const TYPE_NULL = 0x05;
32
-    const TYPE_OBJECT_IDENTIFIER = 0x06;
33
-    const TYPE_OBJECT_DESCRIPTOR = 0x07;
34
-    const TYPE_EXTERNAL = 0x08;
35
-    const TYPE_REAL = 0x09;
36
-    const TYPE_ENUMERATED = 0x0a;
37
-    const TYPE_EMBEDDED_PDV = 0x0b;
38
-    const TYPE_UTF8_STRING = 0x0c;
39
-    const TYPE_RELATIVE_OID = 0x0d;
40
-    const TYPE_SEQUENCE = 0x10;
41
-    const TYPE_SET = 0x11;
42
-    const TYPE_NUMERIC_STRING = 0x12;
43
-    const TYPE_PRINTABLE_STRING = 0x13;
44
-    const TYPE_T61_STRING = 0x14;
45
-    const TYPE_VIDEOTEX_STRING = 0x15;
46
-    const TYPE_IA5_STRING = 0x16;
47
-    const TYPE_UTC_TIME = 0x17;
48
-    const TYPE_GENERALIZED_TIME = 0x18;
49
-    const TYPE_GRAPHIC_STRING = 0x19;
50
-    const TYPE_VISIBLE_STRING = 0x1a;
51
-    const TYPE_GENERAL_STRING = 0x1b;
52
-    const TYPE_UNIVERSAL_STRING = 0x1c;
53
-    const TYPE_CHARACTER_STRING = 0x1d;
54
-    const TYPE_BMP_STRING = 0x1e;
25
+	// Universal type tags
26
+	const TYPE_EOC = 0x00;
27
+	const TYPE_BOOLEAN = 0x01;
28
+	const TYPE_INTEGER = 0x02;
29
+	const TYPE_BIT_STRING = 0x03;
30
+	const TYPE_OCTET_STRING = 0x04;
31
+	const TYPE_NULL = 0x05;
32
+	const TYPE_OBJECT_IDENTIFIER = 0x06;
33
+	const TYPE_OBJECT_DESCRIPTOR = 0x07;
34
+	const TYPE_EXTERNAL = 0x08;
35
+	const TYPE_REAL = 0x09;
36
+	const TYPE_ENUMERATED = 0x0a;
37
+	const TYPE_EMBEDDED_PDV = 0x0b;
38
+	const TYPE_UTF8_STRING = 0x0c;
39
+	const TYPE_RELATIVE_OID = 0x0d;
40
+	const TYPE_SEQUENCE = 0x10;
41
+	const TYPE_SET = 0x11;
42
+	const TYPE_NUMERIC_STRING = 0x12;
43
+	const TYPE_PRINTABLE_STRING = 0x13;
44
+	const TYPE_T61_STRING = 0x14;
45
+	const TYPE_VIDEOTEX_STRING = 0x15;
46
+	const TYPE_IA5_STRING = 0x16;
47
+	const TYPE_UTC_TIME = 0x17;
48
+	const TYPE_GENERALIZED_TIME = 0x18;
49
+	const TYPE_GRAPHIC_STRING = 0x19;
50
+	const TYPE_VISIBLE_STRING = 0x1a;
51
+	const TYPE_GENERAL_STRING = 0x1b;
52
+	const TYPE_UNIVERSAL_STRING = 0x1c;
53
+	const TYPE_CHARACTER_STRING = 0x1d;
54
+	const TYPE_BMP_STRING = 0x1e;
55 55
     
56
-    /**
57
-     * Mapping from universal type tag to implementation class name.
58
-     *
59
-     * @internal
60
-     *
61
-     * @var array
62
-     */
63
-    const MAP_TAG_TO_CLASS = [ /* @formatter:off */
64
-        self::TYPE_BOOLEAN => Primitive\Boolean::class,
65
-        self::TYPE_INTEGER => Primitive\Integer::class,
66
-        self::TYPE_BIT_STRING => Primitive\BitString::class,
67
-        self::TYPE_OCTET_STRING => Primitive\OctetString::class,
68
-        self::TYPE_NULL => Primitive\NullType::class,
69
-        self::TYPE_OBJECT_IDENTIFIER => Primitive\ObjectIdentifier::class,
70
-        self::TYPE_OBJECT_DESCRIPTOR => Primitive\ObjectDescriptor::class,
71
-        self::TYPE_REAL => Primitive\Real::class,
72
-        self::TYPE_ENUMERATED => Primitive\Enumerated::class,
73
-        self::TYPE_UTF8_STRING => Primitive\UTF8String::class,
74
-        self::TYPE_RELATIVE_OID => Primitive\RelativeOID::class,
75
-        self::TYPE_SEQUENCE => Constructed\Sequence::class,
76
-        self::TYPE_SET => Constructed\Set::class,
77
-        self::TYPE_NUMERIC_STRING => Primitive\NumericString::class,
78
-        self::TYPE_PRINTABLE_STRING => Primitive\PrintableString::class,
79
-        self::TYPE_T61_STRING => Primitive\T61String::class,
80
-        self::TYPE_VIDEOTEX_STRING => Primitive\VideotexString::class,
81
-        self::TYPE_IA5_STRING => Primitive\IA5String::class,
82
-        self::TYPE_UTC_TIME => Primitive\UTCTime::class,
83
-        self::TYPE_GENERALIZED_TIME => Primitive\GeneralizedTime::class,
84
-        self::TYPE_GRAPHIC_STRING => Primitive\GraphicString::class,
85
-        self::TYPE_VISIBLE_STRING => Primitive\VisibleString::class,
86
-        self::TYPE_GENERAL_STRING => Primitive\GeneralString::class,
87
-        self::TYPE_UNIVERSAL_STRING => Primitive\UniversalString::class,
88
-        self::TYPE_CHARACTER_STRING => Primitive\CharacterString::class,
89
-        self::TYPE_BMP_STRING => Primitive\BMPString::class
90
-        /* @formatter:on */
91
-    ];
56
+	/**
57
+	 * Mapping from universal type tag to implementation class name.
58
+	 *
59
+	 * @internal
60
+	 *
61
+	 * @var array
62
+	 */
63
+	const MAP_TAG_TO_CLASS = [ /* @formatter:off */
64
+		self::TYPE_BOOLEAN => Primitive\Boolean::class,
65
+		self::TYPE_INTEGER => Primitive\Integer::class,
66
+		self::TYPE_BIT_STRING => Primitive\BitString::class,
67
+		self::TYPE_OCTET_STRING => Primitive\OctetString::class,
68
+		self::TYPE_NULL => Primitive\NullType::class,
69
+		self::TYPE_OBJECT_IDENTIFIER => Primitive\ObjectIdentifier::class,
70
+		self::TYPE_OBJECT_DESCRIPTOR => Primitive\ObjectDescriptor::class,
71
+		self::TYPE_REAL => Primitive\Real::class,
72
+		self::TYPE_ENUMERATED => Primitive\Enumerated::class,
73
+		self::TYPE_UTF8_STRING => Primitive\UTF8String::class,
74
+		self::TYPE_RELATIVE_OID => Primitive\RelativeOID::class,
75
+		self::TYPE_SEQUENCE => Constructed\Sequence::class,
76
+		self::TYPE_SET => Constructed\Set::class,
77
+		self::TYPE_NUMERIC_STRING => Primitive\NumericString::class,
78
+		self::TYPE_PRINTABLE_STRING => Primitive\PrintableString::class,
79
+		self::TYPE_T61_STRING => Primitive\T61String::class,
80
+		self::TYPE_VIDEOTEX_STRING => Primitive\VideotexString::class,
81
+		self::TYPE_IA5_STRING => Primitive\IA5String::class,
82
+		self::TYPE_UTC_TIME => Primitive\UTCTime::class,
83
+		self::TYPE_GENERALIZED_TIME => Primitive\GeneralizedTime::class,
84
+		self::TYPE_GRAPHIC_STRING => Primitive\GraphicString::class,
85
+		self::TYPE_VISIBLE_STRING => Primitive\VisibleString::class,
86
+		self::TYPE_GENERAL_STRING => Primitive\GeneralString::class,
87
+		self::TYPE_UNIVERSAL_STRING => Primitive\UniversalString::class,
88
+		self::TYPE_CHARACTER_STRING => Primitive\CharacterString::class,
89
+		self::TYPE_BMP_STRING => Primitive\BMPString::class
90
+		/* @formatter:on */
91
+	];
92 92
     
93
-    /**
94
-     * Pseudotype for all string types.
95
-     *
96
-     * May be used as an expectation parameter.
97
-     *
98
-     * @var int
99
-     */
100
-    const TYPE_STRING = -1;
93
+	/**
94
+	 * Pseudotype for all string types.
95
+	 *
96
+	 * May be used as an expectation parameter.
97
+	 *
98
+	 * @var int
99
+	 */
100
+	const TYPE_STRING = -1;
101 101
     
102
-    /**
103
-     * Pseudotype for all time types.
104
-     *
105
-     * May be used as an expectation parameter.
106
-     *
107
-     * @var int
108
-     */
109
-    const TYPE_TIME = -2;
102
+	/**
103
+	 * Pseudotype for all time types.
104
+	 *
105
+	 * May be used as an expectation parameter.
106
+	 *
107
+	 * @var int
108
+	 */
109
+	const TYPE_TIME = -2;
110 110
     
111
-    /**
112
-     * Mapping from universal type tag to human readable name.
113
-     *
114
-     * @internal
115
-     *
116
-     * @var array
117
-     */
118
-    const MAP_TYPE_TO_NAME = [ /* @formatter:off */
119
-        self::TYPE_EOC => "EOC",
120
-        self::TYPE_BOOLEAN => "BOOLEAN",
121
-        self::TYPE_INTEGER => "INTEGER",
122
-        self::TYPE_BIT_STRING => "BIT STRING",
123
-        self::TYPE_OCTET_STRING => "OCTET STRING",
124
-        self::TYPE_NULL => "NULL",
125
-        self::TYPE_OBJECT_IDENTIFIER => "OBJECT IDENTIFIER",
126
-        self::TYPE_OBJECT_DESCRIPTOR => "ObjectDescriptor",
127
-        self::TYPE_EXTERNAL => "EXTERNAL",
128
-        self::TYPE_REAL => "REAL",
129
-        self::TYPE_ENUMERATED => "ENUMERATED",
130
-        self::TYPE_EMBEDDED_PDV => "EMBEDDED PDV",
131
-        self::TYPE_UTF8_STRING => "UTF8String",
132
-        self::TYPE_RELATIVE_OID => "RELATIVE-OID",
133
-        self::TYPE_SEQUENCE => "SEQUENCE",
134
-        self::TYPE_SET => "SET",
135
-        self::TYPE_NUMERIC_STRING => "NumericString",
136
-        self::TYPE_PRINTABLE_STRING => "PrintableString",
137
-        self::TYPE_T61_STRING => "T61String",
138
-        self::TYPE_VIDEOTEX_STRING => "VideotexString",
139
-        self::TYPE_IA5_STRING => "IA5String",
140
-        self::TYPE_UTC_TIME => "UTCTime",
141
-        self::TYPE_GENERALIZED_TIME => "GeneralizedTime",
142
-        self::TYPE_GRAPHIC_STRING => "GraphicString",
143
-        self::TYPE_VISIBLE_STRING => "VisibleString",
144
-        self::TYPE_GENERAL_STRING => "GeneralString",
145
-        self::TYPE_UNIVERSAL_STRING => "UniversalString",
146
-        self::TYPE_CHARACTER_STRING => "CHARACTER STRING",
147
-        self::TYPE_BMP_STRING => "BMPString",
148
-        self::TYPE_STRING => "Any String",
149
-        self::TYPE_TIME => "Any Time"
150
-        /* @formatter:on */
151
-    ];
111
+	/**
112
+	 * Mapping from universal type tag to human readable name.
113
+	 *
114
+	 * @internal
115
+	 *
116
+	 * @var array
117
+	 */
118
+	const MAP_TYPE_TO_NAME = [ /* @formatter:off */
119
+		self::TYPE_EOC => "EOC",
120
+		self::TYPE_BOOLEAN => "BOOLEAN",
121
+		self::TYPE_INTEGER => "INTEGER",
122
+		self::TYPE_BIT_STRING => "BIT STRING",
123
+		self::TYPE_OCTET_STRING => "OCTET STRING",
124
+		self::TYPE_NULL => "NULL",
125
+		self::TYPE_OBJECT_IDENTIFIER => "OBJECT IDENTIFIER",
126
+		self::TYPE_OBJECT_DESCRIPTOR => "ObjectDescriptor",
127
+		self::TYPE_EXTERNAL => "EXTERNAL",
128
+		self::TYPE_REAL => "REAL",
129
+		self::TYPE_ENUMERATED => "ENUMERATED",
130
+		self::TYPE_EMBEDDED_PDV => "EMBEDDED PDV",
131
+		self::TYPE_UTF8_STRING => "UTF8String",
132
+		self::TYPE_RELATIVE_OID => "RELATIVE-OID",
133
+		self::TYPE_SEQUENCE => "SEQUENCE",
134
+		self::TYPE_SET => "SET",
135
+		self::TYPE_NUMERIC_STRING => "NumericString",
136
+		self::TYPE_PRINTABLE_STRING => "PrintableString",
137
+		self::TYPE_T61_STRING => "T61String",
138
+		self::TYPE_VIDEOTEX_STRING => "VideotexString",
139
+		self::TYPE_IA5_STRING => "IA5String",
140
+		self::TYPE_UTC_TIME => "UTCTime",
141
+		self::TYPE_GENERALIZED_TIME => "GeneralizedTime",
142
+		self::TYPE_GRAPHIC_STRING => "GraphicString",
143
+		self::TYPE_VISIBLE_STRING => "VisibleString",
144
+		self::TYPE_GENERAL_STRING => "GeneralString",
145
+		self::TYPE_UNIVERSAL_STRING => "UniversalString",
146
+		self::TYPE_CHARACTER_STRING => "CHARACTER STRING",
147
+		self::TYPE_BMP_STRING => "BMPString",
148
+		self::TYPE_STRING => "Any String",
149
+		self::TYPE_TIME => "Any Time"
150
+		/* @formatter:on */
151
+	];
152 152
     
153
-    /**
154
-     * Element's type tag.
155
-     *
156
-     * @var int
157
-     */
158
-    protected $_typeTag;
153
+	/**
154
+	 * Element's type tag.
155
+	 *
156
+	 * @var int
157
+	 */
158
+	protected $_typeTag;
159 159
     
160
-    /**
161
-     *
162
-     * @see \ASN1\Feature\ElementBase::typeClass()
163
-     * @return int
164
-     */
165
-    abstract public function typeClass(): int;
160
+	/**
161
+	 *
162
+	 * @see \ASN1\Feature\ElementBase::typeClass()
163
+	 * @return int
164
+	 */
165
+	abstract public function typeClass(): int;
166 166
     
167
-    /**
168
-     *
169
-     * @see \ASN1\Feature\ElementBase::isConstructed()
170
-     * @return bool
171
-     */
172
-    abstract public function isConstructed(): bool;
167
+	/**
168
+	 *
169
+	 * @see \ASN1\Feature\ElementBase::isConstructed()
170
+	 * @return bool
171
+	 */
172
+	abstract public function isConstructed(): bool;
173 173
     
174
-    /**
175
-     * Get the content encoded in DER.
176
-     *
177
-     * Returns the DER encoded content without identifier and length header
178
-     * octets.
179
-     *
180
-     * @return string
181
-     */
182
-    abstract protected function _encodedContentDER(): string;
174
+	/**
175
+	 * Get the content encoded in DER.
176
+	 *
177
+	 * Returns the DER encoded content without identifier and length header
178
+	 * octets.
179
+	 *
180
+	 * @return string
181
+	 */
182
+	abstract protected function _encodedContentDER(): string;
183 183
     
184
-    /**
185
-     * Decode type-specific element from DER.
186
-     *
187
-     * @param Identifier $identifier Pre-parsed identifier
188
-     * @param string $data DER data
189
-     * @param int $offset Offset in data to the next byte after identifier
190
-     * @throws DecodeException If decoding fails
191
-     * @return ElementBase
192
-     */
193
-    protected static function _decodeFromDER(Identifier $identifier, string $data,
194
-        int &$offset): ElementBase
195
-    {
196
-        throw new \BadMethodCallException(
197
-            __METHOD__ . " must be implemented in derived class.");
198
-    }
184
+	/**
185
+	 * Decode type-specific element from DER.
186
+	 *
187
+	 * @param Identifier $identifier Pre-parsed identifier
188
+	 * @param string $data DER data
189
+	 * @param int $offset Offset in data to the next byte after identifier
190
+	 * @throws DecodeException If decoding fails
191
+	 * @return ElementBase
192
+	 */
193
+	protected static function _decodeFromDER(Identifier $identifier, string $data,
194
+		int &$offset): ElementBase
195
+	{
196
+		throw new \BadMethodCallException(
197
+			__METHOD__ . " must be implemented in derived class.");
198
+	}
199 199
     
200
-    /**
201
-     * Decode element from DER data.
202
-     *
203
-     * @param string $data DER encoded data
204
-     * @param int|null $offset Reference to the variable that contains offset
205
-     *        into the data where to start parsing. Variable is updated to
206
-     *        the offset next to the parsed element. If null, start from offset
207
-     *        0.
208
-     * @throws DecodeException If decoding fails
209
-     * @throws \UnexpectedValueException If called in the context of an expected
210
-     *         type, but decoding yields another type
211
-     * @return ElementBase
212
-     */
213
-    public static function fromDER(string $data, int &$offset = null): ElementBase
214
-    {
215
-        // decode identifier
216
-        $idx = $offset ?? 0;
217
-        $identifier = Identifier::fromDER($data, $idx);
218
-        // determine class that implements type specific decoding
219
-        $cls = self::_determineImplClass($identifier);
220
-        try {
221
-            // decode remaining element
222
-            $element = $cls::_decodeFromDER($identifier, $data, $idx);
223
-        } catch (\LogicException $e) {
224
-            // rethrow as a RuntimeException for unified exception handling
225
-            throw new DecodeException(
226
-                sprintf("Error while decoding %s.",
227
-                    self::tagToName($identifier->intTag())), 0, $e);
228
-        }
229
-        // if called in the context of a concrete class, check
230
-        // that decoded type matches the type of a calling class
231
-        $called_class = get_called_class();
232
-        if (self::class != $called_class) {
233
-            if (!$element instanceof $called_class) {
234
-                throw new \UnexpectedValueException(
235
-                    sprintf("%s expected, got %s.", $called_class,
236
-                        get_class($element)));
237
-            }
238
-        }
239
-        // update offset for the caller
240
-        if (isset($offset)) {
241
-            $offset = $idx;
242
-        }
243
-        return $element;
244
-    }
200
+	/**
201
+	 * Decode element from DER data.
202
+	 *
203
+	 * @param string $data DER encoded data
204
+	 * @param int|null $offset Reference to the variable that contains offset
205
+	 *        into the data where to start parsing. Variable is updated to
206
+	 *        the offset next to the parsed element. If null, start from offset
207
+	 *        0.
208
+	 * @throws DecodeException If decoding fails
209
+	 * @throws \UnexpectedValueException If called in the context of an expected
210
+	 *         type, but decoding yields another type
211
+	 * @return ElementBase
212
+	 */
213
+	public static function fromDER(string $data, int &$offset = null): ElementBase
214
+	{
215
+		// decode identifier
216
+		$idx = $offset ?? 0;
217
+		$identifier = Identifier::fromDER($data, $idx);
218
+		// determine class that implements type specific decoding
219
+		$cls = self::_determineImplClass($identifier);
220
+		try {
221
+			// decode remaining element
222
+			$element = $cls::_decodeFromDER($identifier, $data, $idx);
223
+		} catch (\LogicException $e) {
224
+			// rethrow as a RuntimeException for unified exception handling
225
+			throw new DecodeException(
226
+				sprintf("Error while decoding %s.",
227
+					self::tagToName($identifier->intTag())), 0, $e);
228
+		}
229
+		// if called in the context of a concrete class, check
230
+		// that decoded type matches the type of a calling class
231
+		$called_class = get_called_class();
232
+		if (self::class != $called_class) {
233
+			if (!$element instanceof $called_class) {
234
+				throw new \UnexpectedValueException(
235
+					sprintf("%s expected, got %s.", $called_class,
236
+						get_class($element)));
237
+			}
238
+		}
239
+		// update offset for the caller
240
+		if (isset($offset)) {
241
+			$offset = $idx;
242
+		}
243
+		return $element;
244
+	}
245 245
     
246
-    /**
247
-     *
248
-     * @see \ASN1\Feature\Encodable::toDER()
249
-     * @return string
250
-     */
251
-    public function toDER(): string
252
-    {
253
-        $identifier = new Identifier($this->typeClass(),
254
-            $this->isConstructed() ? Identifier::CONSTRUCTED : Identifier::PRIMITIVE,
255
-            $this->_typeTag);
256
-        $content = $this->_encodedContentDER();
257
-        $length = new Length(strlen($content));
258
-        return $identifier->toDER() . $length->toDER() . $content;
259
-    }
246
+	/**
247
+	 *
248
+	 * @see \ASN1\Feature\Encodable::toDER()
249
+	 * @return string
250
+	 */
251
+	public function toDER(): string
252
+	{
253
+		$identifier = new Identifier($this->typeClass(),
254
+			$this->isConstructed() ? Identifier::CONSTRUCTED : Identifier::PRIMITIVE,
255
+			$this->_typeTag);
256
+		$content = $this->_encodedContentDER();
257
+		$length = new Length(strlen($content));
258
+		return $identifier->toDER() . $length->toDER() . $content;
259
+	}
260 260
     
261
-    /**
262
-     *
263
-     * @see \ASN1\Feature\ElementBase::tag()
264
-     * @return int
265
-     */
266
-    public function tag(): int
267
-    {
268
-        return $this->_typeTag;
269
-    }
261
+	/**
262
+	 *
263
+	 * @see \ASN1\Feature\ElementBase::tag()
264
+	 * @return int
265
+	 */
266
+	public function tag(): int
267
+	{
268
+		return $this->_typeTag;
269
+	}
270 270
     
271
-    /**
272
-     *
273
-     * @see \ASN1\Feature\ElementBase::isType()
274
-     * @return bool
275
-     */
276
-    public function isType(int $tag): bool
277
-    {
278
-        // if element is context specific
279
-        if ($this->typeClass() == Identifier::CLASS_CONTEXT_SPECIFIC) {
280
-            return false;
281
-        }
282
-        // negative tags identify an abstract pseudotype
283
-        if ($tag < 0) {
284
-            return $this->_isPseudoType($tag);
285
-        }
286
-        return $this->_isConcreteType($tag);
287
-    }
271
+	/**
272
+	 *
273
+	 * @see \ASN1\Feature\ElementBase::isType()
274
+	 * @return bool
275
+	 */
276
+	public function isType(int $tag): bool
277
+	{
278
+		// if element is context specific
279
+		if ($this->typeClass() == Identifier::CLASS_CONTEXT_SPECIFIC) {
280
+			return false;
281
+		}
282
+		// negative tags identify an abstract pseudotype
283
+		if ($tag < 0) {
284
+			return $this->_isPseudoType($tag);
285
+		}
286
+		return $this->_isConcreteType($tag);
287
+	}
288 288
     
289
-    /**
290
-     *
291
-     * @see \ASN1\Feature\ElementBase::expectType()
292
-     * @return ElementBase
293
-     */
294
-    public function expectType(int $tag): ElementBase
295
-    {
296
-        if (!$this->isType($tag)) {
297
-            throw new \UnexpectedValueException(
298
-                sprintf("%s expected, got %s.", self::tagToName($tag),
299
-                    $this->_typeDescriptorString()));
300
-        }
301
-        return $this;
302
-    }
289
+	/**
290
+	 *
291
+	 * @see \ASN1\Feature\ElementBase::expectType()
292
+	 * @return ElementBase
293
+	 */
294
+	public function expectType(int $tag): ElementBase
295
+	{
296
+		if (!$this->isType($tag)) {
297
+			throw new \UnexpectedValueException(
298
+				sprintf("%s expected, got %s.", self::tagToName($tag),
299
+					$this->_typeDescriptorString()));
300
+		}
301
+		return $this;
302
+	}
303 303
     
304
-    /**
305
-     * Check whether the element is a concrete type of a given tag.
306
-     *
307
-     * @param int $tag
308
-     * @return bool
309
-     */
310
-    private function _isConcreteType(int $tag): bool
311
-    {
312
-        // if tag doesn't match
313
-        if ($this->tag() != $tag) {
314
-            return false;
315
-        }
316
-        // if type is universal check that instance is of a correct class
317
-        if ($this->typeClass() == Identifier::CLASS_UNIVERSAL) {
318
-            $cls = self::_determineUniversalImplClass($tag);
319
-            if (!$this instanceof $cls) {
320
-                return false;
321
-            }
322
-        }
323
-        return true;
324
-    }
304
+	/**
305
+	 * Check whether the element is a concrete type of a given tag.
306
+	 *
307
+	 * @param int $tag
308
+	 * @return bool
309
+	 */
310
+	private function _isConcreteType(int $tag): bool
311
+	{
312
+		// if tag doesn't match
313
+		if ($this->tag() != $tag) {
314
+			return false;
315
+		}
316
+		// if type is universal check that instance is of a correct class
317
+		if ($this->typeClass() == Identifier::CLASS_UNIVERSAL) {
318
+			$cls = self::_determineUniversalImplClass($tag);
319
+			if (!$this instanceof $cls) {
320
+				return false;
321
+			}
322
+		}
323
+		return true;
324
+	}
325 325
     
326
-    /**
327
-     * Check whether the element is a pseudotype.
328
-     *
329
-     * @param int $tag
330
-     * @return bool
331
-     */
332
-    private function _isPseudoType(int $tag): bool
333
-    {
334
-        switch ($tag) {
335
-            case self::TYPE_STRING:
336
-                return $this instanceof StringType;
337
-            case self::TYPE_TIME:
338
-                return $this instanceof TimeType;
339
-        }
340
-        return false;
341
-    }
326
+	/**
327
+	 * Check whether the element is a pseudotype.
328
+	 *
329
+	 * @param int $tag
330
+	 * @return bool
331
+	 */
332
+	private function _isPseudoType(int $tag): bool
333
+	{
334
+		switch ($tag) {
335
+			case self::TYPE_STRING:
336
+				return $this instanceof StringType;
337
+			case self::TYPE_TIME:
338
+				return $this instanceof TimeType;
339
+		}
340
+		return false;
341
+	}
342 342
     
343
-    /**
344
-     *
345
-     * @see \ASN1\Feature\ElementBase::isTagged()
346
-     * @return bool
347
-     */
348
-    public function isTagged(): bool
349
-    {
350
-        return $this instanceof TaggedType;
351
-    }
343
+	/**
344
+	 *
345
+	 * @see \ASN1\Feature\ElementBase::isTagged()
346
+	 * @return bool
347
+	 */
348
+	public function isTagged(): bool
349
+	{
350
+		return $this instanceof TaggedType;
351
+	}
352 352
     
353
-    /**
354
-     *
355
-     * @see \ASN1\Feature\ElementBase::expectTagged()
356
-     * @return TaggedType
357
-     */
358
-    public function expectTagged($tag = null): TaggedType
359
-    {
360
-        if (!$this->isTagged()) {
361
-            throw new \UnexpectedValueException(
362
-                sprintf("Context specific element expected, got %s.",
363
-                    Identifier::classToName($this->typeClass())));
364
-        }
365
-        if (isset($tag) && $this->tag() != $tag) {
366
-            throw new \UnexpectedValueException(
367
-                sprintf("Tag %d expected, got %d.", $tag, $this->tag()));
368
-        }
369
-        return $this;
370
-    }
353
+	/**
354
+	 *
355
+	 * @see \ASN1\Feature\ElementBase::expectTagged()
356
+	 * @return TaggedType
357
+	 */
358
+	public function expectTagged($tag = null): TaggedType
359
+	{
360
+		if (!$this->isTagged()) {
361
+			throw new \UnexpectedValueException(
362
+				sprintf("Context specific element expected, got %s.",
363
+					Identifier::classToName($this->typeClass())));
364
+		}
365
+		if (isset($tag) && $this->tag() != $tag) {
366
+			throw new \UnexpectedValueException(
367
+				sprintf("Tag %d expected, got %d.", $tag, $this->tag()));
368
+		}
369
+		return $this;
370
+	}
371 371
     
372
-    /**
373
-     *
374
-     * @see \ASN1\Feature\ElementBase::asElement()
375
-     * @return Element
376
-     */
377
-    final public function asElement(): Element
378
-    {
379
-        return $this;
380
-    }
372
+	/**
373
+	 *
374
+	 * @see \ASN1\Feature\ElementBase::asElement()
375
+	 * @return Element
376
+	 */
377
+	final public function asElement(): Element
378
+	{
379
+		return $this;
380
+	}
381 381
     
382
-    /**
383
-     * Get element decorated with UnspecifiedType object.
384
-     *
385
-     * @return UnspecifiedType
386
-     */
387
-    public function asUnspecified(): UnspecifiedType
388
-    {
389
-        return new UnspecifiedType($this);
390
-    }
382
+	/**
383
+	 * Get element decorated with UnspecifiedType object.
384
+	 *
385
+	 * @return UnspecifiedType
386
+	 */
387
+	public function asUnspecified(): UnspecifiedType
388
+	{
389
+		return new UnspecifiedType($this);
390
+	}
391 391
     
392
-    /**
393
-     * Determine the class that implements the type.
394
-     *
395
-     * @param Identifier $identifier
396
-     * @return string Class name
397
-     */
398
-    protected static function _determineImplClass(Identifier $identifier): string
399
-    {
400
-        switch ($identifier->typeClass()) {
401
-            case Identifier::CLASS_UNIVERSAL:
402
-                return self::_determineUniversalImplClass($identifier->intTag());
403
-            case Identifier::CLASS_CONTEXT_SPECIFIC:
404
-                return TaggedType::class;
405
-            case Identifier::CLASS_APPLICATION:
406
-                return ApplicationType::class;
407
-            case Identifier::CLASS_PRIVATE:
408
-                return PrivateType::class;
409
-        }
410
-        throw new \UnexpectedValueException(
411
-            sprintf("%s %d not implemented.",
412
-                Identifier::classToName($identifier->typeClass()),
413
-                $identifier->tag()));
414
-    }
392
+	/**
393
+	 * Determine the class that implements the type.
394
+	 *
395
+	 * @param Identifier $identifier
396
+	 * @return string Class name
397
+	 */
398
+	protected static function _determineImplClass(Identifier $identifier): string
399
+	{
400
+		switch ($identifier->typeClass()) {
401
+			case Identifier::CLASS_UNIVERSAL:
402
+				return self::_determineUniversalImplClass($identifier->intTag());
403
+			case Identifier::CLASS_CONTEXT_SPECIFIC:
404
+				return TaggedType::class;
405
+			case Identifier::CLASS_APPLICATION:
406
+				return ApplicationType::class;
407
+			case Identifier::CLASS_PRIVATE:
408
+				return PrivateType::class;
409
+		}
410
+		throw new \UnexpectedValueException(
411
+			sprintf("%s %d not implemented.",
412
+				Identifier::classToName($identifier->typeClass()),
413
+				$identifier->tag()));
414
+	}
415 415
     
416
-    /**
417
-     * Determine the class that implements an universal type of the given tag.
418
-     *
419
-     * @param int $tag
420
-     * @throws \UnexpectedValueException
421
-     * @return string Class name
422
-     */
423
-    protected static function _determineUniversalImplClass(int $tag): string
424
-    {
425
-        if (!array_key_exists($tag, self::MAP_TAG_TO_CLASS)) {
426
-            throw new \UnexpectedValueException(
427
-                "Universal tag $tag not implemented.");
428
-        }
429
-        return self::MAP_TAG_TO_CLASS[$tag];
430
-    }
416
+	/**
417
+	 * Determine the class that implements an universal type of the given tag.
418
+	 *
419
+	 * @param int $tag
420
+	 * @throws \UnexpectedValueException
421
+	 * @return string Class name
422
+	 */
423
+	protected static function _determineUniversalImplClass(int $tag): string
424
+	{
425
+		if (!array_key_exists($tag, self::MAP_TAG_TO_CLASS)) {
426
+			throw new \UnexpectedValueException(
427
+				"Universal tag $tag not implemented.");
428
+		}
429
+		return self::MAP_TAG_TO_CLASS[$tag];
430
+	}
431 431
     
432
-    /**
433
-     * Get textual description of the type for debugging purposes.
434
-     *
435
-     * @return string
436
-     */
437
-    protected function _typeDescriptorString(): string
438
-    {
439
-        if ($this->typeClass() == Identifier::CLASS_UNIVERSAL) {
440
-            return self::tagToName($this->_typeTag);
441
-        }
442
-        return sprintf("%s TAG %d", Identifier::classToName($this->typeClass()),
443
-            $this->_typeTag);
444
-    }
432
+	/**
433
+	 * Get textual description of the type for debugging purposes.
434
+	 *
435
+	 * @return string
436
+	 */
437
+	protected function _typeDescriptorString(): string
438
+	{
439
+		if ($this->typeClass() == Identifier::CLASS_UNIVERSAL) {
440
+			return self::tagToName($this->_typeTag);
441
+		}
442
+		return sprintf("%s TAG %d", Identifier::classToName($this->typeClass()),
443
+			$this->_typeTag);
444
+	}
445 445
     
446
-    /**
447
-     * Get human readable name for an universal tag.
448
-     *
449
-     * @param int $tag
450
-     * @return string
451
-     */
452
-    public static function tagToName(int $tag): string
453
-    {
454
-        if (!array_key_exists($tag, self::MAP_TYPE_TO_NAME)) {
455
-            return "TAG $tag";
456
-        }
457
-        return self::MAP_TYPE_TO_NAME[$tag];
458
-    }
446
+	/**
447
+	 * Get human readable name for an universal tag.
448
+	 *
449
+	 * @param int $tag
450
+	 * @return string
451
+	 */
452
+	public static function tagToName(int $tag): string
453
+	{
454
+		if (!array_key_exists($tag, self::MAP_TYPE_TO_NAME)) {
455
+			return "TAG $tag";
456
+		}
457
+		return self::MAP_TYPE_TO_NAME[$tag];
458
+	}
459 459
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace ASN1;
6 6
 
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
      *
61 61
      * @var array
62 62
      */
63
-    const MAP_TAG_TO_CLASS = [ /* @formatter:off */
63
+    const MAP_TAG_TO_CLASS = [/* @formatter:off */
64 64
         self::TYPE_BOOLEAN => Primitive\Boolean::class,
65 65
         self::TYPE_INTEGER => Primitive\Integer::class,
66 66
         self::TYPE_BIT_STRING => Primitive\BitString::class,
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
      *
116 116
      * @var array
117 117
      */
118
-    const MAP_TYPE_TO_NAME = [ /* @formatter:off */
118
+    const MAP_TYPE_TO_NAME = [/* @formatter:off */
119 119
         self::TYPE_EOC => "EOC",
120 120
         self::TYPE_BOOLEAN => "BOOLEAN",
121 121
         self::TYPE_INTEGER => "INTEGER",
Please login to merge, or discard this patch.
lib/ASN1/Component/Length.php 2 patches
Indentation   +193 added lines, -193 removed lines patch added patch discarded remove patch
@@ -13,206 +13,206 @@
 block discarded – undo
13 13
  */
14 14
 class Length implements Encodable
15 15
 {
16
-    /**
17
-     * Length.
18
-     *
19
-     * @var BigInt
20
-     */
21
-    private $_length;
16
+	/**
17
+	 * Length.
18
+	 *
19
+	 * @var BigInt
20
+	 */
21
+	private $_length;
22 22
     
23
-    /**
24
-     * Whether length is indefinite.
25
-     *
26
-     * @var bool
27
-     */
28
-    private $_indefinite;
23
+	/**
24
+	 * Whether length is indefinite.
25
+	 *
26
+	 * @var bool
27
+	 */
28
+	private $_indefinite;
29 29
     
30
-    /**
31
-     * Constructor.
32
-     *
33
-     * @param int|string $length Length
34
-     * @param bool $indefinite Whether length is indefinite
35
-     */
36
-    public function __construct($length, bool $indefinite = false)
37
-    {
38
-        $this->_length = new BigInt($length);
39
-        $this->_indefinite = $indefinite;
40
-    }
30
+	/**
31
+	 * Constructor.
32
+	 *
33
+	 * @param int|string $length Length
34
+	 * @param bool $indefinite Whether length is indefinite
35
+	 */
36
+	public function __construct($length, bool $indefinite = false)
37
+	{
38
+		$this->_length = new BigInt($length);
39
+		$this->_indefinite = $indefinite;
40
+	}
41 41
     
42
-    /**
43
-     * Decode length component from DER data.
44
-     *
45
-     * @param string $data DER encoded data
46
-     * @param int|null $offset Reference to the variable that contains offset
47
-     *        into the data where to start parsing. Variable is updated to
48
-     *        the offset next to the parsed length component. If null, start
49
-     *        from offset 0.
50
-     * @throws DecodeException If decoding fails
51
-     * @return self
52
-     */
53
-    public static function fromDER(string $data, int &$offset = null): self
54
-    {
55
-        $idx = $offset ?? 0;
56
-        $datalen = strlen($data);
57
-        if ($idx >= $datalen) {
58
-            throw new DecodeException("Invalid offset.");
59
-        }
60
-        $indefinite = false;
61
-        $byte = ord($data[$idx++]);
62
-        // bits 7 to 1
63
-        $length = (0x7f & $byte);
64
-        // long form
65
-        if (0x80 & $byte) {
66
-            if (!$length) {
67
-                $indefinite = true;
68
-            } else {
69
-                if ($idx + $length > $datalen) {
70
-                    throw new DecodeException("Too many length octets.");
71
-                }
72
-                $length = self::_decodeLongFormLength($length, $data, $idx);
73
-            }
74
-        }
75
-        if (isset($offset)) {
76
-            $offset = $idx;
77
-        }
78
-        return new self($length, $indefinite);
79
-    }
42
+	/**
43
+	 * Decode length component from DER data.
44
+	 *
45
+	 * @param string $data DER encoded data
46
+	 * @param int|null $offset Reference to the variable that contains offset
47
+	 *        into the data where to start parsing. Variable is updated to
48
+	 *        the offset next to the parsed length component. If null, start
49
+	 *        from offset 0.
50
+	 * @throws DecodeException If decoding fails
51
+	 * @return self
52
+	 */
53
+	public static function fromDER(string $data, int &$offset = null): self
54
+	{
55
+		$idx = $offset ?? 0;
56
+		$datalen = strlen($data);
57
+		if ($idx >= $datalen) {
58
+			throw new DecodeException("Invalid offset.");
59
+		}
60
+		$indefinite = false;
61
+		$byte = ord($data[$idx++]);
62
+		// bits 7 to 1
63
+		$length = (0x7f & $byte);
64
+		// long form
65
+		if (0x80 & $byte) {
66
+			if (!$length) {
67
+				$indefinite = true;
68
+			} else {
69
+				if ($idx + $length > $datalen) {
70
+					throw new DecodeException("Too many length octets.");
71
+				}
72
+				$length = self::_decodeLongFormLength($length, $data, $idx);
73
+			}
74
+		}
75
+		if (isset($offset)) {
76
+			$offset = $idx;
77
+		}
78
+		return new self($length, $indefinite);
79
+	}
80 80
     
81
-    /**
82
-     * Decode long form length.
83
-     *
84
-     * @param int $length Number of octets
85
-     * @param string $data Data
86
-     * @param int $offset Reference to the variable containing offset to the
87
-     *        data.
88
-     * @throws DecodeException If decoding fails
89
-     * @return string Integer as a string
90
-     */
91
-    private static function _decodeLongFormLength(int $length, string $data,
92
-        int &$offset): string
93
-    {
94
-        // first octet must not be 0xff (spec 8.1.3.5c)
95
-        if ($length == 127) {
96
-            throw new DecodeException("Invalid number of length octets.");
97
-        }
98
-        $num = gmp_init(0, 10);
99
-        while (--$length >= 0) {
100
-            $byte = ord($data[$offset++]);
101
-            $num <<= 8;
102
-            $num |= $byte;
103
-        }
104
-        return gmp_strval($num);
105
-    }
81
+	/**
82
+	 * Decode long form length.
83
+	 *
84
+	 * @param int $length Number of octets
85
+	 * @param string $data Data
86
+	 * @param int $offset Reference to the variable containing offset to the
87
+	 *        data.
88
+	 * @throws DecodeException If decoding fails
89
+	 * @return string Integer as a string
90
+	 */
91
+	private static function _decodeLongFormLength(int $length, string $data,
92
+		int &$offset): string
93
+	{
94
+		// first octet must not be 0xff (spec 8.1.3.5c)
95
+		if ($length == 127) {
96
+			throw new DecodeException("Invalid number of length octets.");
97
+		}
98
+		$num = gmp_init(0, 10);
99
+		while (--$length >= 0) {
100
+			$byte = ord($data[$offset++]);
101
+			$num <<= 8;
102
+			$num |= $byte;
103
+		}
104
+		return gmp_strval($num);
105
+	}
106 106
     
107
-    /**
108
-     * Decode length from DER.
109
-     *
110
-     * Throws an exception if length doesn't match with expected or if data
111
-     * doesn't contain enough bytes.
112
-     *
113
-     * @see self::fromDER
114
-     * @param string $data DER data
115
-     * @param int $offset Reference to the offset variable
116
-     * @param int|null $expected Expected length, null to bypass checking
117
-     * @throws DecodeException If decoding or expectation fails
118
-     * @return self
119
-     */
120
-    public static function expectFromDER(string $data, int &$offset,
121
-        int $expected = null): self
122
-    {
123
-        $idx = $offset;
124
-        $length = self::fromDER($data, $idx);
125
-        // DER encoding must have definite length (spec 10.1)
126
-        if ($length->isIndefinite()) {
127
-            throw new DecodeException("DER encoding must have definite length.");
128
-        }
129
-        // if certain length was expected
130
-        if (isset($expected) && $expected != $length->intLength()) {
131
-            throw new DecodeException(
132
-                sprintf("Expected length %d, got %d.", $expected,
133
-                    $length->intLength()));
134
-        }
135
-        // check that enough data is available
136
-        if (strlen($data) < $idx + $length->intLength()) {
137
-            throw new DecodeException(
138
-                sprintf("Length %d overflows data, %d bytes left.",
139
-                    $length->intLength(), strlen($data) - $idx));
140
-        }
141
-        $offset = $idx;
142
-        return $length;
143
-    }
107
+	/**
108
+	 * Decode length from DER.
109
+	 *
110
+	 * Throws an exception if length doesn't match with expected or if data
111
+	 * doesn't contain enough bytes.
112
+	 *
113
+	 * @see self::fromDER
114
+	 * @param string $data DER data
115
+	 * @param int $offset Reference to the offset variable
116
+	 * @param int|null $expected Expected length, null to bypass checking
117
+	 * @throws DecodeException If decoding or expectation fails
118
+	 * @return self
119
+	 */
120
+	public static function expectFromDER(string $data, int &$offset,
121
+		int $expected = null): self
122
+	{
123
+		$idx = $offset;
124
+		$length = self::fromDER($data, $idx);
125
+		// DER encoding must have definite length (spec 10.1)
126
+		if ($length->isIndefinite()) {
127
+			throw new DecodeException("DER encoding must have definite length.");
128
+		}
129
+		// if certain length was expected
130
+		if (isset($expected) && $expected != $length->intLength()) {
131
+			throw new DecodeException(
132
+				sprintf("Expected length %d, got %d.", $expected,
133
+					$length->intLength()));
134
+		}
135
+		// check that enough data is available
136
+		if (strlen($data) < $idx + $length->intLength()) {
137
+			throw new DecodeException(
138
+				sprintf("Length %d overflows data, %d bytes left.",
139
+					$length->intLength(), strlen($data) - $idx));
140
+		}
141
+		$offset = $idx;
142
+		return $length;
143
+	}
144 144
     
145
-    /**
146
-     *
147
-     * @see Encodable::toDER()
148
-     * @throws \DomainException If length is too large to encode
149
-     * @return string
150
-     */
151
-    public function toDER(): string
152
-    {
153
-        $bytes = [];
154
-        if ($this->_indefinite) {
155
-            $bytes[] = 0x80;
156
-        } else {
157
-            $num = $this->_length->gmpObj();
158
-            // long form
159
-            if ($num > 127) {
160
-                $octets = [];
161
-                for (; $num > 0; $num >>= 8) {
162
-                    $octets[] = gmp_intval(0xff & $num);
163
-                }
164
-                $count = count($octets);
165
-                // first octet must not be 0xff
166
-                if ($count >= 127) {
167
-                    throw new \DomainException("Too many length octets.");
168
-                }
169
-                $bytes[] = 0x80 | $count;
170
-                foreach (array_reverse($octets) as $octet) {
171
-                    $bytes[] = $octet;
172
-                }
173
-            } else { // short form
174
-                $bytes[] = gmp_intval($num);
175
-            }
176
-        }
177
-        return pack("C*", ...$bytes);
178
-    }
145
+	/**
146
+	 *
147
+	 * @see Encodable::toDER()
148
+	 * @throws \DomainException If length is too large to encode
149
+	 * @return string
150
+	 */
151
+	public function toDER(): string
152
+	{
153
+		$bytes = [];
154
+		if ($this->_indefinite) {
155
+			$bytes[] = 0x80;
156
+		} else {
157
+			$num = $this->_length->gmpObj();
158
+			// long form
159
+			if ($num > 127) {
160
+				$octets = [];
161
+				for (; $num > 0; $num >>= 8) {
162
+					$octets[] = gmp_intval(0xff & $num);
163
+				}
164
+				$count = count($octets);
165
+				// first octet must not be 0xff
166
+				if ($count >= 127) {
167
+					throw new \DomainException("Too many length octets.");
168
+				}
169
+				$bytes[] = 0x80 | $count;
170
+				foreach (array_reverse($octets) as $octet) {
171
+					$bytes[] = $octet;
172
+				}
173
+			} else { // short form
174
+				$bytes[] = gmp_intval($num);
175
+			}
176
+		}
177
+		return pack("C*", ...$bytes);
178
+	}
179 179
     
180
-    /**
181
-     * Get the length.
182
-     *
183
-     * @throws \LogicException If length is indefinite
184
-     * @return string Length as an integer string
185
-     */
186
-    public function length(): string
187
-    {
188
-        if ($this->_indefinite) {
189
-            throw new \LogicException("Length is indefinite.");
190
-        }
191
-        return $this->_length->base10();
192
-    }
180
+	/**
181
+	 * Get the length.
182
+	 *
183
+	 * @throws \LogicException If length is indefinite
184
+	 * @return string Length as an integer string
185
+	 */
186
+	public function length(): string
187
+	{
188
+		if ($this->_indefinite) {
189
+			throw new \LogicException("Length is indefinite.");
190
+		}
191
+		return $this->_length->base10();
192
+	}
193 193
     
194
-    /**
195
-     * Get the length as an integer.
196
-     *
197
-     * @throws \LogicException If length is indefinite
198
-     * @throws \RuntimeException If length overflows integer size
199
-     * @return int
200
-     */
201
-    public function intLength(): int
202
-    {
203
-        if ($this->_indefinite) {
204
-            throw new \LogicException("Length is indefinite.");
205
-        }
206
-        return $this->_length->intVal();
207
-    }
194
+	/**
195
+	 * Get the length as an integer.
196
+	 *
197
+	 * @throws \LogicException If length is indefinite
198
+	 * @throws \RuntimeException If length overflows integer size
199
+	 * @return int
200
+	 */
201
+	public function intLength(): int
202
+	{
203
+		if ($this->_indefinite) {
204
+			throw new \LogicException("Length is indefinite.");
205
+		}
206
+		return $this->_length->intVal();
207
+	}
208 208
     
209
-    /**
210
-     * Whether length is indefinite.
211
-     *
212
-     * @return bool
213
-     */
214
-    public function isIndefinite(): bool
215
-    {
216
-        return $this->_indefinite;
217
-    }
209
+	/**
210
+	 * Whether length is indefinite.
211
+	 *
212
+	 * @return bool
213
+	 */
214
+	public function isIndefinite(): bool
215
+	{
216
+		return $this->_indefinite;
217
+	}
218 218
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace ASN1\Component;
6 6
 
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 ?? 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 ?? 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 bool
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 bool
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 bool
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 bool
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 bool
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 bool
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 bool
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 bool
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 bool
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 bool
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 bool
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 bool
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 = 0b11 & $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 = 0b11 & $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   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace ASN1\Component;
6 6
 
@@ -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", 
Please login to merge, or discard this patch.
lib/ASN1/Feature/ElementBase.php 2 patches
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 bool
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 bool
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.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace ASN1\Feature;
6 6
 
Please login to merge, or discard this patch.
lib/ASN1/Exception/DecodeException.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace ASN1\Exception;
6 6
 
Please login to merge, or discard this patch.
lib/ASN1/Type/Structure.php 2 patches
Indentation   +313 added lines, -313 removed lines patch added patch discarded remove patch
@@ -13,339 +13,339 @@
 block discarded – undo
13 13
  * Base class for the constructed types.
14 14
  */
15 15
 abstract class Structure extends Element implements 
16
-    \Countable,
17
-    \IteratorAggregate
16
+	\Countable,
17
+	\IteratorAggregate
18 18
 {
19
-    use UniversalClass;
19
+	use UniversalClass;
20 20
     
21
-    /**
22
-     * Array of elements in the structure.
23
-     *
24
-     * @var Element[] $_elements
25
-     */
26
-    protected $_elements;
21
+	/**
22
+	 * Array of elements in the structure.
23
+	 *
24
+	 * @var Element[] $_elements
25
+	 */
26
+	protected $_elements;
27 27
     
28
-    /**
29
-     * Lookup table for the tagged elements.
30
-     *
31
-     * @var TaggedType[]|null $_taggedMap
32
-     */
33
-    private $_taggedMap;
28
+	/**
29
+	 * Lookup table for the tagged elements.
30
+	 *
31
+	 * @var TaggedType[]|null $_taggedMap
32
+	 */
33
+	private $_taggedMap;
34 34
     
35
-    /**
36
-     * Cache variable of elements wrapped into UnspecifiedType objects.
37
-     *
38
-     * @var UnspecifiedType[]|null $_unspecifiedTypes
39
-     */
40
-    private $_unspecifiedTypes;
35
+	/**
36
+	 * Cache variable of elements wrapped into UnspecifiedType objects.
37
+	 *
38
+	 * @var UnspecifiedType[]|null $_unspecifiedTypes
39
+	 */
40
+	private $_unspecifiedTypes;
41 41
     
42
-    /**
43
-     * Constructor.
44
-     *
45
-     * @param ElementBase ...$elements Any number of elements
46
-     */
47
-    public function __construct(ElementBase ...$elements)
48
-    {
49
-        $this->_elements = array_map(
50
-            function (ElementBase $el) {
51
-                return $el->asElement();
52
-            }, $elements);
53
-    }
42
+	/**
43
+	 * Constructor.
44
+	 *
45
+	 * @param ElementBase ...$elements Any number of elements
46
+	 */
47
+	public function __construct(ElementBase ...$elements)
48
+	{
49
+		$this->_elements = array_map(
50
+			function (ElementBase $el) {
51
+				return $el->asElement();
52
+			}, $elements);
53
+	}
54 54
     
55
-    /**
56
-     * Clone magic method.
57
-     */
58
-    public function __clone()
59
-    {
60
-        // clear cache-variables
61
-        $this->_taggedMap = null;
62
-        $this->_unspecifiedTypes = null;
63
-    }
55
+	/**
56
+	 * Clone magic method.
57
+	 */
58
+	public function __clone()
59
+	{
60
+		// clear cache-variables
61
+		$this->_taggedMap = null;
62
+		$this->_unspecifiedTypes = null;
63
+	}
64 64
     
65
-    /**
66
-     *
67
-     * @see \ASN1\Element::isConstructed()
68
-     * @return bool
69
-     */
70
-    public function isConstructed(): bool
71
-    {
72
-        return true;
73
-    }
65
+	/**
66
+	 *
67
+	 * @see \ASN1\Element::isConstructed()
68
+	 * @return bool
69
+	 */
70
+	public function isConstructed(): bool
71
+	{
72
+		return true;
73
+	}
74 74
     
75
-    /**
76
-     *
77
-     * @see \ASN1\Element::_encodedContentDER()
78
-     * @return string
79
-     */
80
-    protected function _encodedContentDER(): string
81
-    {
82
-        $data = "";
83
-        foreach ($this->_elements as $element) {
84
-            $data .= $element->toDER();
85
-        }
86
-        return $data;
87
-    }
75
+	/**
76
+	 *
77
+	 * @see \ASN1\Element::_encodedContentDER()
78
+	 * @return string
79
+	 */
80
+	protected function _encodedContentDER(): string
81
+	{
82
+		$data = "";
83
+		foreach ($this->_elements as $element) {
84
+			$data .= $element->toDER();
85
+		}
86
+		return $data;
87
+	}
88 88
     
89
-    /**
90
-     *
91
-     * {@inheritdoc}
92
-     * @see \ASN1\Element::_decodeFromDER()
93
-     * @return self
94
-     */
95
-    protected static function _decodeFromDER(Identifier $identifier, string $data,
96
-        int &$offset): ElementBase
97
-    {
98
-        $idx = $offset;
99
-        if (!$identifier->isConstructed()) {
100
-            throw new DecodeException(
101
-                "Structured element must have constructed bit set.");
102
-        }
103
-        $length = Length::expectFromDER($data, $idx);
104
-        $end = $idx + $length->intLength();
105
-        $elements = [];
106
-        while ($idx < $end) {
107
-            $elements[] = Element::fromDER($data, $idx);
108
-            // check that element didn't overflow length
109
-            if ($idx > $end) {
110
-                throw new DecodeException(
111
-                    "Structure's content overflows length.");
112
-            }
113
-        }
114
-        $offset = $idx;
115
-        // return instance by static late binding
116
-        return new static(...$elements);
117
-    }
89
+	/**
90
+	 *
91
+	 * {@inheritdoc}
92
+	 * @see \ASN1\Element::_decodeFromDER()
93
+	 * @return self
94
+	 */
95
+	protected static function _decodeFromDER(Identifier $identifier, string $data,
96
+		int &$offset): ElementBase
97
+	{
98
+		$idx = $offset;
99
+		if (!$identifier->isConstructed()) {
100
+			throw new DecodeException(
101
+				"Structured element must have constructed bit set.");
102
+		}
103
+		$length = Length::expectFromDER($data, $idx);
104
+		$end = $idx + $length->intLength();
105
+		$elements = [];
106
+		while ($idx < $end) {
107
+			$elements[] = Element::fromDER($data, $idx);
108
+			// check that element didn't overflow length
109
+			if ($idx > $end) {
110
+				throw new DecodeException(
111
+					"Structure's content overflows length.");
112
+			}
113
+		}
114
+		$offset = $idx;
115
+		// return instance by static late binding
116
+		return new static(...$elements);
117
+	}
118 118
     
119
-    /**
120
-     * Explode DER structure to DER encoded components that it contains.
121
-     *
122
-     * @param string $data
123
-     * @throws DecodeException
124
-     * @return string[]
125
-     */
126
-    public static function explodeDER(string $data): array
127
-    {
128
-        $offset = 0;
129
-        $identifier = Identifier::fromDER($data, $offset);
130
-        if (!$identifier->isConstructed()) {
131
-            throw new DecodeException("Element is not constructed.");
132
-        }
133
-        $length = Length::expectFromDER($data, $offset)->intLength();
134
-        $end = $offset + $length;
135
-        $parts = [];
136
-        while ($offset < $end) {
137
-            // start of the element
138
-            $idx = $offset;
139
-            // skip identifier
140
-            Identifier::fromDER($data, $offset);
141
-            // decode element length
142
-            $length = Length::expectFromDER($data, $offset)->intLength();
143
-            // extract der encoding of the element
144
-            $parts[] = substr($data, $idx, $offset - $idx + $length);
145
-            // update offset over content
146
-            $offset += $length;
147
-        }
148
-        return $parts;
149
-    }
119
+	/**
120
+	 * Explode DER structure to DER encoded components that it contains.
121
+	 *
122
+	 * @param string $data
123
+	 * @throws DecodeException
124
+	 * @return string[]
125
+	 */
126
+	public static function explodeDER(string $data): array
127
+	{
128
+		$offset = 0;
129
+		$identifier = Identifier::fromDER($data, $offset);
130
+		if (!$identifier->isConstructed()) {
131
+			throw new DecodeException("Element is not constructed.");
132
+		}
133
+		$length = Length::expectFromDER($data, $offset)->intLength();
134
+		$end = $offset + $length;
135
+		$parts = [];
136
+		while ($offset < $end) {
137
+			// start of the element
138
+			$idx = $offset;
139
+			// skip identifier
140
+			Identifier::fromDER($data, $offset);
141
+			// decode element length
142
+			$length = Length::expectFromDER($data, $offset)->intLength();
143
+			// extract der encoding of the element
144
+			$parts[] = substr($data, $idx, $offset - $idx + $length);
145
+			// update offset over content
146
+			$offset += $length;
147
+		}
148
+		return $parts;
149
+	}
150 150
     
151
-    /**
152
-     * Get self with an element at the given index replaced by another.
153
-     *
154
-     * @param int $idx Element index
155
-     * @param Element $el New element to insert into the structure
156
-     * @throws \OutOfBoundsException
157
-     * @return self
158
-     */
159
-    public function withReplaced(int $idx, Element $el): self
160
-    {
161
-        if (!isset($this->_elements[$idx])) {
162
-            throw new \OutOfBoundsException(
163
-                "Structure doesn't have element at index $idx.");
164
-        }
165
-        $obj = clone $this;
166
-        $obj->_elements[$idx] = $el;
167
-        return $obj;
168
-    }
151
+	/**
152
+	 * Get self with an element at the given index replaced by another.
153
+	 *
154
+	 * @param int $idx Element index
155
+	 * @param Element $el New element to insert into the structure
156
+	 * @throws \OutOfBoundsException
157
+	 * @return self
158
+	 */
159
+	public function withReplaced(int $idx, Element $el): self
160
+	{
161
+		if (!isset($this->_elements[$idx])) {
162
+			throw new \OutOfBoundsException(
163
+				"Structure doesn't have element at index $idx.");
164
+		}
165
+		$obj = clone $this;
166
+		$obj->_elements[$idx] = $el;
167
+		return $obj;
168
+	}
169 169
     
170
-    /**
171
-     * Get self with an element inserted before the given index.
172
-     *
173
-     * @param int $idx Element index
174
-     * @param Element $el New element to insert into the structure
175
-     * @throws \OutOfBoundsException
176
-     * @return self
177
-     */
178
-    public function withInserted(int $idx, Element $el): self
179
-    {
180
-        if (count($this->_elements) < $idx || $idx < 0) {
181
-            throw new \OutOfBoundsException("Index $idx is out of bounds.");
182
-        }
183
-        $obj = clone $this;
184
-        array_splice($obj->_elements, $idx, 0, [$el]);
185
-        return $obj;
186
-    }
170
+	/**
171
+	 * Get self with an element inserted before the given index.
172
+	 *
173
+	 * @param int $idx Element index
174
+	 * @param Element $el New element to insert into the structure
175
+	 * @throws \OutOfBoundsException
176
+	 * @return self
177
+	 */
178
+	public function withInserted(int $idx, Element $el): self
179
+	{
180
+		if (count($this->_elements) < $idx || $idx < 0) {
181
+			throw new \OutOfBoundsException("Index $idx is out of bounds.");
182
+		}
183
+		$obj = clone $this;
184
+		array_splice($obj->_elements, $idx, 0, [$el]);
185
+		return $obj;
186
+	}
187 187
     
188
-    /**
189
-     * Get self with an element appended to the end.
190
-     *
191
-     * @param Element $el Element to insert into the structure
192
-     * @return self
193
-     */
194
-    public function withAppended(Element $el): self
195
-    {
196
-        $obj = clone $this;
197
-        array_push($obj->_elements, $el);
198
-        return $obj;
199
-    }
188
+	/**
189
+	 * Get self with an element appended to the end.
190
+	 *
191
+	 * @param Element $el Element to insert into the structure
192
+	 * @return self
193
+	 */
194
+	public function withAppended(Element $el): self
195
+	{
196
+		$obj = clone $this;
197
+		array_push($obj->_elements, $el);
198
+		return $obj;
199
+	}
200 200
     
201
-    /**
202
-     * Get self with an element prepended in the beginning.
203
-     *
204
-     * @param Element $el Element to insert into the structure
205
-     * @return self
206
-     */
207
-    public function withPrepended(Element $el): self
208
-    {
209
-        $obj = clone $this;
210
-        array_unshift($obj->_elements, $el);
211
-        return $obj;
212
-    }
201
+	/**
202
+	 * Get self with an element prepended in the beginning.
203
+	 *
204
+	 * @param Element $el Element to insert into the structure
205
+	 * @return self
206
+	 */
207
+	public function withPrepended(Element $el): self
208
+	{
209
+		$obj = clone $this;
210
+		array_unshift($obj->_elements, $el);
211
+		return $obj;
212
+	}
213 213
     
214
-    /**
215
-     * Get self with an element at the given index removed.
216
-     *
217
-     * @param int $idx Element index
218
-     * @throws \OutOfBoundsException
219
-     * @return self
220
-     */
221
-    public function withoutElement(int $idx): self
222
-    {
223
-        if (!isset($this->_elements[$idx])) {
224
-            throw new \OutOfBoundsException(
225
-                "Structure doesn't have element at index $idx.");
226
-        }
227
-        $obj = clone $this;
228
-        array_splice($obj->_elements, $idx, 1);
229
-        return $obj;
230
-    }
214
+	/**
215
+	 * Get self with an element at the given index removed.
216
+	 *
217
+	 * @param int $idx Element index
218
+	 * @throws \OutOfBoundsException
219
+	 * @return self
220
+	 */
221
+	public function withoutElement(int $idx): self
222
+	{
223
+		if (!isset($this->_elements[$idx])) {
224
+			throw new \OutOfBoundsException(
225
+				"Structure doesn't have element at index $idx.");
226
+		}
227
+		$obj = clone $this;
228
+		array_splice($obj->_elements, $idx, 1);
229
+		return $obj;
230
+	}
231 231
     
232
-    /**
233
-     * Get elements in the structure.
234
-     *
235
-     * @return UnspecifiedType[]
236
-     */
237
-    public function elements(): array
238
-    {
239
-        if (!isset($this->_unspecifiedTypes)) {
240
-            $this->_unspecifiedTypes = array_map(
241
-                function (Element $el) {
242
-                    return new UnspecifiedType($el);
243
-                }, $this->_elements);
244
-        }
245
-        return $this->_unspecifiedTypes;
246
-    }
232
+	/**
233
+	 * Get elements in the structure.
234
+	 *
235
+	 * @return UnspecifiedType[]
236
+	 */
237
+	public function elements(): array
238
+	{
239
+		if (!isset($this->_unspecifiedTypes)) {
240
+			$this->_unspecifiedTypes = array_map(
241
+				function (Element $el) {
242
+					return new UnspecifiedType($el);
243
+				}, $this->_elements);
244
+		}
245
+		return $this->_unspecifiedTypes;
246
+	}
247 247
     
248
-    /**
249
-     * Check whether the structure has an element at the given index, optionally
250
-     * satisfying given tag expectation.
251
-     *
252
-     * @param int $idx Index 0..n
253
-     * @param int|null $expectedTag Optional type tag expectation
254
-     * @return bool
255
-     */
256
-    public function has(int $idx, $expectedTag = null): bool
257
-    {
258
-        if (!isset($this->_elements[$idx])) {
259
-            return false;
260
-        }
261
-        if (isset($expectedTag)) {
262
-            if (!$this->_elements[$idx]->isType($expectedTag)) {
263
-                return false;
264
-            }
265
-        }
266
-        return true;
267
-    }
248
+	/**
249
+	 * Check whether the structure has an element at the given index, optionally
250
+	 * satisfying given tag expectation.
251
+	 *
252
+	 * @param int $idx Index 0..n
253
+	 * @param int|null $expectedTag Optional type tag expectation
254
+	 * @return bool
255
+	 */
256
+	public function has(int $idx, $expectedTag = null): bool
257
+	{
258
+		if (!isset($this->_elements[$idx])) {
259
+			return false;
260
+		}
261
+		if (isset($expectedTag)) {
262
+			if (!$this->_elements[$idx]->isType($expectedTag)) {
263
+				return false;
264
+			}
265
+		}
266
+		return true;
267
+	}
268 268
     
269
-    /**
270
-     * Get the element at the given index, optionally checking that the element
271
-     * has a given tag.
272
-     *
273
-     * <strong>NOTE!</strong> Expectation checking is deprecated and should be
274
-     * done with <code>UnspecifiedType</code>.
275
-     *
276
-     * @param int $idx Index 0..n
277
-     * @param int|null $expectedTag Optional type tag expectation
278
-     * @throws \OutOfBoundsException If element doesn't exists
279
-     * @throws \UnexpectedValueException If expectation fails
280
-     * @return UnspecifiedType
281
-     */
282
-    public function at(int $idx, $expectedTag = null): UnspecifiedType
283
-    {
284
-        if (!isset($this->_elements[$idx])) {
285
-            throw new \OutOfBoundsException(
286
-                "Structure doesn't have an element at index $idx.");
287
-        }
288
-        $element = $this->_elements[$idx];
289
-        if (isset($expectedTag)) {
290
-            $element->expectType($expectedTag);
291
-        }
292
-        return new UnspecifiedType($element);
293
-    }
269
+	/**
270
+	 * Get the element at the given index, optionally checking that the element
271
+	 * has a given tag.
272
+	 *
273
+	 * <strong>NOTE!</strong> Expectation checking is deprecated and should be
274
+	 * done with <code>UnspecifiedType</code>.
275
+	 *
276
+	 * @param int $idx Index 0..n
277
+	 * @param int|null $expectedTag Optional type tag expectation
278
+	 * @throws \OutOfBoundsException If element doesn't exists
279
+	 * @throws \UnexpectedValueException If expectation fails
280
+	 * @return UnspecifiedType
281
+	 */
282
+	public function at(int $idx, $expectedTag = null): UnspecifiedType
283
+	{
284
+		if (!isset($this->_elements[$idx])) {
285
+			throw new \OutOfBoundsException(
286
+				"Structure doesn't have an element at index $idx.");
287
+		}
288
+		$element = $this->_elements[$idx];
289
+		if (isset($expectedTag)) {
290
+			$element->expectType($expectedTag);
291
+		}
292
+		return new UnspecifiedType($element);
293
+	}
294 294
     
295
-    /**
296
-     * Check whether the structure contains a context specific element with a
297
-     * given tag.
298
-     *
299
-     * @param int $tag Tag number
300
-     * @return bool
301
-     */
302
-    public function hasTagged(int $tag): bool
303
-    {
304
-        // lazily build lookup map
305
-        if (!isset($this->_taggedMap)) {
306
-            $this->_taggedMap = [];
307
-            foreach ($this->_elements as $element) {
308
-                if ($element->isTagged()) {
309
-                    $this->_taggedMap[$element->tag()] = $element;
310
-                }
311
-            }
312
-        }
313
-        return isset($this->_taggedMap[$tag]);
314
-    }
295
+	/**
296
+	 * Check whether the structure contains a context specific element with a
297
+	 * given tag.
298
+	 *
299
+	 * @param int $tag Tag number
300
+	 * @return bool
301
+	 */
302
+	public function hasTagged(int $tag): bool
303
+	{
304
+		// lazily build lookup map
305
+		if (!isset($this->_taggedMap)) {
306
+			$this->_taggedMap = [];
307
+			foreach ($this->_elements as $element) {
308
+				if ($element->isTagged()) {
309
+					$this->_taggedMap[$element->tag()] = $element;
310
+				}
311
+			}
312
+		}
313
+		return isset($this->_taggedMap[$tag]);
314
+	}
315 315
     
316
-    /**
317
-     * Get a context specific element tagged with a given tag.
318
-     *
319
-     * @param int $tag
320
-     * @throws \LogicException If tag doesn't exists
321
-     * @return TaggedType
322
-     */
323
-    public function getTagged(int $tag): TaggedType
324
-    {
325
-        if (!$this->hasTagged($tag)) {
326
-            throw new \LogicException("No tagged element for tag $tag.");
327
-        }
328
-        return $this->_taggedMap[$tag];
329
-    }
316
+	/**
317
+	 * Get a context specific element tagged with a given tag.
318
+	 *
319
+	 * @param int $tag
320
+	 * @throws \LogicException If tag doesn't exists
321
+	 * @return TaggedType
322
+	 */
323
+	public function getTagged(int $tag): TaggedType
324
+	{
325
+		if (!$this->hasTagged($tag)) {
326
+			throw new \LogicException("No tagged element for tag $tag.");
327
+		}
328
+		return $this->_taggedMap[$tag];
329
+	}
330 330
     
331
-    /**
332
-     *
333
-     * @see \Countable::count()
334
-     * @return int
335
-     */
336
-    public function count(): int
337
-    {
338
-        return count($this->_elements);
339
-    }
331
+	/**
332
+	 *
333
+	 * @see \Countable::count()
334
+	 * @return int
335
+	 */
336
+	public function count(): int
337
+	{
338
+		return count($this->_elements);
339
+	}
340 340
     
341
-    /**
342
-     * Get an iterator for the UnspecifiedElement objects.
343
-     *
344
-     * @see \IteratorAggregate::getIterator()
345
-     * @return \ArrayIterator
346
-     */
347
-    public function getIterator(): \ArrayIterator
348
-    {
349
-        return new \ArrayIterator($this->elements());
350
-    }
341
+	/**
342
+	 * Get an iterator for the UnspecifiedElement objects.
343
+	 *
344
+	 * @see \IteratorAggregate::getIterator()
345
+	 * @return \ArrayIterator
346
+	 */
347
+	public function getIterator(): \ArrayIterator
348
+	{
349
+		return new \ArrayIterator($this->elements());
350
+	}
351 351
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-declare(strict_types = 1);
2
+declare(strict_types=1);
3 3
 
4 4
 namespace ASN1\Type;
5 5
 
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
     public function __construct(ElementBase ...$elements)
48 48
     {
49 49
         $this->_elements = array_map(
50
-            function (ElementBase $el) {
50
+            function(ElementBase $el) {
51 51
                 return $el->asElement();
52 52
             }, $elements);
53 53
     }
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
     {
239 239
         if (!isset($this->_unspecifiedTypes)) {
240 240
             $this->_unspecifiedTypes = array_map(
241
-                function (Element $el) {
241
+                function(Element $el) {
242 242
                     return new UnspecifiedType($el);
243 243
                 }, $this->_elements);
244 244
         }
Please login to merge, or discard this patch.