GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — php72 ( 46de60...311c45 )
by Joni
07:20
created
lib/ASN1/Type/Primitive/BitString.php 1 patch
Indentation   +182 added lines, -182 removed lines patch added patch discarded remove patch
@@ -17,195 +17,195 @@
 block discarded – undo
17 17
  */
18 18
 class BitString extends StringType
19 19
 {
20
-    use UniversalClass;
21
-    use PrimitiveType;
20
+	use UniversalClass;
21
+	use PrimitiveType;
22 22
 
23
-    /**
24
-     * Number of unused bits in the last octet.
25
-     *
26
-     * @var int
27
-     */
28
-    protected $_unusedBits;
23
+	/**
24
+	 * Number of unused bits in the last octet.
25
+	 *
26
+	 * @var int
27
+	 */
28
+	protected $_unusedBits;
29 29
 
30
-    /**
31
-     * Constructor.
32
-     *
33
-     * @param string $string      Content octets
34
-     * @param int    $unused_bits Number of unused bits in the last octet
35
-     */
36
-    public function __construct(string $string, int $unused_bits = 0)
37
-    {
38
-        $this->_typeTag = self::TYPE_BIT_STRING;
39
-        parent::__construct($string);
40
-        $this->_unusedBits = $unused_bits;
41
-    }
30
+	/**
31
+	 * Constructor.
32
+	 *
33
+	 * @param string $string      Content octets
34
+	 * @param int    $unused_bits Number of unused bits in the last octet
35
+	 */
36
+	public function __construct(string $string, int $unused_bits = 0)
37
+	{
38
+		$this->_typeTag = self::TYPE_BIT_STRING;
39
+		parent::__construct($string);
40
+		$this->_unusedBits = $unused_bits;
41
+	}
42 42
 
43
-    /**
44
-     * Get the number of bits in the string.
45
-     *
46
-     * @return int
47
-     */
48
-    public function numBits(): int
49
-    {
50
-        return strlen($this->_string) * 8 - $this->_unusedBits;
51
-    }
43
+	/**
44
+	 * Get the number of bits in the string.
45
+	 *
46
+	 * @return int
47
+	 */
48
+	public function numBits(): int
49
+	{
50
+		return strlen($this->_string) * 8 - $this->_unusedBits;
51
+	}
52 52
 
53
-    /**
54
-     * Get the number of unused bits in the last octet of the string.
55
-     *
56
-     * @return int
57
-     */
58
-    public function unusedBits(): int
59
-    {
60
-        return $this->_unusedBits;
61
-    }
53
+	/**
54
+	 * Get the number of unused bits in the last octet of the string.
55
+	 *
56
+	 * @return int
57
+	 */
58
+	public function unusedBits(): int
59
+	{
60
+		return $this->_unusedBits;
61
+	}
62 62
 
63
-    /**
64
-     * Test whether bit is set.
65
-     *
66
-     * @param int $idx Bit index.
67
-     *                 Most significant bit of the first octet is index 0.
68
-     *
69
-     * @return bool
70
-     */
71
-    public function testBit(int $idx): bool
72
-    {
73
-        // octet index
74
-        $oi = (int) floor($idx / 8);
75
-        // if octet is outside range
76
-        if ($oi < 0 || $oi >= strlen($this->_string)) {
77
-            throw new \OutOfBoundsException('Index is out of bounds.');
78
-        }
79
-        // bit index
80
-        $bi = $idx % 8;
81
-        // if tested bit is last octet's unused bit
82
-        if ($oi == strlen($this->_string) - 1) {
83
-            if ($bi >= 8 - $this->_unusedBits) {
84
-                throw new \OutOfBoundsException(
85
-                    'Index refers to an unused bit.');
86
-            }
87
-        }
88
-        $byte = $this->_string[$oi];
89
-        // index 0 is the most significant bit in byte
90
-        $mask = 0x01 << (7 - $bi);
91
-        return (ord($byte) & $mask) > 0;
92
-    }
63
+	/**
64
+	 * Test whether bit is set.
65
+	 *
66
+	 * @param int $idx Bit index.
67
+	 *                 Most significant bit of the first octet is index 0.
68
+	 *
69
+	 * @return bool
70
+	 */
71
+	public function testBit(int $idx): bool
72
+	{
73
+		// octet index
74
+		$oi = (int) floor($idx / 8);
75
+		// if octet is outside range
76
+		if ($oi < 0 || $oi >= strlen($this->_string)) {
77
+			throw new \OutOfBoundsException('Index is out of bounds.');
78
+		}
79
+		// bit index
80
+		$bi = $idx % 8;
81
+		// if tested bit is last octet's unused bit
82
+		if ($oi == strlen($this->_string) - 1) {
83
+			if ($bi >= 8 - $this->_unusedBits) {
84
+				throw new \OutOfBoundsException(
85
+					'Index refers to an unused bit.');
86
+			}
87
+		}
88
+		$byte = $this->_string[$oi];
89
+		// index 0 is the most significant bit in byte
90
+		$mask = 0x01 << (7 - $bi);
91
+		return (ord($byte) & $mask) > 0;
92
+	}
93 93
 
94
-    /**
95
-     * Get range of bits.
96
-     *
97
-     * @param int $start  Index of first bit
98
-     * @param int $length Number of bits in range
99
-     *
100
-     * @throws \OutOfBoundsException
101
-     *
102
-     * @return string Integer of $length bits
103
-     */
104
-    public function range(int $start, int $length): string
105
-    {
106
-        if (!$length) {
107
-            return '0';
108
-        }
109
-        if ($start + $length > $this->numBits()) {
110
-            throw new \OutOfBoundsException('Not enough bits.');
111
-        }
112
-        $bits = gmp_init(0);
113
-        $idx = $start;
114
-        $end = $start + $length;
115
-        while (true) {
116
-            $bit = $this->testBit($idx) ? 1 : 0;
117
-            $bits |= $bit;
118
-            if (++$idx >= $end) {
119
-                break;
120
-            }
121
-            $bits <<= 1;
122
-        }
123
-        return gmp_strval($bits, 10);
124
-    }
94
+	/**
95
+	 * Get range of bits.
96
+	 *
97
+	 * @param int $start  Index of first bit
98
+	 * @param int $length Number of bits in range
99
+	 *
100
+	 * @throws \OutOfBoundsException
101
+	 *
102
+	 * @return string Integer of $length bits
103
+	 */
104
+	public function range(int $start, int $length): string
105
+	{
106
+		if (!$length) {
107
+			return '0';
108
+		}
109
+		if ($start + $length > $this->numBits()) {
110
+			throw new \OutOfBoundsException('Not enough bits.');
111
+		}
112
+		$bits = gmp_init(0);
113
+		$idx = $start;
114
+		$end = $start + $length;
115
+		while (true) {
116
+			$bit = $this->testBit($idx) ? 1 : 0;
117
+			$bits |= $bit;
118
+			if (++$idx >= $end) {
119
+				break;
120
+			}
121
+			$bits <<= 1;
122
+		}
123
+		return gmp_strval($bits, 10);
124
+	}
125 125
 
126
-    /**
127
-     * Get a copy of the bit string with trailing zeroes removed.
128
-     *
129
-     * @return self
130
-     */
131
-    public function withoutTrailingZeroes(): self
132
-    {
133
-        // if bit string was empty
134
-        if (!strlen($this->_string)) {
135
-            return new self('');
136
-        }
137
-        $bits = $this->_string;
138
-        // count number of empty trailing octets
139
-        $unused_octets = 0;
140
-        for ($idx = strlen($bits) - 1; $idx >= 0; --$idx, ++$unused_octets) {
141
-            if ("\x0" != $bits[$idx]) {
142
-                break;
143
-            }
144
-        }
145
-        // strip trailing octets
146
-        if ($unused_octets) {
147
-            $bits = substr($bits, 0, -$unused_octets);
148
-        }
149
-        // if bit string was full of zeroes
150
-        if (!strlen($bits)) {
151
-            return new self('');
152
-        }
153
-        // count number of trailing zeroes in the last octet
154
-        $unused_bits = 0;
155
-        $byte = ord($bits[strlen($bits) - 1]);
156
-        while (!($byte & 0x01)) {
157
-            ++$unused_bits;
158
-            $byte >>= 1;
159
-        }
160
-        return new self($bits, $unused_bits);
161
-    }
126
+	/**
127
+	 * Get a copy of the bit string with trailing zeroes removed.
128
+	 *
129
+	 * @return self
130
+	 */
131
+	public function withoutTrailingZeroes(): self
132
+	{
133
+		// if bit string was empty
134
+		if (!strlen($this->_string)) {
135
+			return new self('');
136
+		}
137
+		$bits = $this->_string;
138
+		// count number of empty trailing octets
139
+		$unused_octets = 0;
140
+		for ($idx = strlen($bits) - 1; $idx >= 0; --$idx, ++$unused_octets) {
141
+			if ("\x0" != $bits[$idx]) {
142
+				break;
143
+			}
144
+		}
145
+		// strip trailing octets
146
+		if ($unused_octets) {
147
+			$bits = substr($bits, 0, -$unused_octets);
148
+		}
149
+		// if bit string was full of zeroes
150
+		if (!strlen($bits)) {
151
+			return new self('');
152
+		}
153
+		// count number of trailing zeroes in the last octet
154
+		$unused_bits = 0;
155
+		$byte = ord($bits[strlen($bits) - 1]);
156
+		while (!($byte & 0x01)) {
157
+			++$unused_bits;
158
+			$byte >>= 1;
159
+		}
160
+		return new self($bits, $unused_bits);
161
+	}
162 162
 
163
-    /**
164
-     * {@inheritdoc}
165
-     */
166
-    protected function _encodedContentDER(): string
167
-    {
168
-        $der = chr($this->_unusedBits);
169
-        $der .= $this->_string;
170
-        if ($this->_unusedBits) {
171
-            $octet = $der[strlen($der) - 1];
172
-            // set unused bits to zero
173
-            $octet &= chr(0xff & ~((1 << $this->_unusedBits) - 1));
174
-            $der[strlen($der) - 1] = $octet;
175
-        }
176
-        return $der;
177
-    }
163
+	/**
164
+	 * {@inheritdoc}
165
+	 */
166
+	protected function _encodedContentDER(): string
167
+	{
168
+		$der = chr($this->_unusedBits);
169
+		$der .= $this->_string;
170
+		if ($this->_unusedBits) {
171
+			$octet = $der[strlen($der) - 1];
172
+			// set unused bits to zero
173
+			$octet &= chr(0xff & ~((1 << $this->_unusedBits) - 1));
174
+			$der[strlen($der) - 1] = $octet;
175
+		}
176
+		return $der;
177
+	}
178 178
 
179
-    /**
180
-     * {@inheritdoc}
181
-     */
182
-    protected static function _decodeFromDER(Identifier $identifier,
183
-        string $data, int &$offset): ElementBase
184
-    {
185
-        $idx = $offset;
186
-        $length = Length::expectFromDER($data, $idx);
187
-        if ($length->intLength() < 1) {
188
-            throw new DecodeException('Bit string length must be at least 1.');
189
-        }
190
-        $unused_bits = ord($data[$idx++]);
191
-        if ($unused_bits > 7) {
192
-            throw new DecodeException(
193
-                'Unused bits in a bit string must be less than 8.');
194
-        }
195
-        $str_len = $length->intLength() - 1;
196
-        if ($str_len) {
197
-            $str = substr($data, $idx, $str_len);
198
-            if ($unused_bits) {
199
-                $mask = (1 << $unused_bits) - 1;
200
-                if (ord($str[strlen($str) - 1]) & $mask) {
201
-                    throw new DecodeException(
202
-                        'DER encoded bit string must have zero padding.');
203
-                }
204
-            }
205
-        } else {
206
-            $str = '';
207
-        }
208
-        $offset = $idx + $str_len;
209
-        return new self($str, $unused_bits);
210
-    }
179
+	/**
180
+	 * {@inheritdoc}
181
+	 */
182
+	protected static function _decodeFromDER(Identifier $identifier,
183
+		string $data, int &$offset): ElementBase
184
+	{
185
+		$idx = $offset;
186
+		$length = Length::expectFromDER($data, $idx);
187
+		if ($length->intLength() < 1) {
188
+			throw new DecodeException('Bit string length must be at least 1.');
189
+		}
190
+		$unused_bits = ord($data[$idx++]);
191
+		if ($unused_bits > 7) {
192
+			throw new DecodeException(
193
+				'Unused bits in a bit string must be less than 8.');
194
+		}
195
+		$str_len = $length->intLength() - 1;
196
+		if ($str_len) {
197
+			$str = substr($data, $idx, $str_len);
198
+			if ($unused_bits) {
199
+				$mask = (1 << $unused_bits) - 1;
200
+				if (ord($str[strlen($str) - 1]) & $mask) {
201
+					throw new DecodeException(
202
+						'DER encoded bit string must have zero padding.');
203
+				}
204
+			}
205
+		} else {
206
+			$str = '';
207
+		}
208
+		$offset = $idx + $str_len;
209
+		return new self($str, $unused_bits);
210
+	}
211 211
 }
