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.
Test Setup Failed
Pull Request — master (#4)
by thomas
02:54
created
lib/ASN1/Feature/Encodable.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -9,10 +9,10 @@
 block discarded – undo
9 9
  */
10 10
 interface Encodable
11 11
 {
12
-    /**
13
-     * Encode object to DER.
14
-     *
15
-     * @return string
16
-     */
17
-    public function toDER(): string;
12
+	/**
13
+	 * Encode object to DER.
14
+	 *
15
+	 * @return string
16
+	 */
17
+	public function toDER(): string;
18 18
 }
Please login to merge, or discard this patch.
lib/ASN1/Feature/ElementBase.php 1 patch
Indentation   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -11,79 +11,79 @@
 block discarded – undo
11 11
  */
12 12
 interface ElementBase extends Encodable
13 13
 {
14
-    /**
15
-     * Get the class of the ASN.1 type.
16
-     *
17
-     * One of <code>Identifier::CLASS_*</code> constants.
18
-     *
19
-     * @return int
20
-     */
21
-    public function typeClass(): int;
14
+	/**
15
+	 * Get the class of the ASN.1 type.
16
+	 *
17
+	 * One of <code>Identifier::CLASS_*</code> constants.
18
+	 *
19
+	 * @return int
20
+	 */
21
+	public function typeClass(): int;
22 22
     
23
-    /**
24
-     * Check whether the element is constructed.
25
-     *
26
-     * Otherwise it's primitive.
27
-     *
28
-     * @return bool
29
-     */
30
-    public function isConstructed(): bool;
23
+	/**
24
+	 * Check whether the element is constructed.
25
+	 *
26
+	 * Otherwise it's primitive.
27
+	 *
28
+	 * @return bool
29
+	 */
30
+	public function isConstructed(): bool;
31 31
     
32
-    /**
33
-     * Get the tag of the element.
34
-     *
35
-     * Interpretation of the tag depends on the context. For example it may
36
-     * represent a universal type tag or a tag of an implicitly or explicitly
37
-     * tagged type.
38
-     *
39
-     * @return int
40
-     */
41
-    public function tag();
32
+	/**
33
+	 * Get the tag of the element.
34
+	 *
35
+	 * Interpretation of the tag depends on the context. For example it may
36
+	 * represent a universal type tag or a tag of an implicitly or explicitly
37
+	 * tagged type.
38
+	 *
39
+	 * @return int
40
+	 */
41
+	public function tag();
42 42
     
43
-    /**
44
-     * Check whether the element is a type of a given tag.
45
-     *
46
-     * @param int $tag Type tag
47
-     * @return boolean
48
-     */
49
-    public function isType($tag): bool;
43
+	/**
44
+	 * Check whether the element is a type of a given tag.
45
+	 *
46
+	 * @param int $tag Type tag
47
+	 * @return boolean
48
+	 */
49
+	public function isType($tag): bool;
50 50
     
51
-    /**
52
-     * Check whether the element is a type of a given tag.
53
-     *
54
-     * Throws an exception if expectation fails.
55
-     *
56
-     * @param int $tag Type tag
57
-     * @throws \UnexpectedValueException If the element type differs from the
58
-     *         expected
59
-     * @return ElementBase
60
-     */
61
-    public function expectType($tag): ElementBase;
51
+	/**
52
+	 * Check whether the element is a type of a given tag.
53
+	 *
54
+	 * Throws an exception if expectation fails.
55
+	 *
56
+	 * @param int $tag Type tag
57
+	 * @throws \UnexpectedValueException If the element type differs from the
58
+	 *         expected
59
+	 * @return ElementBase
60
+	 */
61
+	public function expectType($tag): ElementBase;
62 62
     
63
-    /**
64
-     * Check whether the element is tagged (context specific).
65
-     *
66
-     * @return bool
67
-     */
68
-    public function isTagged(): bool;
63
+	/**
64
+	 * Check whether the element is tagged (context specific).
65
+	 *
66
+	 * @return bool
67
+	 */
68
+	public function isTagged(): bool;
69 69
     
70
-    /**
71
-     * Check whether the element is tagged (context specific) and optionally has
72
-     * a given tag.
73
-     *
74
-     * Throws an exception if the element is not tagged or tag differs from
75
-     * the expected.
76
-     *
77
-     * @param int|null $tag Optional type tag
78
-     * @throws \UnexpectedValueException If expectation fails
79
-     * @return \ASN1\Type\TaggedType
80
-     */
81
-    public function expectTagged($tag = null): TaggedType;
70
+	/**
71
+	 * Check whether the element is tagged (context specific) and optionally has
72
+	 * a given tag.
73
+	 *
74
+	 * Throws an exception if the element is not tagged or tag differs from
75
+	 * the expected.
76
+	 *
77
+	 * @param int|null $tag Optional type tag
78
+	 * @throws \UnexpectedValueException If expectation fails
79
+	 * @return \ASN1\Type\TaggedType
80
+	 */
81
+	public function expectTagged($tag = null): TaggedType;
82 82
     
83
-    /**
84
-     * Get the object as an abstract Element instance.
85
-     *
86
-     * @return \ASN1\Element
87
-     */
88
-    public function asElement(): Element;
83
+	/**
84
+	 * Get the object as an abstract Element instance.
85
+	 *
86
+	 * @return \ASN1\Element
87
+	 */
88
+	public function asElement(): Element;
89 89
 }
Please login to merge, or discard this patch.
lib/ASN1/Component/Length.php 1 patch
Indentation   +177 added lines, -177 removed lines patch added patch discarded remove patch
@@ -12,190 +12,190 @@
 block discarded – undo
12 12
  */
13 13
 class Length implements Encodable
14 14
 {
15
-    /**
16
-     * Length.
17
-     *
18
-     * @var int|string
19
-     */
20
-    private $_length;
15
+	/**
16
+	 * Length.
17
+	 *
18
+	 * @var int|string
19
+	 */
20
+	private $_length;
21 21
     
22
-    /**
23
-     * Whether length is indefinite.
24
-     *
25
-     * @var boolean
26
-     */
27
-    private $_indefinite;
22
+	/**
23
+	 * Whether length is indefinite.
24
+	 *
25
+	 * @var boolean
26
+	 */
27
+	private $_indefinite;
28 28
     
29
-    /**
30
-     * Constructor.
31
-     *
32
-     * @param int|string $length Length
33
-     * @param boolean $indefinite Whether length is indefinite
34
-     */
35
-    public function __construct($length, bool $indefinite = false)
36
-    {
37
-        $this->_length = $length;
38
-        $this->_indefinite = $indefinite;
39
-    }
29
+	/**
30
+	 * Constructor.
31
+	 *
32
+	 * @param int|string $length Length
33
+	 * @param boolean $indefinite Whether length is indefinite
34
+	 */
35
+	public function __construct($length, bool $indefinite = false)
36
+	{
37
+		$this->_length = $length;
38
+		$this->_indefinite = $indefinite;
39
+	}
40 40
     
41
-    /**
42
-     * Decode length component from DER data.
43
-     *
44
-     * @param string $data DER encoded data
45
-     * @param int|null $offset Reference to the variable that contains offset
46
-     *        into the data where to start parsing. Variable is updated to
47
-     *        the offset next to the parsed length component. If null, start
48
-     *        from offset 0.
49
-     * @throws DecodeException If decoding fails
50
-     * @return self
51
-     */
52
-    public static function fromDER(string $data, int &$offset = null): self
53
-    {
54
-        $idx = $offset ? $offset : 0;
55
-        $datalen = strlen($data);
56
-        if ($idx >= $datalen) {
57
-            throw new DecodeException("Invalid offset.");
58
-        }
59
-        $indefinite = false;
60
-        $byte = ord($data[$idx++]);
61
-        // bits 7 to 1
62
-        $length = (0x7f & $byte);
63
-        // long form
64
-        if (0x80 & $byte) {
65
-            if (!$length) {
66
-                $indefinite = true;
67
-            } else {
68
-                if ($idx + $length > $datalen) {
69
-                    throw new DecodeException("Too many length octets.");
70
-                }
71
-                $length = self::_decodeLongFormLength($length, $data, $idx);
72
-            }
73
-        }
74
-        if (isset($offset)) {
75
-            $offset = $idx;
76
-        }
77
-        return new self($length, $indefinite);
78
-    }
41
+	/**
42
+	 * Decode length component from DER data.
43
+	 *
44
+	 * @param string $data DER encoded data
45
+	 * @param int|null $offset Reference to the variable that contains offset
46
+	 *        into the data where to start parsing. Variable is updated to
47
+	 *        the offset next to the parsed length component. If null, start
48
+	 *        from offset 0.
49
+	 * @throws DecodeException If decoding fails
50
+	 * @return self
51
+	 */
52
+	public static function fromDER(string $data, int &$offset = null): self
53
+	{
54
+		$idx = $offset ? $offset : 0;
55
+		$datalen = strlen($data);
56
+		if ($idx >= $datalen) {
57
+			throw new DecodeException("Invalid offset.");
58
+		}
59
+		$indefinite = false;
60
+		$byte = ord($data[$idx++]);
61
+		// bits 7 to 1
62
+		$length = (0x7f & $byte);
63
+		// long form
64
+		if (0x80 & $byte) {
65
+			if (!$length) {
66
+				$indefinite = true;
67
+			} else {
68
+				if ($idx + $length > $datalen) {
69
+					throw new DecodeException("Too many length octets.");
70
+				}
71
+				$length = self::_decodeLongFormLength($length, $data, $idx);
72
+			}
73
+		}
74
+		if (isset($offset)) {
75
+			$offset = $idx;
76
+		}
77
+		return new self($length, $indefinite);
78
+	}
79 79
     
80
-    /**
81
-     * Decode long form length.
82
-     *
83
-     * @param int $length Number of octets
84
-     * @param string $data Data
85
-     * @param int $offset Reference to the variable containing offset to the
86
-     *        data.
87
-     * @throws DecodeException If decoding fails
88
-     * @return int|string
89
-     */
90
-    private static function _decodeLongFormLength(int $length, string $data, int &$offset)
91
-    {
92
-        // first octet must not be 0xff (spec 8.1.3.5c)
93
-        if ($length == 127) {
94
-            throw new DecodeException("Invalid number of length octets.");
95
-        }
96
-        $num = gmp_init(0, 10);
97
-        while (--$length >= 0) {
98
-            $byte = ord($data[$offset++]);
99
-            $num <<= 8;
100
-            $num |= $byte;
101
-        }
80
+	/**
81
+	 * Decode long form length.
82
+	 *
83
+	 * @param int $length Number of octets
84
+	 * @param string $data Data
85
+	 * @param int $offset Reference to the variable containing offset to the
86
+	 *        data.
87
+	 * @throws DecodeException If decoding fails
88
+	 * @return int|string
89
+	 */
90
+	private static function _decodeLongFormLength(int $length, string $data, int &$offset)
91
+	{
92
+		// first octet must not be 0xff (spec 8.1.3.5c)
93
+		if ($length == 127) {
94
+			throw new DecodeException("Invalid number of length octets.");
95
+		}
96
+		$num = gmp_init(0, 10);
97
+		while (--$length >= 0) {
98
+			$byte = ord($data[$offset++]);
99
+			$num <<= 8;
100
+			$num |= $byte;
101
+		}
102 102
 
103
-        return gmp_strval($num);
104
-    }
103
+		return gmp_strval($num);
104
+	}
105 105
     
106
-    /**
107
-     * Decode length from DER.
108
-     *
109
-     * Throws an exception if length doesn't match with expected or if data
110
-     * doesn't contain enough bytes.
111
-     *
112
-     * @see self::fromDER
113
-     * @param string $data DER data
114
-     * @param int $offset Reference to the offset variable
115
-     * @param int|null $expected Expected length, null to bypass checking
116
-     * @throws DecodeException If decoding or expectation fails
117
-     * @return self
118
-     */
119
-    public static function expectFromDER(string $data, int &$offset, int $expected = null): self
120
-    {
121
-        $idx = $offset;
122
-        $length = self::fromDER($data, $idx);
123
-        // DER encoding must have definite length (spec 10.1)
124
-        if ($length->isIndefinite()) {
125
-            throw new DecodeException("DER encoding must have definite length.");
126
-        }
127
-        // if certain length was expected
128
-        if (isset($expected) && $expected != $length->_length) {
129
-            throw new DecodeException(
130
-                sprintf("Expected length %d, got %d.", $expected,
131
-                    $length->_length));
132
-        }
133
-        // check that enough data is available
134
-        if (strlen($data) < $idx + $length->_length) {
135
-            throw new DecodeException(
136
-                sprintf("Length %d overflows data, %d bytes left.",
137
-                    $length->_length, strlen($data) - $idx));
138
-        }
139
-        $offset = $idx;
140
-        return $length;
141
-    }
106
+	/**
107
+	 * Decode length from DER.
108
+	 *
109
+	 * Throws an exception if length doesn't match with expected or if data
110
+	 * doesn't contain enough bytes.
111
+	 *
112
+	 * @see self::fromDER
113
+	 * @param string $data DER data
114
+	 * @param int $offset Reference to the offset variable
115
+	 * @param int|null $expected Expected length, null to bypass checking
116
+	 * @throws DecodeException If decoding or expectation fails
117
+	 * @return self
118
+	 */
119
+	public static function expectFromDER(string $data, int &$offset, int $expected = null): self
120
+	{
121
+		$idx = $offset;
122
+		$length = self::fromDER($data, $idx);
123
+		// DER encoding must have definite length (spec 10.1)
124
+		if ($length->isIndefinite()) {
125
+			throw new DecodeException("DER encoding must have definite length.");
126
+		}
127
+		// if certain length was expected
128
+		if (isset($expected) && $expected != $length->_length) {
129
+			throw new DecodeException(
130
+				sprintf("Expected length %d, got %d.", $expected,
131
+					$length->_length));
132
+		}
133
+		// check that enough data is available
134
+		if (strlen($data) < $idx + $length->_length) {
135
+			throw new DecodeException(
136
+				sprintf("Length %d overflows data, %d bytes left.",
137
+					$length->_length, strlen($data) - $idx));
138
+		}
139
+		$offset = $idx;
140
+		return $length;
141
+	}
142 142
     
143
-    /**
144
-     *
145
-     * @see Encodable::toDER()
146
-     * @throws \DomainException If length is too large to encode
147
-     * @return string
148
-     */
149
-    public function toDER(): string
150
-    {
151
-        $bytes = [];
152
-        if ($this->_indefinite) {
153
-            $bytes[] = 0x80;
154
-        } else {
155
-            $num = gmp_init($this->_length, 10);
156
-            // long form
157
-            if ($num > 127) {
158
-                $octets = [];
159
-                for (; $num > 0; $num >>= 8) {
160
-                    $octets[] = gmp_intval(0xff & $num);
161
-                }
162
-                $count = count($octets);
163
-                // first octet must not be 0xff
164
-                if ($count >= 127) {
165
-                    throw new \DomainException("Too many length octets.");
166
-                }
167
-                $bytes[] = 0x80 | $count;
168
-                foreach (array_reverse($octets) as $octet) {
169
-                    $bytes[] = $octet;
170
-                }
171
-            } else { // short form
172
-                $bytes[] = gmp_intval($num);
173
-            }
174
-        }
175
-        return pack("C*", ...$bytes);
176
-    }
143
+	/**
144
+	 *
145
+	 * @see Encodable::toDER()
146
+	 * @throws \DomainException If length is too large to encode
147
+	 * @return string
148
+	 */
149
+	public function toDER(): string
150
+	{
151
+		$bytes = [];
152
+		if ($this->_indefinite) {
153
+			$bytes[] = 0x80;
154
+		} else {
155
+			$num = gmp_init($this->_length, 10);
156
+			// long form
157
+			if ($num > 127) {
158
+				$octets = [];
159
+				for (; $num > 0; $num >>= 8) {
160
+					$octets[] = gmp_intval(0xff & $num);
161
+				}
162
+				$count = count($octets);
163
+				// first octet must not be 0xff
164
+				if ($count >= 127) {
165
+					throw new \DomainException("Too many length octets.");
166
+				}
167
+				$bytes[] = 0x80 | $count;
168
+				foreach (array_reverse($octets) as $octet) {
169
+					$bytes[] = $octet;
170
+				}
171
+			} else { // short form
172
+				$bytes[] = gmp_intval($num);
173
+			}
174
+		}
175
+		return pack("C*", ...$bytes);
176
+	}
177 177
     
178
-    /**
179
-     * Get the length.
180
-     *
181
-     * @throws \LogicException If length is indefinite
182
-     * @return int|string
183
-     */
184
-    public function length()
185
-    {
186
-        if ($this->_indefinite) {
187
-            throw new \LogicException("Length is indefinite.");
188
-        }
189
-        return $this->_length;
190
-    }
178
+	/**
179
+	 * Get the length.
180
+	 *
181
+	 * @throws \LogicException If length is indefinite
182
+	 * @return int|string
183
+	 */
184
+	public function length()
185
+	{
186
+		if ($this->_indefinite) {
187
+			throw new \LogicException("Length is indefinite.");
188
+		}
189
+		return $this->_length;
190
+	}
191 191
     
192
-    /**
193
-     * Whether length is indefinite.
194
-     *
195
-     * @return boolean
196
-     */
197
-    public function isIndefinite(): bool
198
-    {
199
-        return $this->_indefinite;
200
-    }
192
+	/**
193
+	 * Whether length is indefinite.
194
+	 *
195
+	 * @return boolean
196
+	 */
197
+	public function isIndefinite(): bool
198
+	{
199
+		return $this->_indefinite;
200
+	}
201 201
 }
Please login to merge, or discard this patch.
lib/ASN1/Component/Identifier.php 1 patch
Indentation   +261 added lines, -261 removed lines patch added patch discarded remove patch
@@ -12,286 +12,286 @@
 block discarded – undo
12 12
  */
13 13
 class Identifier implements Encodable
14 14
 {
15
-    // Type class enumerations
16
-    const CLASS_UNIVERSAL = 0b00;
17
-    const CLASS_APPLICATION = 0b01;
18
-    const CLASS_CONTEXT_SPECIFIC = 0b10;
19
-    const CLASS_PRIVATE = 0b11;
15
+	// Type class enumerations
16
+	const CLASS_UNIVERSAL = 0b00;
17
+	const CLASS_APPLICATION = 0b01;
18
+	const CLASS_CONTEXT_SPECIFIC = 0b10;
19
+	const CLASS_PRIVATE = 0b11;
20 20
     
21
-    /**
22
-     * Mapping from type class to human readable name.
23
-     *
24
-     * @internal
25
-     *
26
-     * @var array
27
-     */
28
-    const MAP_CLASS_TO_NAME = [
29
-        /* @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
-    ];
21
+	/**
22
+	 * Mapping from type class to human readable name.
23
+	 *
24
+	 * @internal
25
+	 *
26
+	 * @var array
27
+	 */
28
+	const MAP_CLASS_TO_NAME = [
29
+		/* @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 int|string
59
-     */
60
-    private $_tag;
55
+	/**
56
+	 * Content type tag.
57
+	 *
58
+	 * @var int|string
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 = $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 = $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): self
88
-    {
89
-        $idx = $offset ? $offset : 0;
90
-        $datalen = strlen($data);
91
-        if ($idx >= $datalen) {
92
-            throw new DecodeException("Invalid offset.");
93
-        }
94
-        $byte = ord($data[$idx++]);
95
-        // bits 8 and 7 (class)
96
-        // 0 = universal, 1 = application, 2 = context-specific, 3 = private
97
-        $class = (0b11000000 & $byte) >> 6;
98
-        // bit 6 (0 = primitive / 1 = constructed)
99
-        $pc = (0b00100000 & $byte) >> 5;
100
-        // bits 5 to 1 (tag number)
101
-        $tag = (0b00011111 & $byte);
102
-        // long-form identifier
103
-        if (0x1f == $tag) {
104
-            $tag = self::_decodeLongFormTag($data, $idx);
105
-        }
106
-        if (isset($offset)) {
107
-            $offset = $idx;
108
-        }
109
-        return new self($class, $pc, $tag);
110
-    }
76
+	/**
77
+	 * Decode identifier component from DER data.
78
+	 *
79
+	 * @param string $data DER encoded data
80
+	 * @param int|null $offset Reference to the variable that contains offset
81
+	 *        into the data where to start parsing. Variable is updated to
82
+	 *        the offset next to the parsed identifier. If null, start from
83
+	 *        offset 0.
84
+	 * @throws DecodeException If decoding fails
85
+	 * @return self
86
+	 */
87
+	public static function fromDER(string $data, int &$offset = null): self
88
+	{
89
+		$idx = $offset ? $offset : 0;
90
+		$datalen = strlen($data);
91
+		if ($idx >= $datalen) {
92
+			throw new DecodeException("Invalid offset.");
93
+		}
94
+		$byte = ord($data[$idx++]);
95
+		// bits 8 and 7 (class)
96
+		// 0 = universal, 1 = application, 2 = context-specific, 3 = private
97
+		$class = (0b11000000 & $byte) >> 6;
98
+		// bit 6 (0 = primitive / 1 = constructed)
99
+		$pc = (0b00100000 & $byte) >> 5;
100
+		// bits 5 to 1 (tag number)
101
+		$tag = (0b00011111 & $byte);
102
+		// long-form identifier
103
+		if (0x1f == $tag) {
104
+			$tag = self::_decodeLongFormTag($data, $idx);
105
+		}
106
+		if (isset($offset)) {
107
+			$offset = $idx;
108
+		}
109
+		return new self($class, $pc, $tag);
110
+	}
111 111
     
112
-    /**
113
-     * Parse long form tag.
114
-     *
115
-     * @param string $data DER data
116
-     * @param int $offset Reference to the variable containing offset to data
117
-     * @throws DecodeException If decoding fails
118
-     * @return string Tag number
119
-     */
120
-    private static function _decodeLongFormTag(string $data, int &$offset): string
121
-    {
122
-        $datalen = strlen($data);
123
-        $tag = gmp_init(0, 10);
124
-        while (true) {
125
-            if ($offset >= $datalen) {
126
-                throw new DecodeException(
127
-                    "Unexpected end of data while decoding" .
128
-                         " long form identifier.");
129
-            }
130
-            $byte = ord($data[$offset++]);
131
-            $tag <<= 7;
132
-            $tag |= 0x7f & $byte;
133
-            // last byte has bit 8 set to zero
134
-            if (!(0x80 & $byte)) {
135
-                break;
136
-            }
137
-        }
138
-        return gmp_strval($tag, 10);
139
-    }
112
+	/**
113
+	 * Parse long form tag.
114
+	 *
115
+	 * @param string $data DER data
116
+	 * @param int $offset Reference to the variable containing offset to data
117
+	 * @throws DecodeException If decoding fails
118
+	 * @return string Tag number
119
+	 */
120
+	private static function _decodeLongFormTag(string $data, int &$offset): string
121
+	{
122
+		$datalen = strlen($data);
123
+		$tag = gmp_init(0, 10);
124
+		while (true) {
125
+			if ($offset >= $datalen) {
126
+				throw new DecodeException(
127
+					"Unexpected end of data while decoding" .
128
+						 " long form identifier.");
129
+			}
130
+			$byte = ord($data[$offset++]);
131
+			$tag <<= 7;
132
+			$tag |= 0x7f & $byte;
133
+			// last byte has bit 8 set to zero
134
+			if (!(0x80 & $byte)) {
135
+				break;
136
+			}
137
+		}
138
+		return gmp_strval($tag, 10);
139
+	}
140 140
     
141
-    /**
142
-     *
143
-     * @see Encodable::toDER()
144
-     * @return string
145
-     */
146
-    public function toDER(): string
147
-    {
148
-        $bytes = [];
149
-        $byte = $this->_class << 6 | $this->_pc << 5;
150
-        $tag = gmp_init($this->_tag, 10);
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 = gmp_init($this->_tag, 10);
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 int|string
192
-     */
193
-    public function tag()
194
-    {
195
-        return $this->_tag;
196
-    }
188
+	/**
189
+	 * Get the tag number.
190
+	 *
191
+	 * @return int|string
192
+	 */
193
+	public function tag()
194
+	{
195
+		return $this->_tag;
196
+	}
197 197
     
198
-    /**
199
-     * Check whether type is of an universal class.
200
-     *
201
-     * @return boolean
202
-     */
203
-    public function isUniversal(): bool
204
-    {
205
-        return self::CLASS_UNIVERSAL == $this->_class;
206
-    }
198
+	/**
199
+	 * Check whether type is of an universal class.
200
+	 *
201
+	 * @return boolean
202
+	 */
203
+	public function isUniversal(): bool
204
+	{
205
+		return self::CLASS_UNIVERSAL == $this->_class;
206
+	}
207 207
     
208
-    /**
209
-     * Check whether type is of an application class.
210
-     *
211
-     * @return boolean
212
-     */
213
-    public function isApplication(): bool
214
-    {
215
-        return self::CLASS_APPLICATION == $this->_class;
216
-    }
208
+	/**
209
+	 * Check whether type is of an application class.
210
+	 *
211
+	 * @return boolean
212
+	 */
213
+	public function isApplication(): bool
214
+	{
215
+		return self::CLASS_APPLICATION == $this->_class;
216
+	}
217 217
     
218
-    /**
219
-     * Check whether type is of a context specific class.
220
-     *
221
-     * @return boolean
222
-     */
223
-    public function isContextSpecific(): bool
224
-    {
225
-        return self::CLASS_CONTEXT_SPECIFIC == $this->_class;
226
-    }
218
+	/**
219
+	 * Check whether type is of a context specific class.
220
+	 *
221
+	 * @return boolean
222
+	 */
223
+	public function isContextSpecific(): bool
224
+	{
225
+		return self::CLASS_CONTEXT_SPECIFIC == $this->_class;
226
+	}
227 227
     
228
-    /**
229
-     * Check whether type is of a private class.
230
-     *
231
-     * @return boolean
232
-     */
233
-    public function isPrivate(): bool
234
-    {
235
-        return self::CLASS_PRIVATE == $this->_class;
236
-    }
228
+	/**
229
+	 * Check whether type is of a private class.
230
+	 *
231
+	 * @return boolean
232
+	 */
233
+	public function isPrivate(): bool
234
+	{
235
+		return self::CLASS_PRIVATE == $this->_class;
236
+	}
237 237
     
238
-    /**
239
-     * Check whether content is primitive type.
240
-     *
241
-     * @return boolean
242
-     */
243
-    public function isPrimitive(): bool
244
-    {
245
-        return self::PRIMITIVE == $this->_pc;
246
-    }
238
+	/**
239
+	 * Check whether content is primitive type.
240
+	 *
241
+	 * @return boolean
242
+	 */
243
+	public function isPrimitive(): bool
244
+	{
245
+		return self::PRIMITIVE == $this->_pc;
246
+	}
247 247
     
248
-    /**
249
-     * Check hether content is constructed type.
250
-     *
251
-     * @return boolean
252
-     */
253
-    public function isConstructed(): bool
254
-    {
255
-        return self::CONSTRUCTED == $this->_pc;
256
-    }
248
+	/**
249
+	 * Check hether content is constructed type.
250
+	 *
251
+	 * @return boolean
252
+	 */
253
+	public function isConstructed(): bool
254
+	{
255
+		return self::CONSTRUCTED == $this->_pc;
256
+	}
257 257
     
258
-    /**
259
-     * Get self with given type class.
260
-     *
261
-     * @param int $class One of <code>CLASS_*</code> enumerations
262
-     * @return self
263
-     */
264
-    public function withClass(int $class): self
265
-    {
266
-        $obj = clone $this;
267
-        $obj->_class = $class;
268
-        return $obj;
269
-    }
258
+	/**
259
+	 * Get self with given type class.
260
+	 *
261
+	 * @param int $class One of <code>CLASS_*</code> enumerations
262
+	 * @return self
263
+	 */
264
+	public function withClass(int $class): self
265
+	{
266
+		$obj = clone $this;
267
+		$obj->_class = $class;
268
+		return $obj;
269
+	}
270 270
     
271
-    /**
272
-     * Get self with given type tag.
273
-     *
274
-     * @param int|string $tag Tag number
275
-     * @return self
276
-     */
277
-    public function withTag(int $tag): self
278
-    {
279
-        $obj = clone $this;
280
-        $obj->_tag = $tag;
281
-        return $obj;
282
-    }
271
+	/**
272
+	 * Get self with given type tag.
273
+	 *
274
+	 * @param int|string $tag Tag number
275
+	 * @return self
276
+	 */
277
+	public function withTag(int $tag): self
278
+	{
279
+		$obj = clone $this;
280
+		$obj->_tag = $tag;
281
+		return $obj;
282
+	}
283 283
     
284
-    /**
285
-     * Get human readable name of the type class.
286
-     *
287
-     * @param int $class
288
-     * @return string
289
-     */
290
-    public static function classToName(int $class): string
291
-    {
292
-        if (!array_key_exists($class, self::MAP_CLASS_TO_NAME)) {
293
-            return "CLASS $class";
294
-        }
295
-        return self::MAP_CLASS_TO_NAME[$class];
296
-    }
284
+	/**
285
+	 * Get human readable name of the type class.
286
+	 *
287
+	 * @param int $class
288
+	 * @return string
289
+	 */
290
+	public static function classToName(int $class): string
291
+	{
292
+		if (!array_key_exists($class, self::MAP_CLASS_TO_NAME)) {
293
+			return "CLASS $class";
294
+		}
295
+		return self::MAP_CLASS_TO_NAME[$class];
296
+	}
297 297
 }
Please login to merge, or discard this patch.
lib/ASN1/DERData.php 1 patch
Indentation   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -14,82 +14,82 @@
 block discarded – undo
14 14
  */
15 15
 class DERData extends Element
16 16
 {
17
-    /**
18
-     * DER encoded data.
19
-     *
20
-     * @var string $_der
21
-     */
22
-    protected $_der;
17
+	/**
18
+	 * DER encoded data.
19
+	 *
20
+	 * @var string $_der
21
+	 */
22
+	protected $_der;
23 23
     
24
-    /**
25
-     * Identifier of the underlying type.
26
-     *
27
-     * @var Identifier $_identifier
28
-     */
29
-    protected $_identifier;
24
+	/**
25
+	 * Identifier of the underlying type.
26
+	 *
27
+	 * @var Identifier $_identifier
28
+	 */
29
+	protected $_identifier;
30 30
     
31
-    /**
32
-     * Offset to the content in DER data.
33
-     *
34
-     * @var int $_contentOffset
35
-     */
36
-    protected $_contentOffset = 0;
31
+	/**
32
+	 * Offset to the content in DER data.
33
+	 *
34
+	 * @var int $_contentOffset
35
+	 */
36
+	protected $_contentOffset = 0;
37 37
     
38
-    /**
39
-     * Constructor.
40
-     *
41
-     * @param string $data DER encoded data
42
-     * @throws \ASN1\Exception\DecodeException If data does not adhere to DER
43
-     */
44
-    public function __construct(string $data)
45
-    {
46
-        $this->_identifier = Identifier::fromDER($data, $this->_contentOffset);
47
-        Length::expectFromDER($data, $this->_contentOffset);
48
-        $this->_der = $data;
49
-        $this->_typeTag = intval($this->_identifier->tag());
50
-    }
38
+	/**
39
+	 * Constructor.
40
+	 *
41
+	 * @param string $data DER encoded data
42
+	 * @throws \ASN1\Exception\DecodeException If data does not adhere to DER
43
+	 */
44
+	public function __construct(string $data)
45
+	{
46
+		$this->_identifier = Identifier::fromDER($data, $this->_contentOffset);
47
+		Length::expectFromDER($data, $this->_contentOffset);
48
+		$this->_der = $data;
49
+		$this->_typeTag = intval($this->_identifier->tag());
50
+	}
51 51
     
52
-    /**
53
-     *
54
-     * @see \ASN1\Element::typeClass()
55
-     * @return int
56
-     */
57
-    public function typeClass(): int
58
-    {
59
-        return $this->_identifier->typeClass();
60
-    }
52
+	/**
53
+	 *
54
+	 * @see \ASN1\Element::typeClass()
55
+	 * @return int
56
+	 */
57
+	public function typeClass(): int
58
+	{
59
+		return $this->_identifier->typeClass();
60
+	}
61 61
     
62
-    /**
63
-     *
64
-     * @see \ASN1\Element::isConstructed()
65
-     * @return bool
66
-     */
67
-    public function isConstructed(): bool
68
-    {
69
-        return $this->_identifier->isConstructed();
70
-    }
62
+	/**
63
+	 *
64
+	 * @see \ASN1\Element::isConstructed()
65
+	 * @return bool
66
+	 */
67
+	public function isConstructed(): bool
68
+	{
69
+		return $this->_identifier->isConstructed();
70
+	}
71 71
     
72
-    /**
73
-     *
74
-     * @see \ASN1\Element::_encodedContentDER()
75
-     * @return string
76
-     */
77
-    protected function _encodedContentDER(): string
78
-    {
79
-        // if there's no content payload
80
-        if (strlen($this->_der) == $this->_contentOffset) {
81
-            return "";
82
-        }
83
-        return substr($this->_der, $this->_contentOffset);
84
-    }
72
+	/**
73
+	 *
74
+	 * @see \ASN1\Element::_encodedContentDER()
75
+	 * @return string
76
+	 */
77
+	protected function _encodedContentDER(): string
78
+	{
79
+		// if there's no content payload
80
+		if (strlen($this->_der) == $this->_contentOffset) {
81
+			return "";
82
+		}
83
+		return substr($this->_der, $this->_contentOffset);
84
+	}
85 85
     
86
-    /**
87
-     *
88
-     * @see \ASN1\Element::toDER()
89
-     * @return string
90
-     */
91
-    public function toDER(): string
92
-    {
93
-        return $this->_der;
94
-    }
86
+	/**
87
+	 *
88
+	 * @see \ASN1\Element::toDER()
89
+	 * @return string
90
+	 */
91
+	public function toDER(): string
92
+	{
93
+		return $this->_der;
94
+	}
95 95
 }
Please login to merge, or discard this patch.
lib/ASN1/Element.php 1 patch
Indentation   +411 added lines, -411 removed lines patch added patch discarded remove patch
@@ -20,439 +20,439 @@
 block discarded – undo
20 20
  */
21 21
 abstract class Element implements ElementBase
22 22
 {
23
-    // Universal type tags
24
-    const TYPE_EOC = 0x00;
25
-    const TYPE_BOOLEAN = 0x01;
26
-    const TYPE_INTEGER = 0x02;
27
-    const TYPE_BIT_STRING = 0x03;
28
-    const TYPE_OCTET_STRING = 0x04;
29
-    const TYPE_NULL = 0x05;
30
-    const TYPE_OBJECT_IDENTIFIER = 0x06;
31
-    const TYPE_OBJECT_DESCRIPTOR = 0x07;
32
-    const TYPE_EXTERNAL = 0x08;
33
-    const TYPE_REAL = 0x09;
34
-    const TYPE_ENUMERATED = 0x0a;
35
-    const TYPE_EMBEDDED_PDV = 0x0b;
36
-    const TYPE_UTF8_STRING = 0x0c;
37
-    const TYPE_RELATIVE_OID = 0x0d;
38
-    const TYPE_SEQUENCE = 0x10;
39
-    const TYPE_SET = 0x11;
40
-    const TYPE_NUMERIC_STRING = 0x12;
41
-    const TYPE_PRINTABLE_STRING = 0x13;
42
-    const TYPE_T61_STRING = 0x14;
43
-    const TYPE_VIDEOTEX_STRING = 0x15;
44
-    const TYPE_IA5_STRING = 0x16;
45
-    const TYPE_UTC_TIME = 0x17;
46
-    const TYPE_GENERALIZED_TIME = 0x18;
47
-    const TYPE_GRAPHIC_STRING = 0x19;
48
-    const TYPE_VISIBLE_STRING = 0x1a;
49
-    const TYPE_GENERAL_STRING = 0x1b;
50
-    const TYPE_UNIVERSAL_STRING = 0x1c;
51
-    const TYPE_CHARACTER_STRING = 0x1d;
52
-    const TYPE_BMP_STRING = 0x1e;
23
+	// Universal type tags
24
+	const TYPE_EOC = 0x00;
25
+	const TYPE_BOOLEAN = 0x01;
26
+	const TYPE_INTEGER = 0x02;
27
+	const TYPE_BIT_STRING = 0x03;
28
+	const TYPE_OCTET_STRING = 0x04;
29
+	const TYPE_NULL = 0x05;
30
+	const TYPE_OBJECT_IDENTIFIER = 0x06;
31
+	const TYPE_OBJECT_DESCRIPTOR = 0x07;
32
+	const TYPE_EXTERNAL = 0x08;
33
+	const TYPE_REAL = 0x09;
34
+	const TYPE_ENUMERATED = 0x0a;
35
+	const TYPE_EMBEDDED_PDV = 0x0b;
36
+	const TYPE_UTF8_STRING = 0x0c;
37
+	const TYPE_RELATIVE_OID = 0x0d;
38
+	const TYPE_SEQUENCE = 0x10;
39
+	const TYPE_SET = 0x11;
40
+	const TYPE_NUMERIC_STRING = 0x12;
41
+	const TYPE_PRINTABLE_STRING = 0x13;
42
+	const TYPE_T61_STRING = 0x14;
43
+	const TYPE_VIDEOTEX_STRING = 0x15;
44
+	const TYPE_IA5_STRING = 0x16;
45
+	const TYPE_UTC_TIME = 0x17;
46
+	const TYPE_GENERALIZED_TIME = 0x18;
47
+	const TYPE_GRAPHIC_STRING = 0x19;
48
+	const TYPE_VISIBLE_STRING = 0x1a;
49
+	const TYPE_GENERAL_STRING = 0x1b;
50
+	const TYPE_UNIVERSAL_STRING = 0x1c;
51
+	const TYPE_CHARACTER_STRING = 0x1d;
52
+	const TYPE_BMP_STRING = 0x1e;
53 53
     
54
-    /**
55
-     * Mapping from universal type tag to implementation class name.
56
-     *
57
-     * @internal
58
-     *
59
-     * @var array
60
-     */
61
-    const MAP_TAG_TO_CLASS = [
62
-        /* @formatter:off */
63
-        self::TYPE_BOOLEAN => Primitive\Boolean::class,
64
-        self::TYPE_INTEGER => Primitive\Integer::class,
65
-        self::TYPE_BIT_STRING => Primitive\BitString::class,
66
-        self::TYPE_OCTET_STRING => Primitive\OctetString::class,
67
-        self::TYPE_NULL => Primitive\NullType::class,
68
-        self::TYPE_OBJECT_IDENTIFIER => Primitive\ObjectIdentifier::class,
69
-        self::TYPE_OBJECT_DESCRIPTOR => Primitive\ObjectDescriptor::class,
70
-        self::TYPE_REAL => Primitive\Real::class,
71
-        self::TYPE_ENUMERATED => Primitive\Enumerated::class,
72
-        self::TYPE_UTF8_STRING => Primitive\UTF8String::class,
73
-        self::TYPE_RELATIVE_OID => Primitive\RelativeOID::class,
74
-        self::TYPE_SEQUENCE => Constructed\Sequence::class,
75
-        self::TYPE_SET => Constructed\Set::class,
76
-        self::TYPE_NUMERIC_STRING => Primitive\NumericString::class,
77
-        self::TYPE_PRINTABLE_STRING => Primitive\PrintableString::class,
78
-        self::TYPE_T61_STRING => Primitive\T61String::class,
79
-        self::TYPE_VIDEOTEX_STRING => Primitive\VideotexString::class,
80
-        self::TYPE_IA5_STRING => Primitive\IA5String::class,
81
-        self::TYPE_UTC_TIME => Primitive\UTCTime::class,
82
-        self::TYPE_GENERALIZED_TIME => Primitive\GeneralizedTime::class,
83
-        self::TYPE_GRAPHIC_STRING => Primitive\GraphicString::class,
84
-        self::TYPE_VISIBLE_STRING => Primitive\VisibleString::class,
85
-        self::TYPE_GENERAL_STRING => Primitive\GeneralString::class,
86
-        self::TYPE_UNIVERSAL_STRING => Primitive\UniversalString::class,
87
-        self::TYPE_CHARACTER_STRING => Primitive\CharacterString::class,
88
-        self::TYPE_BMP_STRING => Primitive\BMPString::class,
89
-        /* @formatter:on */
90
-    ];
54
+	/**
55
+	 * Mapping from universal type tag to implementation class name.
56
+	 *
57
+	 * @internal
58
+	 *
59
+	 * @var array
60
+	 */
61
+	const MAP_TAG_TO_CLASS = [
62
+		/* @formatter:off */
63
+		self::TYPE_BOOLEAN => Primitive\Boolean::class,
64
+		self::TYPE_INTEGER => Primitive\Integer::class,
65
+		self::TYPE_BIT_STRING => Primitive\BitString::class,
66
+		self::TYPE_OCTET_STRING => Primitive\OctetString::class,
67
+		self::TYPE_NULL => Primitive\NullType::class,
68
+		self::TYPE_OBJECT_IDENTIFIER => Primitive\ObjectIdentifier::class,
69
+		self::TYPE_OBJECT_DESCRIPTOR => Primitive\ObjectDescriptor::class,
70
+		self::TYPE_REAL => Primitive\Real::class,
71
+		self::TYPE_ENUMERATED => Primitive\Enumerated::class,
72
+		self::TYPE_UTF8_STRING => Primitive\UTF8String::class,
73
+		self::TYPE_RELATIVE_OID => Primitive\RelativeOID::class,
74
+		self::TYPE_SEQUENCE => Constructed\Sequence::class,
75
+		self::TYPE_SET => Constructed\Set::class,
76
+		self::TYPE_NUMERIC_STRING => Primitive\NumericString::class,
77
+		self::TYPE_PRINTABLE_STRING => Primitive\PrintableString::class,
78
+		self::TYPE_T61_STRING => Primitive\T61String::class,
79
+		self::TYPE_VIDEOTEX_STRING => Primitive\VideotexString::class,
80
+		self::TYPE_IA5_STRING => Primitive\IA5String::class,
81
+		self::TYPE_UTC_TIME => Primitive\UTCTime::class,
82
+		self::TYPE_GENERALIZED_TIME => Primitive\GeneralizedTime::class,
83
+		self::TYPE_GRAPHIC_STRING => Primitive\GraphicString::class,
84
+		self::TYPE_VISIBLE_STRING => Primitive\VisibleString::class,
85
+		self::TYPE_GENERAL_STRING => Primitive\GeneralString::class,
86
+		self::TYPE_UNIVERSAL_STRING => Primitive\UniversalString::class,
87
+		self::TYPE_CHARACTER_STRING => Primitive\CharacterString::class,
88
+		self::TYPE_BMP_STRING => Primitive\BMPString::class,
89
+		/* @formatter:on */
90
+	];
91 91
     
92
-    /**
93
-     * Pseudotype for all string types.
94
-     *
95
-     * May be used as an expectation parameter.
96
-     *
97
-     * @var int
98
-     */
99
-    const TYPE_STRING = -1;
92
+	/**
93
+	 * Pseudotype for all string types.
94
+	 *
95
+	 * May be used as an expectation parameter.
96
+	 *
97
+	 * @var int
98
+	 */
99
+	const TYPE_STRING = -1;
100 100
     
101
-    /**
102
-     * Pseudotype for all time types.
103
-     *
104
-     * May be used as an expectation parameter.
105
-     *
106
-     * @var int
107
-     */
108
-    const TYPE_TIME = -2;
101
+	/**
102
+	 * Pseudotype for all time types.
103
+	 *
104
+	 * May be used as an expectation parameter.
105
+	 *
106
+	 * @var int
107
+	 */
108
+	const TYPE_TIME = -2;
109 109
     
110
-    /**
111
-     * Mapping from universal type tag to human readable name.
112
-     *
113
-     * @internal
114
-     *
115
-     * @var array
116
-     */
117
-    const MAP_TYPE_TO_NAME = array(
118
-        /* @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
-    );
110
+	/**
111
+	 * Mapping from universal type tag to human readable name.
112
+	 *
113
+	 * @internal
114
+	 *
115
+	 * @var array
116
+	 */
117
+	const MAP_TYPE_TO_NAME = array(
118
+		/* @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();
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();
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)
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)
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 self
212
-     */
213
-    public static function fromDER(string $data, int &$offset = null)
214
-    {
215
-        // decode identifier
216
-        $idx = $offset ? $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->tag())), 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 (__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 self
212
+	 */
213
+	public static function fromDER(string $data, int &$offset = null)
214
+	{
215
+		// decode identifier
216
+		$idx = $offset ? $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->tag())), 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 (__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()
267
-    {
268
-        return $this->_typeTag;
269
-    }
261
+	/**
262
+	 *
263
+	 * @see \ASN1\Feature\ElementBase::tag()
264
+	 * @return int
265
+	 */
266
+	public function tag()
267
+	{
268
+		return $this->_typeTag;
269
+	}
270 270
     
271
-    /**
272
-     *
273
-     * @see \ASN1\Feature\ElementBase::isType()
274
-     * @return bool
275
-     */
276
-    public function isType($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($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($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($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($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($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($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($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
-        // tagged type
401
-        if ($identifier->isContextSpecific()) {
402
-            return TaggedType::class;
403
-        }
404
-        // universal class
405
-        if ($identifier->isUniversal()) {
406
-            return self::_determineUniversalImplClass(
407
-                intval($identifier->tag()));
408
-        }
409
-        throw new \UnexpectedValueException(
410
-            sprintf("%s %d not implemented.",
411
-                Identifier::classToName($identifier->typeClass()),
412
-                $identifier->tag()));
413
-    }
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
+		// tagged type
401
+		if ($identifier->isContextSpecific()) {
402
+			return TaggedType::class;
403
+		}
404
+		// universal class
405
+		if ($identifier->isUniversal()) {
406
+			return self::_determineUniversalImplClass(
407
+				intval($identifier->tag()));
408
+		}
409
+		throw new \UnexpectedValueException(
410
+			sprintf("%s %d not implemented.",
411
+				Identifier::classToName($identifier->typeClass()),
412
+				$identifier->tag()));
413
+	}
414 414
     
415
-    /**
416
-     * Determine the class that implements an universal type of the given tag.
417
-     *
418
-     * @param int $tag
419
-     * @throws \UnexpectedValueException
420
-     * @return string Class name
421
-     */
422
-    protected static function _determineUniversalImplClass($tag): string
423
-    {
424
-        if (!array_key_exists($tag, self::MAP_TAG_TO_CLASS)) {
425
-            throw new \UnexpectedValueException(
426
-                "Universal tag $tag not implemented.");
427
-        }
428
-        return self::MAP_TAG_TO_CLASS[$tag];
429
-    }
415
+	/**
416
+	 * Determine the class that implements an universal type of the given tag.
417
+	 *
418
+	 * @param int $tag
419
+	 * @throws \UnexpectedValueException
420
+	 * @return string Class name
421
+	 */
422
+	protected static function _determineUniversalImplClass($tag): string
423
+	{
424
+		if (!array_key_exists($tag, self::MAP_TAG_TO_CLASS)) {
425
+			throw new \UnexpectedValueException(
426
+				"Universal tag $tag not implemented.");
427
+		}
428
+		return self::MAP_TAG_TO_CLASS[$tag];
429
+	}
430 430
     
431
-    /**
432
-     * Get textual description of the type for debugging purposes.
433
-     *
434
-     * @return string
435
-     */
436
-    protected function _typeDescriptorString(): string
437
-    {
438
-        if ($this->typeClass() == Identifier::CLASS_UNIVERSAL) {
439
-            return self::tagToName($this->_typeTag);
440
-        }
441
-        return sprintf("%s TAG %d", Identifier::classToName($this->typeClass()),
442
-            $this->_typeTag);
443
-    }
431
+	/**
432
+	 * Get textual description of the type for debugging purposes.
433
+	 *
434
+	 * @return string
435
+	 */
436
+	protected function _typeDescriptorString(): string
437
+	{
438
+		if ($this->typeClass() == Identifier::CLASS_UNIVERSAL) {
439
+			return self::tagToName($this->_typeTag);
440
+		}
441
+		return sprintf("%s TAG %d", Identifier::classToName($this->typeClass()),
442
+			$this->_typeTag);
443
+	}
444 444
     
445
-    /**
446
-     * Get human readable name for an universal tag.
447
-     *
448
-     * @param int $tag
449
-     * @return string
450
-     */
451
-    public static function tagToName($tag): string
452
-    {
453
-        if (!array_key_exists($tag, self::MAP_TYPE_TO_NAME)) {
454
-            return "TAG $tag";
455
-        }
456
-        return self::MAP_TYPE_TO_NAME[$tag];
457
-    }
445
+	/**
446
+	 * Get human readable name for an universal tag.
447
+	 *
448
+	 * @param int $tag
449
+	 * @return string
450
+	 */
451
+	public static function tagToName($tag): string
452
+	{
453
+		if (!array_key_exists($tag, self::MAP_TYPE_TO_NAME)) {
454
+			return "TAG $tag";
455
+		}
456
+		return self::MAP_TYPE_TO_NAME[$tag];
457
+	}
458 458
 }
Please login to merge, or discard this patch.
lib/ASN1/Util/Flags.php 1 patch
Indentation   +119 added lines, -119 removed lines patch added patch discarded remove patch
@@ -11,130 +11,130 @@
 block discarded – undo
11 11
  */
12 12
 class Flags
13 13
 {
14
-    /**
15
-     * Flag octets.
16
-     *
17
-     * @var string $_flags
18
-     */
19
-    protected $_flags;
14
+	/**
15
+	 * Flag octets.
16
+	 *
17
+	 * @var string $_flags
18
+	 */
19
+	protected $_flags;
20 20
     
21
-    /**
22
-     * Number of flags.
23
-     *
24
-     * @var int $_width
25
-     */
26
-    protected $_width;
21
+	/**
22
+	 * Number of flags.
23
+	 *
24
+	 * @var int $_width
25
+	 */
26
+	protected $_width;
27 27
     
28
-    /**
29
-     * Constructor.
30
-     *
31
-     * @param number $flags Flags
32
-     * @param int $width The number of flags. If width is larger than number of
33
-     *        bits in $flags, zeroes are prepended to flag field.
34
-     */
35
-    public function __construct($flags, int $width)
36
-    {
37
-        if (!$width) {
38
-            $this->_flags = "";
39
-        } else {
40
-            // calculate number of unused bits in last octet
41
-            $last_octet_bits = $width % 8;
42
-            $unused_bits = $last_octet_bits ? 8 - $last_octet_bits : 0;
43
-            $num = gmp_init($flags);
44
-            // mask bits outside bitfield width
45
-            $mask = gmp_sub(gmp_init(1) << $width, 1);
46
-            $num &= $mask;
47
-            // shift towards MSB if needed
48
-            $data = gmp_export($num << $unused_bits, 1,
49
-                GMP_MSW_FIRST | GMP_BIG_ENDIAN);
50
-            $octets = unpack("C*", $data);
51
-            $bits = count($octets) * 8;
52
-            // pad with zeroes
53
-            while ($bits < $width) {
54
-                array_unshift($octets, 0);
55
-                $bits += 8;
56
-            }
57
-            $this->_flags = pack("C*", ...$octets);
58
-        }
59
-        $this->_width = $width;
60
-    }
28
+	/**
29
+	 * Constructor.
30
+	 *
31
+	 * @param number $flags Flags
32
+	 * @param int $width The number of flags. If width is larger than number of
33
+	 *        bits in $flags, zeroes are prepended to flag field.
34
+	 */
35
+	public function __construct($flags, int $width)
36
+	{
37
+		if (!$width) {
38
+			$this->_flags = "";
39
+		} else {
40
+			// calculate number of unused bits in last octet
41
+			$last_octet_bits = $width % 8;
42
+			$unused_bits = $last_octet_bits ? 8 - $last_octet_bits : 0;
43
+			$num = gmp_init($flags);
44
+			// mask bits outside bitfield width
45
+			$mask = gmp_sub(gmp_init(1) << $width, 1);
46
+			$num &= $mask;
47
+			// shift towards MSB if needed
48
+			$data = gmp_export($num << $unused_bits, 1,
49
+				GMP_MSW_FIRST | GMP_BIG_ENDIAN);
50
+			$octets = unpack("C*", $data);
51
+			$bits = count($octets) * 8;
52
+			// pad with zeroes
53
+			while ($bits < $width) {
54
+				array_unshift($octets, 0);
55
+				$bits += 8;
56
+			}
57
+			$this->_flags = pack("C*", ...$octets);
58
+		}
59
+		$this->_width = $width;
60
+	}
61 61
     
62
-    /**
63
-     * Initialize from BitString.
64
-     *
65
-     * @param BitString $bs
66
-     * @param int $width
67
-     * @return self
68
-     */
69
-    public static function fromBitString(BitString $bs, int $width)
70
-    {
71
-        $num_bits = $bs->numBits();
72
-        $num = gmp_import($bs->string(), 1, GMP_MSW_FIRST | GMP_BIG_ENDIAN);
73
-        $num >>= $bs->unusedBits();
74
-        if ($num_bits < $width) {
75
-            $num <<= ($width - $num_bits);
76
-        }
77
-        return new self(gmp_strval($num, 10), $width);
78
-    }
62
+	/**
63
+	 * Initialize from BitString.
64
+	 *
65
+	 * @param BitString $bs
66
+	 * @param int $width
67
+	 * @return self
68
+	 */
69
+	public static function fromBitString(BitString $bs, int $width)
70
+	{
71
+		$num_bits = $bs->numBits();
72
+		$num = gmp_import($bs->string(), 1, GMP_MSW_FIRST | GMP_BIG_ENDIAN);
73
+		$num >>= $bs->unusedBits();
74
+		if ($num_bits < $width) {
75
+			$num <<= ($width - $num_bits);
76
+		}
77
+		return new self(gmp_strval($num, 10), $width);
78
+	}
79 79
     
80
-    /**
81
-     * Check whether a bit at given index is set.
82
-     * Index 0 is the leftmost bit.
83
-     *
84
-     * @param int $idx
85
-     * @throws \OutOfBoundsException
86
-     * @return bool
87
-     */
88
-    public function test(int $idx)
89
-    {
90
-        if ($idx >= $this->_width) {
91
-            throw new \OutOfBoundsException("Index is out of bounds.");
92
-        }
93
-        // octet index
94
-        $oi = (int) floor($idx / 8);
95
-        $byte = $this->_flags[$oi];
96
-        // bit index
97
-        $bi = $idx % 8;
98
-        // index 0 is the most significant bit in byte
99
-        $mask = 0x01 << (7 - $bi);
100
-        return (ord($byte) & $mask) > 0;
101
-    }
80
+	/**
81
+	 * Check whether a bit at given index is set.
82
+	 * Index 0 is the leftmost bit.
83
+	 *
84
+	 * @param int $idx
85
+	 * @throws \OutOfBoundsException
86
+	 * @return bool
87
+	 */
88
+	public function test(int $idx)
89
+	{
90
+		if ($idx >= $this->_width) {
91
+			throw new \OutOfBoundsException("Index is out of bounds.");
92
+		}
93
+		// octet index
94
+		$oi = (int) floor($idx / 8);
95
+		$byte = $this->_flags[$oi];
96
+		// bit index
97
+		$bi = $idx % 8;
98
+		// index 0 is the most significant bit in byte
99
+		$mask = 0x01 << (7 - $bi);
100
+		return (ord($byte) & $mask) > 0;
101
+	}
102 102
     
103
-    /**
104
-     * Get flags as an octet string.
105
-     * Zeroes are appended to the last octet if width is not divisible by 8.
106
-     *
107
-     * @return string
108
-     */
109
-    public function string(): string
110
-    {
111
-        return $this->_flags;
112
-    }
103
+	/**
104
+	 * Get flags as an octet string.
105
+	 * Zeroes are appended to the last octet if width is not divisible by 8.
106
+	 *
107
+	 * @return string
108
+	 */
109
+	public function string(): string
110
+	{
111
+		return $this->_flags;
112
+	}
113 113
     
114
-    /**
115
-     * Get flags as a base 10 integer.
116
-     *
117
-     * @return int|string
118
-     */
119
-    public function number()
120
-    {
121
-        $num = gmp_import($this->_flags, 1, GMP_MSW_FIRST | GMP_BIG_ENDIAN);
122
-        $last_octet_bits = $this->_width % 8;
123
-        $unused_bits = $last_octet_bits ? 8 - $last_octet_bits : 0;
124
-        $num >>= $unused_bits;
125
-        return gmp_strval($num, 10);
126
-    }
114
+	/**
115
+	 * Get flags as a base 10 integer.
116
+	 *
117
+	 * @return int|string
118
+	 */
119
+	public function number()
120
+	{
121
+		$num = gmp_import($this->_flags, 1, GMP_MSW_FIRST | GMP_BIG_ENDIAN);
122
+		$last_octet_bits = $this->_width % 8;
123
+		$unused_bits = $last_octet_bits ? 8 - $last_octet_bits : 0;
124
+		$num >>= $unused_bits;
125
+		return gmp_strval($num, 10);
126
+	}
127 127
     
128
-    /**
129
-     * Get flags as a BitString.
130
-     * Unused bits are set accordingly. Trailing zeroes are not stripped.
131
-     *
132
-     * @return BitString
133
-     */
134
-    public function bitString(): BitString
135
-    {
136
-        $last_octet_bits = $this->_width % 8;
137
-        $unused_bits = $last_octet_bits ? 8 - $last_octet_bits : 0;
138
-        return new BitString($this->_flags, $unused_bits);
139
-    }
128
+	/**
129
+	 * Get flags as a BitString.
130
+	 * Unused bits are set accordingly. Trailing zeroes are not stripped.
131
+	 *
132
+	 * @return BitString
133
+	 */
134
+	public function bitString(): BitString
135
+	{
136
+		$last_octet_bits = $this->_width % 8;
137
+		$unused_bits = $last_octet_bits ? 8 - $last_octet_bits : 0;
138
+		return new BitString($this->_flags, $unused_bits);
139
+	}
140 140
 }
Please login to merge, or discard this patch.
lib/ASN1/Type/StringType.php 1 patch
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -11,48 +11,48 @@
 block discarded – undo
11 11
  */
12 12
 abstract class StringType extends Element
13 13
 {
14
-    /**
15
-     * String value.
16
-     *
17
-     * @var string $_string
18
-     */
19
-    protected $_string;
14
+	/**
15
+	 * String value.
16
+	 *
17
+	 * @var string $_string
18
+	 */
19
+	protected $_string;
20 20
     
21
-    /**
22
-     * Constructor.
23
-     *
24
-     * @param string $string
25
-     * @throws \InvalidArgumentException
26
-     */
27
-    public function __construct(string $string)
28
-    {
29
-        if (!$this->_validateString($string)) {
30
-            throw new \InvalidArgumentException(
31
-                sprintf("Not a valid %s string.",
32
-                    self::tagToName($this->_typeTag)));
33
-        }
34
-        $this->_string = $string;
35
-    }
21
+	/**
22
+	 * Constructor.
23
+	 *
24
+	 * @param string $string
25
+	 * @throws \InvalidArgumentException
26
+	 */
27
+	public function __construct(string $string)
28
+	{
29
+		if (!$this->_validateString($string)) {
30
+			throw new \InvalidArgumentException(
31
+				sprintf("Not a valid %s string.",
32
+					self::tagToName($this->_typeTag)));
33
+		}
34
+		$this->_string = $string;
35
+	}
36 36
     
37
-    /**
38
-     * Get the string value.
39
-     *
40
-     * @return string
41
-     */
42
-    public function string()
43
-    {
44
-        return $this->_string;
45
-    }
37
+	/**
38
+	 * Get the string value.
39
+	 *
40
+	 * @return string
41
+	 */
42
+	public function string()
43
+	{
44
+		return $this->_string;
45
+	}
46 46
     
47
-    /**
48
-     * Check whether string is valid for the concrete type.
49
-     *
50
-     * @param string $string
51
-     * @return bool
52
-     */
53
-    protected function _validateString(string $string): bool
54
-    {
55
-        // Override in derived classes
56
-        return true;
57
-    }
47
+	/**
48
+	 * Check whether string is valid for the concrete type.
49
+	 *
50
+	 * @param string $string
51
+	 * @return bool
52
+	 */
53
+	protected function _validateString(string $string): bool
54
+	{
55
+		// Override in derived classes
56
+		return true;
57
+	}
58 58
 }
Please login to merge, or discard this patch.
lib/ASN1/Type/Structure.php 1 patch
Indentation   +309 added lines, -309 removed lines patch added patch discarded remove patch
@@ -13,335 +13,335 @@
 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 Element[] $elements Any number of elements
46
-     */
47
-    public function __construct(Element ...$elements)
48
-    {
49
-        $this->_elements = $elements;
50
-    }
42
+	/**
43
+	 * Constructor.
44
+	 *
45
+	 * @param Element[] $elements Any number of elements
46
+	 */
47
+	public function __construct(Element ...$elements)
48
+	{
49
+		$this->_elements = $elements;
50
+	}
51 51
     
52
-    /**
53
-     * Clone magic method.
54
-     */
55
-    public function __clone()
56
-    {
57
-        // clear cache-variables
58
-        $this->_taggedMap = null;
59
-        $this->_unspecifiedTypes = null;
60
-    }
52
+	/**
53
+	 * Clone magic method.
54
+	 */
55
+	public function __clone()
56
+	{
57
+		// clear cache-variables
58
+		$this->_taggedMap = null;
59
+		$this->_unspecifiedTypes = null;
60
+	}
61 61
     
62
-    /**
63
-     *
64
-     * @see \ASN1\Element::isConstructed()
65
-     * @return bool
66
-     */
67
-    public function isConstructed(): bool
68
-    {
69
-        return true;
70
-    }
62
+	/**
63
+	 *
64
+	 * @see \ASN1\Element::isConstructed()
65
+	 * @return bool
66
+	 */
67
+	public function isConstructed(): bool
68
+	{
69
+		return true;
70
+	}
71 71
     
72
-    /**
73
-     *
74
-     * @see \ASN1\Element::_encodedContentDER()
75
-     * @return string
76
-     */
77
-    protected function _encodedContentDER(): string
78
-    {
79
-        $data = "";
80
-        foreach ($this->_elements as $element) {
81
-            $data .= $element->toDER();
82
-        }
83
-        return $data;
84
-    }
72
+	/**
73
+	 *
74
+	 * @see \ASN1\Element::_encodedContentDER()
75
+	 * @return string
76
+	 */
77
+	protected function _encodedContentDER(): string
78
+	{
79
+		$data = "";
80
+		foreach ($this->_elements as $element) {
81
+			$data .= $element->toDER();
82
+		}
83
+		return $data;
84
+	}
85 85
     
86
-    /**
87
-     *
88
-     * @see \ASN1\Element::_decodeFromDER()
89
-     * @return self
90
-     */
91
-    protected static function _decodeFromDER(Identifier $identifier, string $data,
92
-        int &$offset)
93
-    {
94
-        $idx = $offset;
95
-        if (!$identifier->isConstructed()) {
96
-            throw new DecodeException(
97
-                "Structured element must have constructed bit set.");
98
-        }
99
-        $length = Length::expectFromDER($data, $idx);
100
-        $end = $idx + $length->length();
101
-        $elements = [];
102
-        while ($idx < $end) {
103
-            $elements[] = Element::fromDER($data, $idx);
104
-            // check that element didn't overflow length
105
-            if ($idx > $end) {
106
-                throw new DecodeException(
107
-                    "Structure's content overflows length.");
108
-            }
109
-        }
110
-        $offset = $idx;
111
-        // return instance by static late binding
112
-        return new static(...$elements);
113
-    }
86
+	/**
87
+	 *
88
+	 * @see \ASN1\Element::_decodeFromDER()
89
+	 * @return self
90
+	 */
91
+	protected static function _decodeFromDER(Identifier $identifier, string $data,
92
+		int &$offset)
93
+	{
94
+		$idx = $offset;
95
+		if (!$identifier->isConstructed()) {
96
+			throw new DecodeException(
97
+				"Structured element must have constructed bit set.");
98
+		}
99
+		$length = Length::expectFromDER($data, $idx);
100
+		$end = $idx + $length->length();
101
+		$elements = [];
102
+		while ($idx < $end) {
103
+			$elements[] = Element::fromDER($data, $idx);
104
+			// check that element didn't overflow length
105
+			if ($idx > $end) {
106
+				throw new DecodeException(
107
+					"Structure's content overflows length.");
108
+			}
109
+		}
110
+		$offset = $idx;
111
+		// return instance by static late binding
112
+		return new static(...$elements);
113
+	}
114 114
     
115
-    /**
116
-     * Explode DER structure to DER encoded components that it contains.
117
-     *
118
-     * @param string $data
119
-     * @throws DecodeException
120
-     * @return string[]
121
-     */
122
-    public static function explodeDER(string $data): array
123
-    {
124
-        $offset = 0;
125
-        $identifier = Identifier::fromDER($data, $offset);
126
-        if (!$identifier->isConstructed()) {
127
-            throw new DecodeException("Element is not constructed.");
128
-        }
129
-        $length = Length::expectFromDER($data, $offset);
130
-        $end = $offset + $length->length();
131
-        $parts = [];
132
-        while ($offset < $end) {
133
-            // start of the element
134
-            $idx = $offset;
135
-            // skip identifier
136
-            Identifier::fromDER($data, $offset);
137
-            // decode element length
138
-            $length = Length::expectFromDER($data, $offset);
139
-            // extract der encoding of the element
140
-            $parts[] = substr($data, $idx, $offset - $idx + $length->length());
141
-            // update offset over content
142
-            $offset += $length->length();
143
-        }
144
-        return $parts;
145
-    }
115
+	/**
116
+	 * Explode DER structure to DER encoded components that it contains.
117
+	 *
118
+	 * @param string $data
119
+	 * @throws DecodeException
120
+	 * @return string[]
121
+	 */
122
+	public static function explodeDER(string $data): array
123
+	{
124
+		$offset = 0;
125
+		$identifier = Identifier::fromDER($data, $offset);
126
+		if (!$identifier->isConstructed()) {
127
+			throw new DecodeException("Element is not constructed.");
128
+		}
129
+		$length = Length::expectFromDER($data, $offset);
130
+		$end = $offset + $length->length();
131
+		$parts = [];
132
+		while ($offset < $end) {
133
+			// start of the element
134
+			$idx = $offset;
135
+			// skip identifier
136
+			Identifier::fromDER($data, $offset);
137
+			// decode element length
138
+			$length = Length::expectFromDER($data, $offset);
139
+			// extract der encoding of the element
140
+			$parts[] = substr($data, $idx, $offset - $idx + $length->length());
141
+			// update offset over content
142
+			$offset += $length->length();
143
+		}
144
+		return $parts;
145
+	}
146 146
     
147
-    /**
148
-     * Get self with an element at the given index replaced by another.
149
-     *
150
-     * @param int $idx Element index
151
-     * @param Element $el New element to insert into the structure
152
-     * @throws \OutOfBoundsException
153
-     * @return self
154
-     */
155
-    public function withReplaced(int $idx, Element $el)
156
-    {
157
-        if (!isset($this->_elements[$idx])) {
158
-            throw new \OutOfBoundsException(
159
-                "Structure doesn't have element at index $idx.");
160
-        }
161
-        $obj = clone $this;
162
-        $obj->_elements[$idx] = $el;
163
-        return $obj;
164
-    }
147
+	/**
148
+	 * Get self with an element at the given index replaced by another.
149
+	 *
150
+	 * @param int $idx Element index
151
+	 * @param Element $el New element to insert into the structure
152
+	 * @throws \OutOfBoundsException
153
+	 * @return self
154
+	 */
155
+	public function withReplaced(int $idx, Element $el)
156
+	{
157
+		if (!isset($this->_elements[$idx])) {
158
+			throw new \OutOfBoundsException(
159
+				"Structure doesn't have element at index $idx.");
160
+		}
161
+		$obj = clone $this;
162
+		$obj->_elements[$idx] = $el;
163
+		return $obj;
164
+	}
165 165
     
166
-    /**
167
-     * Get self with an element inserted before the given index.
168
-     *
169
-     * @param int $idx Element index
170
-     * @param Element $el New element to insert into the structure
171
-     * @throws \OutOfBoundsException
172
-     * @return self
173
-     */
174
-    public function withInserted(int $idx, Element $el)
175
-    {
176
-        if (count($this->_elements) < $idx || $idx < 0) {
177
-            throw new \OutOfBoundsException("Index $idx is out of bounds.");
178
-        }
179
-        $obj = clone $this;
180
-        array_splice($obj->_elements, $idx, 0, [$el]);
181
-        return $obj;
182
-    }
166
+	/**
167
+	 * Get self with an element inserted before the given index.
168
+	 *
169
+	 * @param int $idx Element index
170
+	 * @param Element $el New element to insert into the structure
171
+	 * @throws \OutOfBoundsException
172
+	 * @return self
173
+	 */
174
+	public function withInserted(int $idx, Element $el)
175
+	{
176
+		if (count($this->_elements) < $idx || $idx < 0) {
177
+			throw new \OutOfBoundsException("Index $idx is out of bounds.");
178
+		}
179
+		$obj = clone $this;
180
+		array_splice($obj->_elements, $idx, 0, [$el]);
181
+		return $obj;
182
+	}
183 183
     
184
-    /**
185
-     * Get self with an element appended to the end.
186
-     *
187
-     * @param Element $el Element to insert into the structure
188
-     * @return self
189
-     */
190
-    public function withAppended(Element $el)
191
-    {
192
-        $obj = clone $this;
193
-        array_push($obj->_elements, $el);
194
-        return $obj;
195
-    }
184
+	/**
185
+	 * Get self with an element appended to the end.
186
+	 *
187
+	 * @param Element $el Element to insert into the structure
188
+	 * @return self
189
+	 */
190
+	public function withAppended(Element $el)
191
+	{
192
+		$obj = clone $this;
193
+		array_push($obj->_elements, $el);
194
+		return $obj;
195
+	}
196 196
     
197
-    /**
198
-     * Get self with an element prepended in the beginning.
199
-     *
200
-     * @param Element $el Element to insert into the structure
201
-     * @return self
202
-     */
203
-    public function withPrepended(Element $el)
204
-    {
205
-        $obj = clone $this;
206
-        array_unshift($obj->_elements, $el);
207
-        return $obj;
208
-    }
197
+	/**
198
+	 * Get self with an element prepended in the beginning.
199
+	 *
200
+	 * @param Element $el Element to insert into the structure
201
+	 * @return self
202
+	 */
203
+	public function withPrepended(Element $el)
204
+	{
205
+		$obj = clone $this;
206
+		array_unshift($obj->_elements, $el);
207
+		return $obj;
208
+	}
209 209
     
210
-    /**
211
-     * Get self with an element at the given index removed.
212
-     *
213
-     * @param int $idx Element index
214
-     * @throws \OutOfBoundsException
215
-     * @return self
216
-     */
217
-    public function withoutElement($idx)
218
-    {
219
-        if (!isset($this->_elements[$idx])) {
220
-            throw new \OutOfBoundsException(
221
-                "Structure doesn't have element at index $idx.");
222
-        }
223
-        $obj = clone $this;
224
-        array_splice($obj->_elements, $idx, 1);
225
-        return $obj;
226
-    }
210
+	/**
211
+	 * Get self with an element at the given index removed.
212
+	 *
213
+	 * @param int $idx Element index
214
+	 * @throws \OutOfBoundsException
215
+	 * @return self
216
+	 */
217
+	public function withoutElement($idx)
218
+	{
219
+		if (!isset($this->_elements[$idx])) {
220
+			throw new \OutOfBoundsException(
221
+				"Structure doesn't have element at index $idx.");
222
+		}
223
+		$obj = clone $this;
224
+		array_splice($obj->_elements, $idx, 1);
225
+		return $obj;
226
+	}
227 227
     
228
-    /**
229
-     * Get elements in the structure.
230
-     *
231
-     * @return UnspecifiedType[]
232
-     */
233
-    public function elements(): array
234
-    {
235
-        if (!isset($this->_unspecifiedTypes)) {
236
-            $this->_unspecifiedTypes = array_map(
237
-                function (Element $el) {
238
-                    return new UnspecifiedType($el);
239
-                }, $this->_elements);
240
-        }
241
-        return $this->_unspecifiedTypes;
242
-    }
228
+	/**
229
+	 * Get elements in the structure.
230
+	 *
231
+	 * @return UnspecifiedType[]
232
+	 */
233
+	public function elements(): array
234
+	{
235
+		if (!isset($this->_unspecifiedTypes)) {
236
+			$this->_unspecifiedTypes = array_map(
237
+				function (Element $el) {
238
+					return new UnspecifiedType($el);
239
+				}, $this->_elements);
240
+		}
241
+		return $this->_unspecifiedTypes;
242
+	}
243 243
     
244
-    /**
245
-     * Check whether the structure has an element at the given index, optionally
246
-     * satisfying given tag expectation.
247
-     *
248
-     * @param int $idx Index 0..n
249
-     * @param int|null $expectedTag Optional type tag expectation
250
-     * @return bool
251
-     */
252
-    public function has(int $idx, $expectedTag = null): bool
253
-    {
254
-        if (!isset($this->_elements[$idx])) {
255
-            return false;
256
-        }
257
-        if (isset($expectedTag)) {
258
-            if (!$this->_elements[$idx]->isType($expectedTag)) {
259
-                return false;
260
-            }
261
-        }
262
-        return true;
263
-    }
244
+	/**
245
+	 * Check whether the structure has an element at the given index, optionally
246
+	 * satisfying given tag expectation.
247
+	 *
248
+	 * @param int $idx Index 0..n
249
+	 * @param int|null $expectedTag Optional type tag expectation
250
+	 * @return bool
251
+	 */
252
+	public function has(int $idx, $expectedTag = null): bool
253
+	{
254
+		if (!isset($this->_elements[$idx])) {
255
+			return false;
256
+		}
257
+		if (isset($expectedTag)) {
258
+			if (!$this->_elements[$idx]->isType($expectedTag)) {
259
+				return false;
260
+			}
261
+		}
262
+		return true;
263
+	}
264 264
     
265
-    /**
266
-     * Get the element at the given index, optionally checking that the element
267
-     * has a given tag.
268
-     *
269
-     * NOTE! Expectation checking is deprecated and should be done
270
-     * with UnspecifiedType.
271
-     *
272
-     * @param int $idx Index 0..n
273
-     * @param int|null $expectedTag Optional type tag expectation
274
-     * @throws \OutOfBoundsException If element doesn't exists
275
-     * @throws \UnexpectedValueException If expectation fails
276
-     * @return UnspecifiedType
277
-     */
278
-    public function at(int $idx, $expectedTag = null): UnspecifiedType
279
-    {
280
-        if (!isset($this->_elements[$idx])) {
281
-            throw new \OutOfBoundsException(
282
-                "Structure doesn't have an element at index $idx.");
283
-        }
284
-        $element = $this->_elements[$idx];
285
-        if (isset($expectedTag)) {
286
-            $element->expectType($expectedTag);
287
-        }
288
-        return new UnspecifiedType($element);
289
-    }
265
+	/**
266
+	 * Get the element at the given index, optionally checking that the element
267
+	 * has a given tag.
268
+	 *
269
+	 * NOTE! Expectation checking is deprecated and should be done
270
+	 * with UnspecifiedType.
271
+	 *
272
+	 * @param int $idx Index 0..n
273
+	 * @param int|null $expectedTag Optional type tag expectation
274
+	 * @throws \OutOfBoundsException If element doesn't exists
275
+	 * @throws \UnexpectedValueException If expectation fails
276
+	 * @return UnspecifiedType
277
+	 */
278
+	public function at(int $idx, $expectedTag = null): UnspecifiedType
279
+	{
280
+		if (!isset($this->_elements[$idx])) {
281
+			throw new \OutOfBoundsException(
282
+				"Structure doesn't have an element at index $idx.");
283
+		}
284
+		$element = $this->_elements[$idx];
285
+		if (isset($expectedTag)) {
286
+			$element->expectType($expectedTag);
287
+		}
288
+		return new UnspecifiedType($element);
289
+	}
290 290
     
291
-    /**
292
-     * Check whether the structure contains a context specific element with a
293
-     * given tag.
294
-     *
295
-     * @param int $tag Tag number
296
-     * @return boolean
297
-     */
298
-    public function hasTagged($tag): bool
299
-    {
300
-        // lazily build lookup map
301
-        if (!isset($this->_taggedMap)) {
302
-            $this->_taggedMap = [];
303
-            foreach ($this->_elements as $element) {
304
-                if ($element->isTagged()) {
305
-                    $this->_taggedMap[$element->tag()] = $element;
306
-                }
307
-            }
308
-        }
309
-        return isset($this->_taggedMap[$tag]);
310
-    }
291
+	/**
292
+	 * Check whether the structure contains a context specific element with a
293
+	 * given tag.
294
+	 *
295
+	 * @param int $tag Tag number
296
+	 * @return boolean
297
+	 */
298
+	public function hasTagged($tag): bool
299
+	{
300
+		// lazily build lookup map
301
+		if (!isset($this->_taggedMap)) {
302
+			$this->_taggedMap = [];
303
+			foreach ($this->_elements as $element) {
304
+				if ($element->isTagged()) {
305
+					$this->_taggedMap[$element->tag()] = $element;
306
+				}
307
+			}
308
+		}
309
+		return isset($this->_taggedMap[$tag]);
310
+	}
311 311
     
312
-    /**
313
-     * Get a context specific element tagged with a given tag.
314
-     *
315
-     * @param int $tag
316
-     * @throws \LogicException If tag doesn't exists
317
-     * @return TaggedType
318
-     */
319
-    public function getTagged($tag): TaggedType
320
-    {
321
-        if (!$this->hasTagged($tag)) {
322
-            throw new \LogicException("No tagged element for tag $tag.");
323
-        }
324
-        return $this->_taggedMap[$tag];
325
-    }
312
+	/**
313
+	 * Get a context specific element tagged with a given tag.
314
+	 *
315
+	 * @param int $tag
316
+	 * @throws \LogicException If tag doesn't exists
317
+	 * @return TaggedType
318
+	 */
319
+	public function getTagged($tag): TaggedType
320
+	{
321
+		if (!$this->hasTagged($tag)) {
322
+			throw new \LogicException("No tagged element for tag $tag.");
323
+		}
324
+		return $this->_taggedMap[$tag];
325
+	}
326 326
     
327
-    /**
328
-     *
329
-     * @see \Countable::count()
330
-     * @return int
331
-     */
332
-    public function count(): int
333
-    {
334
-        return count($this->_elements);
335
-    }
327
+	/**
328
+	 *
329
+	 * @see \Countable::count()
330
+	 * @return int
331
+	 */
332
+	public function count(): int
333
+	{
334
+		return count($this->_elements);
335
+	}
336 336
     
337
-    /**
338
-     * Get an iterator for the UnspecifiedElement objects.
339
-     *
340
-     * @see \IteratorAggregate::getIterator()
341
-     * @return \ArrayIterator
342
-     */
343
-    public function getIterator(): \ArrayIterator
344
-    {
345
-        return new \ArrayIterator($this->elements());
346
-    }
337
+	/**
338
+	 * Get an iterator for the UnspecifiedElement objects.
339
+	 *
340
+	 * @see \IteratorAggregate::getIterator()
341
+	 * @return \ArrayIterator
342
+	 */
343
+	public function getIterator(): \ArrayIterator
344
+	{
345
+		return new \ArrayIterator($this->elements());
346
+	}
347 347
 }
Please login to merge, or discard this patch.