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 ( 9e3709...6a1987 )
by Joni
03:09
created
lib/ASN1/Type/PrimitiveType.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -9,13 +9,13 @@
 block discarded – undo
9 9
  */
10 10
 trait PrimitiveType
11 11
 {
12
-    /**
13
-     *
14
-     * @see \ASN1\Element::isConstructed()
15
-     * @return bool
16
-     */
17
-    public function isConstructed(): bool
18
-    {
19
-        return false;
20
-    }
12
+	/**
13
+	 *
14
+	 * @see \ASN1\Element::isConstructed()
15
+	 * @return bool
16
+	 */
17
+	public function isConstructed(): bool
18
+	{
19
+		return false;
20
+	}
21 21
 }
Please login to merge, or discard this patch.
lib/ASN1/Type/PrimitiveString.php 1 patch
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.
lib/ASN1/Type/Constructed/Sequence.php 1 patch
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.
lib/ASN1/Type/Constructed/Set.php 1 patch
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.
lib/ASN1/Element.php 3 patches
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 self
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 self
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.
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.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -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",
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
      * @return self
192 192
      */
193 193
     protected static function _decodeFromDER(Identifier $identifier, string $data,
194
-        int &$offset): ElementBase
194
+        int & $offset): ElementBase
195 195
     {
196 196
         throw new \BadMethodCallException(
197 197
             __METHOD__ . " must be implemented in derived class.");
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
      *         type, but decoding yields another type
211 211
      * @return ElementBase
212 212
      */
213
-    public static function fromDER(string $data, int &$offset = null): ElementBase
213
+    public static function fromDER(string $data, int & $offset = null): ElementBase
214 214
     {
215 215
         // decode identifier
216 216
         $idx = $offset ?? 0;
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   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
      * @throws DecodeException If decoding fails
51 51
      * @return self
52 52
      */
53
-    public static function fromDER(string $data, int &$offset = null): self
53
+    public static function fromDER(string $data, int & $offset = null): self
54 54
     {
55 55
         $idx = $offset ?? 0;
56 56
         $datalen = strlen($data);
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
      * @return string Integer as a string
90 90
      */
91 91
     private static function _decodeLongFormLength(int $length, string $data,
92
-        int &$offset): string
92
+        int & $offset): string
93 93
     {
94 94
         // first octet must not be 0xff (spec 8.1.3.5c)
95 95
         if ($length == 127) {
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
      * @throws DecodeException If decoding or expectation fails
118 118
      * @return self
119 119
      */
120
-    public static function expectFromDER(string $data, int &$offset,
120
+    public static function expectFromDER(string $data, int & $offset,
121 121
         int $expected = null): self
122 122
     {
123 123
         $idx = $offset;
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   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
      *
27 27
      * @var array
28 28
      */
29
-    const MAP_CLASS_TO_NAME = [ /* @formatter:off */
29
+    const MAP_CLASS_TO_NAME = [/* @formatter:off */
30 30
         self::CLASS_UNIVERSAL => "UNIVERSAL", 
31 31
         self::CLASS_APPLICATION => "APPLICATION", 
32 32
         self::CLASS_CONTEXT_SPECIFIC => "CONTEXT SPECIFIC", 
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
      * @throws DecodeException If decoding fails
85 85
      * @return self
86 86
      */
87
-    public static function fromDER(string $data, int &$offset = null): Identifier
87
+    public static function fromDER(string $data, int & $offset = null): Identifier
88 88
     {
89 89
         $idx = $offset ?? 0;
90 90
         $datalen = strlen($data);
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
      * @throws DecodeException If decoding fails
118 118
      * @return string Tag number
119 119
      */
120
-    private static function _decodeLongFormTag(string $data, int &$offset): string
120
+    private static function _decodeLongFormTag(string $data, int & $offset): string
121 121
     {
122 122
         $datalen = strlen($data);
123 123
         $tag = gmp_init(0, 10);
Please login to merge, or discard this patch.
lib/ASN1/Feature/ElementBase.php 1 patch
Indentation   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -13,86 +13,86 @@
 block discarded – undo
13 13
  */
14 14
 interface ElementBase extends Encodable
15 15
 {
16
-    /**
17
-     * Get the class of the ASN.1 type.
18
-     *
19
-     * One of <code>Identifier::CLASS_*</code> constants.
20
-     *
21
-     * @return int
22
-     */
23
-    public function typeClass(): int;
16
+	/**
17
+	 * Get the class of the ASN.1 type.
18
+	 *
19
+	 * One of <code>Identifier::CLASS_*</code> constants.
20
+	 *
21
+	 * @return int
22
+	 */
23
+	public function typeClass(): int;
24 24
     
25
-    /**
26
-     * Check whether the element is constructed.
27
-     *
28
-     * Otherwise it's primitive.
29
-     *
30
-     * @return bool
31
-     */
32
-    public function isConstructed(): bool;
25
+	/**
26
+	 * Check whether the element is constructed.
27
+	 *
28
+	 * Otherwise it's primitive.
29
+	 *
30
+	 * @return bool
31
+	 */
32
+	public function isConstructed(): bool;
33 33
     
34
-    /**
35
-     * Get the tag of the element.
36
-     *
37
-     * Interpretation of the tag depends on the context. For example it may
38
-     * represent a universal type tag or a tag of an implicitly or explicitly
39
-     * tagged type.
40
-     *
41
-     * @return int
42
-     */
43
-    public function tag(): int;
34
+	/**
35
+	 * Get the tag of the element.
36
+	 *
37
+	 * Interpretation of the tag depends on the context. For example it may
38
+	 * represent a universal type tag or a tag of an implicitly or explicitly
39
+	 * tagged type.
40
+	 *
41
+	 * @return int
42
+	 */
43
+	public function tag(): int;
44 44
     
45
-    /**
46
-     * Check whether the element is a type of a given tag.
47
-     *
48
-     * @param int $tag Type tag
49
-     * @return 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.