Please login to merge, or discard this patch.
lib/ASN1/Type/Primitive/UTCTime.php 1 patch
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -17,70 +17,70 @@
 block discarded – undo
17 17
  */
18 18
 class UTCTime extends TimeType
19 19
 {
20
-    use UniversalClass;
21
-    use PrimitiveType;
20
+	use UniversalClass;
21
+	use PrimitiveType;
22 22
 
23
-    /**
24
-     * Regular expression to parse date.
25
-     *
26
-     * DER restricts format to UTC timezone (Z suffix).
27
-     *
28
-     * @var string
29
-     */
30
-    const REGEX = '#^' .
31
-        '(\d\d)' . // YY
32
-        '(\d\d)' . // MM
33
-        '(\d\d)' . // DD
34
-        '(\d\d)' . // hh
35
-        '(\d\d)' . // mm
36
-        '(\d\d)' . // ss
37
-        'Z' . // TZ
38
-        '$#';
23
+	/**
24
+	 * Regular expression to parse date.
25
+	 *
26
+	 * DER restricts format to UTC timezone (Z suffix).
27
+	 *
28
+	 * @var string
29
+	 */
30
+	const REGEX = '#^' .
31
+		'(\d\d)' . // YY
32
+		'(\d\d)' . // MM
33
+		'(\d\d)' . // DD
34
+		'(\d\d)' . // hh
35
+		'(\d\d)' . // mm
36
+		'(\d\d)' . // ss
37
+		'Z' . // TZ
38
+		'$#';
39 39
 
40
-    /**
41
-     * Constructor.
42
-     *
43
-     * @param \DateTimeImmutable $dt
44
-     */
45
-    public function __construct(\DateTimeImmutable $dt)
46
-    {
47
-        $this->_typeTag = self::TYPE_UTC_TIME;
48
-        parent::__construct($dt);
49
-    }
40
+	/**
41
+	 * Constructor.
42
+	 *
43
+	 * @param \DateTimeImmutable $dt
44
+	 */
45
+	public function __construct(\DateTimeImmutable $dt)
46
+	{
47
+		$this->_typeTag = self::TYPE_UTC_TIME;
48
+		parent::__construct($dt);
49
+	}
50 50
 
51
-    /**
52
-     * {@inheritdoc}
53
-     */
54
-    protected function _encodedContentDER(): string
55
-    {
56
-        $dt = $this->_dateTime->setTimezone(self::_createTimeZone(self::TZ_UTC));
57
-        return $dt->format('ymdHis\\Z');
58
-    }
51
+	/**
52
+	 * {@inheritdoc}
53
+	 */
54
+	protected function _encodedContentDER(): string
55
+	{
56
+		$dt = $this->_dateTime->setTimezone(self::_createTimeZone(self::TZ_UTC));
57
+		return $dt->format('ymdHis\\Z');
58
+	}
59 59
 
60
-    /**
61
-     * {@inheritdoc}
62
-     */
63
-    protected static function _decodeFromDER(Identifier $identifier,
64
-        string $data, int &$offset): ElementBase
65
-    {
66
-        $idx = $offset;
67
-        $length = Length::expectFromDER($data, $idx)->intLength();
68
-        $str = substr($data, $idx, $length);
69
-        $idx += $length;
70
-        /** @var string[] $match */
71
-        if (!preg_match(self::REGEX, $str, $match)) {
72
-            throw new DecodeException('Invalid UTCTime format.');
73
-        }
74
-        [, $year, $month, $day, $hour, $minute, $second] = $match;
75
-        $time = $year . $month . $day . $hour . $minute . $second . self::TZ_UTC;
76
-        $dt = \DateTimeImmutable::createFromFormat('!ymdHisT', $time,
77
-            self::_createTimeZone(self::TZ_UTC));
78
-        if (!$dt) {
79
-            throw new DecodeException(
80
-                'Failed to decode UTCTime: ' .
81
-                self::_getLastDateTimeImmutableErrorsStr());
82
-        }
83
-        $offset = $idx;
84
-        return new self($dt);
85
-    }
60
+	/**
61
+	 * {@inheritdoc}
62
+	 */
63
+	protected static function _decodeFromDER(Identifier $identifier,
64
+		string $data, int &$offset): ElementBase
65
+	{
66
+		$idx = $offset;
67
+		$length = Length::expectFromDER($data, $idx)->intLength();
68
+		$str = substr($data, $idx, $length);
69
+		$idx += $length;
70
+		/** @var string[] $match */
71
+		if (!preg_match(self::REGEX, $str, $match)) {
72
+			throw new DecodeException('Invalid UTCTime format.');
73
+		}
74
+		[, $year, $month, $day, $hour, $minute, $second] = $match;
75
+		$time = $year . $month . $day . $hour . $minute . $second . self::TZ_UTC;
76
+		$dt = \DateTimeImmutable::createFromFormat('!ymdHisT', $time,
77
+			self::_createTimeZone(self::TZ_UTC));
78
+		if (!$dt) {
79
+			throw new DecodeException(
80
+				'Failed to decode UTCTime: ' .
81
+				self::_getLastDateTimeImmutableErrorsStr());
82
+		}
83
+		$offset = $idx;
84
+		return new self($dt);
85
+	}
86 86
 }
Please login to merge, or discard this patch.
lib/ASN1/Type/Primitive/GeneralString.php 1 patch
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -12,25 +12,25 @@
 block discarded – undo
12 12
  */
13 13
 class GeneralString extends PrimitiveString
14 14
 {
15
-    use UniversalClass;
15
+	use UniversalClass;
16 16
 
17
-    /**
18
-     * Constructor.
19
-     *
20
-     * @param string $string
21
-     */
22
-    public function __construct(string $string)
23
-    {
24
-        $this->_typeTag = self::TYPE_GENERAL_STRING;
25
-        parent::__construct($string);
26
-    }
17
+	/**
18
+	 * Constructor.
19
+	 *
20
+	 * @param string $string
21
+	 */
22
+	public function __construct(string $string)
23
+	{
24
+		$this->_typeTag = self::TYPE_GENERAL_STRING;
25
+		parent::__construct($string);
26
+	}
27 27
 
28
-    /**
29
-     * {@inheritdoc}
30
-     */
31
-    protected function _validateString(string $string): bool
32
-    {
33
-        // allow everything
34
-        return true;
35
-    }
28
+	/**
29
+	 * {@inheritdoc}
30
+	 */
31
+	protected function _validateString(string $string): bool
32
+	{
33
+		// allow everything
34
+		return true;
35
+	}
36 36
 }
Please login to merge, or discard this patch.
lib/ASN1/Type/Primitive/NumericString.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -12,24 +12,24 @@
 block discarded – undo
12 12
  */
13 13
 class NumericString extends PrimitiveString
14 14
 {
15
-    use UniversalClass;
15
+	use UniversalClass;
16 16
 
17
-    /**
18
-     * Constructor.
19
-     *
20
-     * @param string $string
21
-     */
22
-    public function __construct(string $string)
23
-    {
24
-        $this->_typeTag = self::TYPE_NUMERIC_STRING;
25
-        parent::__construct($string);
26
-    }
17
+	/**
18
+	 * Constructor.
19
+	 *
20
+	 * @param string $string
21
+	 */
22
+	public function __construct(string $string)
23
+	{
24
+		$this->_typeTag = self::TYPE_NUMERIC_STRING;
25
+		parent::__construct($string);
26
+	}
27 27
 
28
-    /**
29
-     * {@inheritdoc}
30
-     */
31
-    protected function _validateString(string $string): bool
32
-    {
33
-        return 0 == preg_match('/[^0-9 ]/', $string);
34
-    }
28
+	/**
29
+	 * {@inheritdoc}
30
+	 */
31
+	protected function _validateString(string $string): bool
32
+	{
33
+		return 0 == preg_match('/[^0-9 ]/', $string);
34
+	}
35 35
 }
Please login to merge, or discard this patch.
lib/ASN1/Type/Primitive/IA5String.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -12,24 +12,24 @@
 block discarded – undo
12 12
  */
13 13
 class IA5String extends PrimitiveString
14 14
 {
15
-    use UniversalClass;
15
+	use UniversalClass;
16 16
 
17
-    /**
18
-     * Constructor.
19
-     *
20
-     * @param string $string
21
-     */
22
-    public function __construct(string $string)
23
-    {
24
-        $this->_typeTag = self::TYPE_IA5_STRING;
25
-        parent::__construct($string);
26
-    }
17
+	/**
18
+	 * Constructor.
19
+	 *
20
+	 * @param string $string
21
+	 */
22
+	public function __construct(string $string)
23
+	{
24
+		$this->_typeTag = self::TYPE_IA5_STRING;
25
+		parent::__construct($string);
26
+	}
27 27
 
28
-    /**
29
-     * {@inheritdoc}
30
-     */
31
-    protected function _validateString(string $string): bool
32
-    {
33
-        return 0 == preg_match('/[^\x01-\x7f]/', $string);
34
-    }
28
+	/**
29
+	 * {@inheritdoc}
30
+	 */
31
+	protected function _validateString(string $string): bool
32
+	{
33
+		return 0 == preg_match('/[^\x01-\x7f]/', $string);
34
+	}
35 35
 }
Please login to merge, or discard this patch.
lib/ASN1/Type/Primitive/Integer.php 1 patch
Indentation   +148 added lines, -148 removed lines patch added patch discarded remove patch
@@ -17,161 +17,161 @@
 block discarded – undo
17 17
  */
18 18
 class Integer extends Element
19 19
 {
20
-    use UniversalClass;
21
-    use PrimitiveType;
20
+	use UniversalClass;
21
+	use PrimitiveType;
22 22
 
23
-    /**
24
-     * The number.
25
-     *
26
-     * @var BigInt
27
-     */
28
-    private $_number;
23
+	/**
24
+	 * The number.
25
+	 *
26
+	 * @var BigInt
27
+	 */
28
+	private $_number;
29 29
 
30
-    /**
31
-     * Constructor.
32
-     *
33
-     * @param int|string $number Base 10 integer
34
-     */
35
-    public function __construct($number)
36
-    {
37
-        $this->_typeTag = self::TYPE_INTEGER;
38
-        if (!self::_validateNumber($number)) {
39
-            $var = is_scalar($number) ? strval($number) : gettype($number);
40
-            throw new \InvalidArgumentException("'${var}' is not a valid number.");
41
-        }
42
-        $this->_number = new BigInt($number);
43
-    }
30
+	/**
31
+	 * Constructor.
32
+	 *
33
+	 * @param int|string $number Base 10 integer
34
+	 */
35
+	public function __construct($number)
36
+	{
37
+		$this->_typeTag = self::TYPE_INTEGER;
38
+		if (!self::_validateNumber($number)) {
39
+			$var = is_scalar($number) ? strval($number) : gettype($number);
40
+			throw new \InvalidArgumentException("'${var}' is not a valid number.");
41
+		}
42
+		$this->_number = new BigInt($number);
43
+	}
44 44
 
45
-    /**
46
-     * Get the number as a base 10.
47
-     *
48
-     * @return string Integer as a string
49
-     */
50
-    public function number(): string
51
-    {
52
-        return $this->_number->base10();
53
-    }
45
+	/**
46
+	 * Get the number as a base 10.
47
+	 *
48
+	 * @return string Integer as a string
49
+	 */
50
+	public function number(): string
51
+	{
52
+		return $this->_number->base10();
53
+	}
54 54
 
55
-    /**
56
-     * Get the number as an integer type.
57
-     *
58
-     * @return int
59
-     */
60
-    public function intNumber(): int
61
-    {
62
-        return $this->_number->intVal();
63
-    }
55
+	/**
56
+	 * Get the number as an integer type.
57
+	 *
58
+	 * @return int
59
+	 */
60
+	public function intNumber(): int
61
+	{
62
+		return $this->_number->intVal();
63
+	}
64 64
 
65
-    /**
66
-     * {@inheritdoc}
67
-     */
68
-    protected function _encodedContentDER(): string
69
-    {
70
-        $num = $this->_number->gmpObj();
71
-        switch (gmp_sign($num)) {
72
-            // positive
73
-            case 1:
74
-                return self::_encodePositiveInteger($num);
75
-            // negative
76
-            case -1:
77
-                return self::_encodeNegativeInteger($num);
78
-        }
79
-        // zero
80
-        return "\0";
81
-    }
65
+	/**
66
+	 * {@inheritdoc}
67
+	 */
68
+	protected function _encodedContentDER(): string
69
+	{
70
+		$num = $this->_number->gmpObj();
71
+		switch (gmp_sign($num)) {
72
+			// positive
73
+			case 1:
74
+				return self::_encodePositiveInteger($num);
75
+			// negative
76
+			case -1:
77
+				return self::_encodeNegativeInteger($num);
78
+		}
79
+		// zero
80
+		return "\0";
81
+	}
82 82
 
83
-    /**
84
-     * {@inheritdoc}
85
-     */
86
-    protected static function _decodeFromDER(Identifier $identifier,
87
-        string $data, int &$offset): ElementBase
88
-    {
89
-        $idx = $offset;
90
-        $length = Length::expectFromDER($data, $idx)->intLength();
91
-        $bytes = substr($data, $idx, $length);
92
-        $idx += $length;
93
-        $neg = ord($bytes[0]) & 0x80;
94
-        // negative, apply inversion of two's complement
95
-        if ($neg) {
96
-            $len = strlen($bytes);
97
-            for ($i = 0; $i < $len; ++$i) {
98
-                $bytes[$i] = ~$bytes[$i];
99
-            }
100
-        }
101
-        $num = gmp_init(bin2hex($bytes), 16);
102
-        // negative, apply addition of two's complement
103
-        // and produce negative result
104
-        if ($neg) {
105
-            $num = gmp_neg($num + 1);
106
-        }
107
-        $offset = $idx;
108
-        // late static binding since enumerated extends integer type
109
-        return new static(gmp_strval($num, 10));
110
-    }
83
+	/**
84
+	 * {@inheritdoc}
85
+	 */
86
+	protected static function _decodeFromDER(Identifier $identifier,
87
+		string $data, int &$offset): ElementBase
88
+	{
89
+		$idx = $offset;
90
+		$length = Length::expectFromDER($data, $idx)->intLength();
91
+		$bytes = substr($data, $idx, $length);
92
+		$idx += $length;
93
+		$neg = ord($bytes[0]) & 0x80;
94
+		// negative, apply inversion of two's complement
95
+		if ($neg) {
96
+			$len = strlen($bytes);
97
+			for ($i = 0; $i < $len; ++$i) {
98
+				$bytes[$i] = ~$bytes[$i];
99
+			}
100
+		}
101
+		$num = gmp_init(bin2hex($bytes), 16);
102
+		// negative, apply addition of two's complement
103
+		// and produce negative result
104
+		if ($neg) {
105
+			$num = gmp_neg($num + 1);
106
+		}
107
+		$offset = $idx;
108
+		// late static binding since enumerated extends integer type
109
+		return new static(gmp_strval($num, 10));
110
+	}
111 111
 
112
-    /**
113
-     * Encode positive integer to DER content.
114
-     *
115
-     * @param \GMP $num
116
-     *
117
-     * @return string
118
-     */
119
-    private static function _encodePositiveInteger(\GMP $num): string
120
-    {
121
-        $bin = gmp_export($num, 1, GMP_MSW_FIRST | GMP_BIG_ENDIAN);
122
-        // if first bit is 1, prepend full zero byte
123
-        // to represent positive two's complement
124
-        if (ord($bin[0]) & 0x80) {
125
-            $bin = chr(0x00) . $bin;
126
-        }
127
-        return $bin;
128
-    }
112
+	/**
113
+	 * Encode positive integer to DER content.
114
+	 *
115
+	 * @param \GMP $num
116
+	 *
117
+	 * @return string
118
+	 */
119
+	private static function _encodePositiveInteger(\GMP $num): string
120
+	{
121
+		$bin = gmp_export($num, 1, GMP_MSW_FIRST | GMP_BIG_ENDIAN);
122
+		// if first bit is 1, prepend full zero byte
123
+		// to represent positive two's complement
124
+		if (ord($bin[0]) & 0x80) {
125
+			$bin = chr(0x00) . $bin;
126
+		}
127
+		return $bin;
128
+	}
129 129
 
130
-    /**
131
-     * Encode negative integer to DER content.
132
-     *
133
-     * @param \GMP $num
134
-     *
135
-     * @return string
136
-     */
137
-    private static function _encodeNegativeInteger(\GMP $num): string
138
-    {
139
-        $num = gmp_abs($num);
140
-        // compute number of bytes required
141
-        $width = 1;
142
-        if ($num > 128) {
143
-            $tmp = $num;
144
-            do {
145
-                ++$width;
146
-                $tmp >>= 8;
147
-            } while ($tmp > 128);
148
-        }
149
-        // compute two's complement 2^n - x
150
-        $num = gmp_pow('2', 8 * $width) - $num;
151
-        $bin = gmp_export($num, 1, GMP_MSW_FIRST | GMP_BIG_ENDIAN);
152
-        // if first bit is 0, prepend full inverted byte
153
-        // to represent negative two's complement
154
-        if (!(ord($bin[0]) & 0x80)) {
155
-            $bin = chr(0xff) . $bin;
156
-        }
157
-        return $bin;
158
-    }
130
+	/**
131
+	 * Encode negative integer to DER content.
132
+	 *
133
+	 * @param \GMP $num
134
+	 *
135
+	 * @return string
136
+	 */
137
+	private static function _encodeNegativeInteger(\GMP $num): string
138
+	{
139
+		$num = gmp_abs($num);
140
+		// compute number of bytes required
141
+		$width = 1;
142
+		if ($num > 128) {
143
+			$tmp = $num;
144
+			do {
145
+				++$width;
146
+				$tmp >>= 8;
147
+			} while ($tmp > 128);
148
+		}
149
+		// compute two's complement 2^n - x
150
+		$num = gmp_pow('2', 8 * $width) - $num;
151
+		$bin = gmp_export($num, 1, GMP_MSW_FIRST | GMP_BIG_ENDIAN);
152
+		// if first bit is 0, prepend full inverted byte
153
+		// to represent negative two's complement
154
+		if (!(ord($bin[0]) & 0x80)) {
155
+			$bin = chr(0xff) . $bin;
156
+		}
157
+		return $bin;
158
+	}
159 159
 
160
-    /**
161
-     * Test that number is valid for this context.
162
-     *
163
-     * @param mixed $num
164
-     *
165
-     * @return bool
166
-     */
167
-    private static function _validateNumber($num): bool
168
-    {
169
-        if (is_int($num)) {
170
-            return true;
171
-        }
172
-        if (is_string($num) && preg_match('/-?\d+/', $num)) {
173
-            return true;
174
-        }
175
-        return false;
176
-    }
160
+	/**
161
+	 * Test that number is valid for this context.
162
+	 *
163
+	 * @param mixed $num
164
+	 *
165
+	 * @return bool
166
+	 */
167
+	private static function _validateNumber($num): bool
168
+	{
169
+		if (is_int($num)) {
170
+			return true;
171
+		}
172
+		if (is_string($num) && preg_match('/-?\d+/', $num)) {
173
+			return true;
174
+		}
175
+		return false;
176
+	}
177 177
 }
Please login to merge, or discard this patch.
lib/ASN1/Type/Primitive/ObjectIdentifier.php 1 patch
Indentation   +185 added lines, -185 removed lines patch added patch discarded remove patch
@@ -17,199 +17,199 @@
 block discarded – undo
17 17
  */
18 18
 class ObjectIdentifier extends Element
19 19
 {
20
-    use UniversalClass;
21
-    use PrimitiveType;
20
+	use UniversalClass;
21
+	use PrimitiveType;
22 22
 
23
-    /**
24
-     * Object identifier in dotted format.
25
-     *
26
-     * @var string
27
-     */
28
-    protected $_oid;
23
+	/**
24
+	 * Object identifier in dotted format.
25
+	 *
26
+	 * @var string
27
+	 */
28
+	protected $_oid;
29 29
 
30
-    /**
31
-     * Object identifier split to sub ID's.
32
-     *
33
-     * @var \GMP[]
34
-     */
35
-    protected $_subids;
30
+	/**
31
+	 * Object identifier split to sub ID's.
32
+	 *
33
+	 * @var \GMP[]
34
+	 */
35
+	protected $_subids;
36 36
 
37
-    /**
38
-     * Constructor.
39
-     *
40
-     * @param string $oid OID in dotted format
41
-     */
42
-    public function __construct(string $oid)
43
-    {
44
-        $this->_oid = $oid;
45
-        $this->_subids = self::_explodeDottedOID($oid);
46
-        // if OID is non-empty
47
-        if (count($this->_subids) > 0) {
48
-            // check that at least two nodes are set
49
-            if (count($this->_subids) < 2) {
50
-                throw new \UnexpectedValueException(
51
-                    'OID must have at least two nodes.');
52
-            }
53
-            // check that root arc is in 0..2 range
54
-            if ($this->_subids[0] > 2) {
55
-                throw new \UnexpectedValueException(
56
-                    'Root arc must be in range of 0..2.');
57
-            }
58
-            // if root arc is 0 or 1, second node must be in 0..39 range
59
-            if ($this->_subids[0] < 2 && $this->_subids[1] >= 40) {
60
-                throw new \UnexpectedValueException(
61
-                    'Second node must be in 0..39 range for root arcs 0 and 1.');
62
-            }
63
-        }
64
-        $this->_typeTag = self::TYPE_OBJECT_IDENTIFIER;
65
-    }
37
+	/**
38
+	 * Constructor.
39
+	 *
40
+	 * @param string $oid OID in dotted format
41
+	 */
42
+	public function __construct(string $oid)
43
+	{
44
+		$this->_oid = $oid;
45
+		$this->_subids = self::_explodeDottedOID($oid);
46
+		// if OID is non-empty
47
+		if (count($this->_subids) > 0) {
48
+			// check that at least two nodes are set
49
+			if (count($this->_subids) < 2) {
50
+				throw new \UnexpectedValueException(
51
+					'OID must have at least two nodes.');
52
+			}
53
+			// check that root arc is in 0..2 range
54
+			if ($this->_subids[0] > 2) {
55
+				throw new \UnexpectedValueException(
56
+					'Root arc must be in range of 0..2.');
57
+			}
58
+			// if root arc is 0 or 1, second node must be in 0..39 range
59
+			if ($this->_subids[0] < 2 && $this->_subids[1] >= 40) {
60
+				throw new \UnexpectedValueException(
61
+					'Second node must be in 0..39 range for root arcs 0 and 1.');
62
+			}
63
+		}
64
+		$this->_typeTag = self::TYPE_OBJECT_IDENTIFIER;
65
+	}
66 66
 
67
-    /**
68
-     * Get OID in dotted format.
69
-     *
70
-     * @return string
71
-     */
72
-    public function oid(): string
73
-    {
74
-        return $this->_oid;
75
-    }
67
+	/**
68
+	 * Get OID in dotted format.
69
+	 *
70
+	 * @return string
71
+	 */
72
+	public function oid(): string
73
+	{
74
+		return $this->_oid;
75
+	}
76 76
 
77
-    /**
78
-     * {@inheritdoc}
79
-     */
80
-    protected function _encodedContentDER(): string
81
-    {
82
-        $subids = $this->_subids;
83
-        // encode first two subids to one according to spec section 8.19.4
84
-        if (count($subids) >= 2) {
85
-            $num = ($subids[0] * 40) + $subids[1];
86
-            array_splice($subids, 0, 2, [$num]);
87
-        }
88
-        return self::_encodeSubIDs(...$subids);
89
-    }
77
+	/**
78
+	 * {@inheritdoc}
79
+	 */
80
+	protected function _encodedContentDER(): string
81
+	{
82
+		$subids = $this->_subids;
83
+		// encode first two subids to one according to spec section 8.19.4
84
+		if (count($subids) >= 2) {
85
+			$num = ($subids[0] * 40) + $subids[1];
86
+			array_splice($subids, 0, 2, [$num]);
87
+		}
88
+		return self::_encodeSubIDs(...$subids);
89
+	}
90 90
 
91
-    /**
92
-     * {@inheritdoc}
93
-     */
94
-    protected static function _decodeFromDER(Identifier $identifier,
95
-        string $data, int &$offset): ElementBase
96
-    {
97
-        $idx = $offset;
98
-        $len = Length::expectFromDER($data, $idx)->intLength();
99
-        $subids = self::_decodeSubIDs(substr($data, $idx, $len));
100
-        $idx += $len;
101
-        // decode first subidentifier according to spec section 8.19.4
102
-        if (isset($subids[0])) {
103
-            if ($subids[0] < 80) {
104
-                [$x, $y] = gmp_div_qr($subids[0], '40');
105
-            } else {
106
-                $x = gmp_init(2, 10);
107
-                $y = $subids[0] - 80;
108
-            }
109
-            array_splice($subids, 0, 1, [$x, $y]);
110
-        }
111
-        $offset = $idx;
112
-        return new self(self::_implodeSubIDs(...$subids));
113
-    }
91
+	/**
92
+	 * {@inheritdoc}
93
+	 */
94
+	protected static function _decodeFromDER(Identifier $identifier,
95
+		string $data, int &$offset): ElementBase
96
+	{
97
+		$idx = $offset;
98
+		$len = Length::expectFromDER($data, $idx)->intLength();
99
+		$subids = self::_decodeSubIDs(substr($data, $idx, $len));
100
+		$idx += $len;
101
+		// decode first subidentifier according to spec section 8.19.4
102
+		if (isset($subids[0])) {
103
+			if ($subids[0] < 80) {
104
+				[$x, $y] = gmp_div_qr($subids[0], '40');
105
+			} else {
106
+				$x = gmp_init(2, 10);
107
+				$y = $subids[0] - 80;
108
+			}
109
+			array_splice($subids, 0, 1, [$x, $y]);
110
+		}
111
+		$offset = $idx;
112
+		return new self(self::_implodeSubIDs(...$subids));
113
+	}
114 114
 
115
-    /**
116
-     * Explode dotted OID to an array of sub ID's.
117
-     *
118
-     * @param string $oid OID in dotted format
119
-     *
120
-     * @return \GMP[] Array of GMP numbers
121
-     */
122
-    protected static function _explodeDottedOID(string $oid): array
123
-    {
124
-        $subids = [];
125
-        if (strlen($oid)) {
126
-            foreach (explode('.', $oid) as $subid) {
127
-                $n = @gmp_init($subid, 10);
128
-                if (false === $n) {
129
-                    throw new \UnexpectedValueException(
130
-                        "'${subid}' is not a number.");
131
-                }
132
-                $subids[] = $n;
133
-            }
134
-        }
135
-        return $subids;
136
-    }
115
+	/**
116
+	 * Explode dotted OID to an array of sub ID's.
117
+	 *
118
+	 * @param string $oid OID in dotted format
119
+	 *
120
+	 * @return \GMP[] Array of GMP numbers
121
+	 */
122
+	protected static function _explodeDottedOID(string $oid): array
123
+	{
124
+		$subids = [];
125
+		if (strlen($oid)) {
126
+			foreach (explode('.', $oid) as $subid) {
127
+				$n = @gmp_init($subid, 10);
128
+				if (false === $n) {
129
+					throw new \UnexpectedValueException(
130
+						"'${subid}' is not a number.");
131
+				}
132
+				$subids[] = $n;
133
+			}
134
+		}
135
+		return $subids;
136
+	}
137 137
 
138
-    /**
139
-     * Implode an array of sub IDs to dotted OID format.
140
-     *
141
-     * @param \GMP ...$subids
142
-     *
143
-     * @return string
144
-     */
145
-    protected static function _implodeSubIDs(\GMP ...$subids): string
146
-    {
147
-        return implode('.',
148
-            array_map(function ($num) {
149
-                return gmp_strval($num, 10);
150
-            }, $subids));
151
-    }
138
+	/**
139
+	 * Implode an array of sub IDs to dotted OID format.
140
+	 *
141
+	 * @param \GMP ...$subids
142
+	 *
143
+	 * @return string
144
+	 */
145
+	protected static function _implodeSubIDs(\GMP ...$subids): string
146
+	{
147
+		return implode('.',
148
+			array_map(function ($num) {
149
+				return gmp_strval($num, 10);
150
+			}, $subids));
151
+	}
152 152
 
153
-    /**
154
-     * Encode sub ID's to DER.
155
-     *
156
-     * @param \GMP ...$subids
157
-     *
158
-     * @return string
159
-     */
160
-    protected static function _encodeSubIDs(\GMP ...$subids): string
161
-    {
162
-        $data = '';
163
-        foreach ($subids as $subid) {
164
-            // if number fits to one base 128 byte
165
-            if ($subid < 128) {
166
-                $data .= chr(intval($subid));
167
-            } else { // encode to multiple bytes
168
-                $bytes = [];
169
-                do {
170
-                    array_unshift($bytes, 0x7f & gmp_intval($subid));
171
-                    $subid >>= 7;
172
-                } while ($subid > 0);
173
-                // all bytes except last must have bit 8 set to one
174
-                foreach (array_splice($bytes, 0, -1) as $byte) {
175
-                    $data .= chr(0x80 | $byte);
176
-                }
177
-                $data .= chr(reset($bytes));
178
-            }
179
-        }
180
-        return $data;
181
-    }
153
+	/**
154
+	 * Encode sub ID's to DER.
155
+	 *
156
+	 * @param \GMP ...$subids
157
+	 *
158
+	 * @return string
159
+	 */
160
+	protected static function _encodeSubIDs(\GMP ...$subids): string
161
+	{
162
+		$data = '';
163
+		foreach ($subids as $subid) {
164
+			// if number fits to one base 128 byte
165
+			if ($subid < 128) {
166
+				$data .= chr(intval($subid));
167
+			} else { // encode to multiple bytes
168
+				$bytes = [];
169
+				do {
170
+					array_unshift($bytes, 0x7f & gmp_intval($subid));
171
+					$subid >>= 7;
172
+				} while ($subid > 0);
173
+				// all bytes except last must have bit 8 set to one
174
+				foreach (array_splice($bytes, 0, -1) as $byte) {
175
+					$data .= chr(0x80 | $byte);
176
+				}
177
+				$data .= chr(reset($bytes));
178
+			}
179
+		}
180
+		return $data;
181
+	}
182 182
 
183
-    /**
184
-     * Decode sub ID's from DER data.
185
-     *
186
-     * @param string $data
187
-     *
188
-     * @throws DecodeException
189
-     *
190
-     * @return \GMP[] Array of GMP numbers
191
-     */
192
-    protected static function _decodeSubIDs(string $data): array
193
-    {
194
-        $subids = [];
195
-        $idx = 0;
196
-        $end = strlen($data);
197
-        while ($idx < $end) {
198
-            $num = gmp_init('0', 10);
199
-            while (true) {
200
-                if ($idx >= $end) {
201
-                    throw new DecodeException('Unexpected end of data.');
202
-                }
203
-                $byte = ord($data[$idx++]);
204
-                $num |= $byte & 0x7f;
205
-                // bit 8 of the last octet is zero
206
-                if (!($byte & 0x80)) {
207
-                    break;
208
-                }
209
-                $num <<= 7;
210
-            }
211
-            $subids[] = $num;
212
-        }
213
-        return $subids;
214
-    }
183
+	/**
184
+	 * Decode sub ID's from DER data.
185
+	 *
186
+	 * @param string $data
187
+	 *
188
+	 * @throws DecodeException
189
+	 *
190
+	 * @return \GMP[] Array of GMP numbers
191
+	 */
192
+	protected static function _decodeSubIDs(string $data): array
193
+	{
194
+		$subids = [];
195
+		$idx = 0;
196
+		$end = strlen($data);
197
+		while ($idx < $end) {
198
+			$num = gmp_init('0', 10);
199
+			while (true) {
200
+				if ($idx >= $end) {
201
+					throw new DecodeException('Unexpected end of data.');
202
+				}
203
+				$byte = ord($data[$idx++]);
204
+				$num |= $byte & 0x7f;
205
+				// bit 8 of the last octet is zero
206
+				if (!($byte & 0x80)) {
207
+					break;
208
+				}
209
+				$num <<= 7;
210
+			}
211
+			$subids[] = $num;
212
+		}
213
+		return $subids;
214
+	}
215 215
 }
Please login to merge, or discard this patch.
lib/ASN1/Type/Primitive/PrintableString.php 1 patch
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -12,25 +12,25 @@
 block discarded – undo
12 12
  */
13 13
 class PrintableString extends PrimitiveString
14 14
 {
15
-    use UniversalClass;
15
+	use UniversalClass;
16 16
 
17
-    /**
18
-     * Constructor.
19
-     *
20
-     * @param string $string
21
-     */
22
-    public function __construct(string $string)
23
-    {
24
-        $this->_typeTag = self::TYPE_PRINTABLE_STRING;
25
-        parent::__construct($string);
26
-    }
17
+	/**
18
+	 * Constructor.
19
+	 *
20
+	 * @param string $string
21
+	 */
22
+	public function __construct(string $string)
23
+	{
24
+		$this->_typeTag = self::TYPE_PRINTABLE_STRING;
25
+		parent::__construct($string);
26
+	}
27 27
 
28
-    /**
29
-     * {@inheritdoc}
30
-     */
31
-    protected function _validateString(string $string): bool
32
-    {
33
-        $chars = preg_quote(" '()+,-./:=?]", '/');
34
-        return 0 == preg_match('/[^A-Za-z0-9' . $chars . ']/', $string);
35
-    }
28
+	/**
29
+	 * {@inheritdoc}
30
+	 */
31
+	protected function _validateString(string $string): bool
32
+	{
33
+		$chars = preg_quote(" '()+,-./:=?]", '/');
34
+		return 0 == preg_match('/[^A-Za-z0-9' . $chars . ']/', $string);
35
+	}
36 36
 }
Please login to merge, or discard this patch.
lib/ASN1/Type/Primitive/VisibleString.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -12,24 +12,24 @@
 block discarded – undo
12 12
  */
13 13
 class VisibleString extends PrimitiveString
14 14
 {
15
-    use UniversalClass;
15
+	use UniversalClass;
16 16
 
17
-    /**
18
-     * Constructor.
19
-     *
20
-     * @param string $string
21
-     */
22
-    public function __construct(string $string)
23
-    {
24
-        $this->_typeTag = self::TYPE_VISIBLE_STRING;
25
-        parent::__construct($string);
26
-    }
17
+	/**
18
+	 * Constructor.
19
+	 *
20
+	 * @param string $string
21
+	 */
22
+	public function __construct(string $string)
23
+	{
24
+		$this->_typeTag = self::TYPE_VISIBLE_STRING;
25
+		parent::__construct($string);
26
+	}
27 27
 
28
-    /**
29
-     * {@inheritdoc}
30
-     */
31
-    protected function _validateString(string $string): bool
32
-    {
33
-        return 0 == preg_match('/[^\x20-\x7e]/', $string);
34
-    }
28
+	/**
29
+	 * {@inheritdoc}
30
+	 */
31
+	protected function _validateString(string $string): bool
32
+	{
33
+		return 0 == preg_match('/[^\x20-\x7e]/', $string);
34
+	}
35 35
 }
Please login to merge, or discard this patch.