GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 662af5...44febf )
by Joni
02:17
created
lib/ASN1/Type/TaggedType.php 1 patch
Indentation   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -14,79 +14,79 @@
 block discarded – undo
14 14
  */
15 15
 abstract class TaggedType extends Element
16 16
 {
17
-    /**
18
-     * Check whether element supports explicit tagging.
19
-     *
20
-     * @param null|int $expectedTag Optional outer tag expectation
21
-     *
22
-     * @throws \UnexpectedValueException If expectation fails
23
-     *
24
-     * @return ExplicitTagging
25
-     */
26
-    public function expectExplicit(?int $expectedTag = null): ExplicitTagging
27
-    {
28
-        $el = $this;
29
-        if (!$el instanceof ExplicitTagging) {
30
-            throw new \UnexpectedValueException(
31
-                "Element doesn't implement explicit tagging.");
32
-        }
33
-        if (isset($expectedTag)) {
34
-            $el->expectTagged($expectedTag);
35
-        }
36
-        return $el;
37
-    }
17
+	/**
18
+	 * Check whether element supports explicit tagging.
19
+	 *
20
+	 * @param null|int $expectedTag Optional outer tag expectation
21
+	 *
22
+	 * @throws \UnexpectedValueException If expectation fails
23
+	 *
24
+	 * @return ExplicitTagging
25
+	 */
26
+	public function expectExplicit(?int $expectedTag = null): ExplicitTagging
27
+	{
28
+		$el = $this;
29
+		if (!$el instanceof ExplicitTagging) {
30
+			throw new \UnexpectedValueException(
31
+				"Element doesn't implement explicit tagging.");
32
+		}
33
+		if (isset($expectedTag)) {
34
+			$el->expectTagged($expectedTag);
35
+		}
36
+		return $el;
37
+	}
38 38
 
39
-    /**
40
-     * Get the wrapped inner element employing explicit tagging.
41
-     *
42
-     * @param null|int $expectedTag Optional outer tag expectation
43
-     *
44
-     * @throws \UnexpectedValueException If expectation fails
45
-     *
46
-     * @return UnspecifiedType
47
-     */
48
-    public function asExplicit(?int $expectedTag = null): UnspecifiedType
49
-    {
50
-        return $this->expectExplicit($expectedTag)->explicit();
51
-    }
39
+	/**
40
+	 * Get the wrapped inner element employing explicit tagging.
41
+	 *
42
+	 * @param null|int $expectedTag Optional outer tag expectation
43
+	 *
44
+	 * @throws \UnexpectedValueException If expectation fails
45
+	 *
46
+	 * @return UnspecifiedType
47
+	 */
48
+	public function asExplicit(?int $expectedTag = null): UnspecifiedType
49
+	{
50
+		return $this->expectExplicit($expectedTag)->explicit();
51
+	}
52 52
 
53
-    /**
54
-     * Check whether element supports implicit tagging.
55
-     *
56
-     * @param null|int $expectedTag Optional outer tag expectation
57
-     *
58
-     * @throws \UnexpectedValueException If expectation fails
59
-     *
60
-     * @return ImplicitTagging
61
-     */
62
-    public function expectImplicit(?int $expectedTag = null): ImplicitTagging
63
-    {
64
-        $el = $this;
65
-        if (!$el instanceof ImplicitTagging) {
66
-            throw new \UnexpectedValueException(
67
-                "Element doesn't implement implicit tagging.");
68
-        }
69
-        if (isset($expectedTag)) {
70
-            $el->expectTagged($expectedTag);
71
-        }
72
-        return $el;
73
-    }
53
+	/**
54
+	 * Check whether element supports implicit tagging.
55
+	 *
56
+	 * @param null|int $expectedTag Optional outer tag expectation
57
+	 *
58
+	 * @throws \UnexpectedValueException If expectation fails
59
+	 *
60
+	 * @return ImplicitTagging
61
+	 */
62
+	public function expectImplicit(?int $expectedTag = null): ImplicitTagging
63
+	{
64
+		$el = $this;
65
+		if (!$el instanceof ImplicitTagging) {
66
+			throw new \UnexpectedValueException(
67
+				"Element doesn't implement implicit tagging.");
68
+		}
69
+		if (isset($expectedTag)) {
70
+			$el->expectTagged($expectedTag);
71
+		}
72
+		return $el;
73
+	}
74 74
 
75
-    /**
76
-     * Get the wrapped inner element employing implicit tagging.
77
-     *
78
-     * @param int      $tag           Type tag of the inner element
79
-     * @param null|int $expectedTag   Optional outer tag expectation
80
-     * @param int      $expectedClass Optional inner type class expectation
81
-     *
82
-     * @throws \UnexpectedValueException If expectation fails
83
-     *
84
-     * @return UnspecifiedType
85
-     */
86
-    public function asImplicit(int $tag, ?int $expectedTag = null,
87
-        int $expectedClass = Identifier::CLASS_UNIVERSAL): UnspecifiedType
88
-    {
89
-        return $this->expectImplicit($expectedTag)->implicit($tag,
90
-            $expectedClass);
91
-    }
75
+	/**
76
+	 * Get the wrapped inner element employing implicit tagging.
77
+	 *
78
+	 * @param int      $tag           Type tag of the inner element
79
+	 * @param null|int $expectedTag   Optional outer tag expectation
80
+	 * @param int      $expectedClass Optional inner type class expectation
81
+	 *
82
+	 * @throws \UnexpectedValueException If expectation fails
83
+	 *
84
+	 * @return UnspecifiedType
85
+	 */
86
+	public function asImplicit(int $tag, ?int $expectedTag = null,
87
+		int $expectedClass = Identifier::CLASS_UNIVERSAL): UnspecifiedType
88
+	{
89
+		return $this->expectImplicit($expectedTag)->implicit($tag,
90
+			$expectedClass);
91
+	}
92 92
 }
Please login to merge, or discard this patch.
lib/ASN1/Type/Tagged/DERTaggedType.php 1 patch
Indentation   +120 added lines, -120 removed lines patch added patch discarded remove patch
@@ -23,135 +23,135 @@
 block discarded – undo
23 23
  */
24 24
 class DERTaggedType extends TaggedType implements ExplicitTagging, ImplicitTagging
25 25
 {
26
-    /**
27
-     * Identifier.
28
-     *
29
-     * @var Identifier
30
-     */
31
-    private $_identifier;
26
+	/**
27
+	 * Identifier.
28
+	 *
29
+	 * @var Identifier
30
+	 */
31
+	private $_identifier;
32 32
 
33
-    /**
34
-     * DER data.
35
-     *
36
-     * @var string
37
-     */
38
-    private $_data;
33
+	/**
34
+	 * DER data.
35
+	 *
36
+	 * @var string
37
+	 */
38
+	private $_data;
39 39
 
40
-    /**
41
-     * Offset to next byte after identifier.
42
-     *
43
-     * @var int
44
-     */
45
-    private $_offset;
40
+	/**
41
+	 * Offset to next byte after identifier.
42
+	 *
43
+	 * @var int
44
+	 */
45
+	private $_offset;
46 46
 
47
-    /**
48
-     * Offset to content.
49
-     *
50
-     * @var int
51
-     */
52
-    private $_valueOffset;
47
+	/**
48
+	 * Offset to content.
49
+	 *
50
+	 * @var int
51
+	 */
52
+	private $_valueOffset;
53 53
 
54
-    /**
55
-     * Length of the content.
56
-     *
57
-     * @var int
58
-     */
59
-    private $_valueLength;
54
+	/**
55
+	 * Length of the content.
56
+	 *
57
+	 * @var int
58
+	 */
59
+	private $_valueLength;
60 60
 
61
-    /**
62
-     * Constructor.
63
-     *
64
-     * @param Identifier $identifier   Pre-parsed identifier
65
-     * @param string     $data         DER data
66
-     * @param int        $offset       Offset to next byte after identifier
67
-     * @param int        $value_offset Offset to content
68
-     * @param int        $value_length Content length
69
-     */
70
-    public function __construct(Identifier $identifier, string $data,
71
-        int $offset, int $value_offset, int $value_length,
72
-        bool $indefinite_length)
73
-    {
74
-        $this->_identifier = $identifier;
75
-        $this->_data = $data;
76
-        $this->_offset = $offset;
77
-        $this->_valueOffset = $value_offset;
78
-        $this->_valueLength = $value_length;
79
-        $this->_indefiniteLength = $indefinite_length;
80
-        $this->_typeTag = $identifier->intTag();
81
-    }
61
+	/**
62
+	 * Constructor.
63
+	 *
64
+	 * @param Identifier $identifier   Pre-parsed identifier
65
+	 * @param string     $data         DER data
66
+	 * @param int        $offset       Offset to next byte after identifier
67
+	 * @param int        $value_offset Offset to content
68
+	 * @param int        $value_length Content length
69
+	 */
70
+	public function __construct(Identifier $identifier, string $data,
71
+		int $offset, int $value_offset, int $value_length,
72
+		bool $indefinite_length)
73
+	{
74
+		$this->_identifier = $identifier;
75
+		$this->_data = $data;
76
+		$this->_offset = $offset;
77
+		$this->_valueOffset = $value_offset;
78
+		$this->_valueLength = $value_length;
79
+		$this->_indefiniteLength = $indefinite_length;
80
+		$this->_typeTag = $identifier->intTag();
81
+	}
82 82
 
83
-    /**
84
-     * {@inheritdoc}
85
-     */
86
-    public function typeClass(): int
87
-    {
88
-        return $this->_identifier->typeClass();
89
-    }
83
+	/**
84
+	 * {@inheritdoc}
85
+	 */
86
+	public function typeClass(): int
87
+	{
88
+		return $this->_identifier->typeClass();
89
+	}
90 90
 
91
-    /**
92
-     * {@inheritdoc}
93
-     */
94
-    public function isConstructed(): bool
95
-    {
96
-        return $this->_identifier->isConstructed();
97
-    }
91
+	/**
92
+	 * {@inheritdoc}
93
+	 */
94
+	public function isConstructed(): bool
95
+	{
96
+		return $this->_identifier->isConstructed();
97
+	}
98 98
 
99
-    /**
100
-     * {@inheritdoc}
101
-     */
102
-    public function implicit(int $tag, int $class = Identifier::CLASS_UNIVERSAL): UnspecifiedType
103
-    {
104
-        $identifier = $this->_identifier->withClass($class)->withTag($tag);
105
-        $cls = self::_determineImplClass($identifier);
106
-        $idx = $this->_offset;
107
-        /** @var \Sop\ASN1\Feature\ElementBase $element */
108
-        $element = $cls::_decodeFromDER($identifier, $this->_data, $idx);
109
-        return $element->asUnspecified();
110
-    }
99
+	/**
100
+	 * {@inheritdoc}
101
+	 */
102
+	public function implicit(int $tag, int $class = Identifier::CLASS_UNIVERSAL): UnspecifiedType
103
+	{
104
+		$identifier = $this->_identifier->withClass($class)->withTag($tag);
105
+		$cls = self::_determineImplClass($identifier);
106
+		$idx = $this->_offset;
107
+		/** @var \Sop\ASN1\Feature\ElementBase $element */
108
+		$element = $cls::_decodeFromDER($identifier, $this->_data, $idx);
109
+		return $element->asUnspecified();
110
+	}
111 111
 
112
-    /**
113
-     * {@inheritdoc}
114
-     */
115
-    public function explicit(): UnspecifiedType
116
-    {
117
-        $idx = $this->_valueOffset;
118
-        return Element::fromDER($this->_data, $idx)->asUnspecified();
119
-    }
112
+	/**
113
+	 * {@inheritdoc}
114
+	 */
115
+	public function explicit(): UnspecifiedType
116
+	{
117
+		$idx = $this->_valueOffset;
118
+		return Element::fromDER($this->_data, $idx)->asUnspecified();
119
+	}
120 120
 
121
-    /**
122
-     * {@inheritdoc}
123
-     */
124
-    protected static function _decodeFromDER(Identifier $identifier,
125
-        string $data, int &$offset): ElementBase
126
-    {
127
-        $idx = $offset;
128
-        $length = Length::expectFromDER($data, $idx);
129
-        // offset to inner value
130
-        $value_offset = $idx;
131
-        if ($length->isIndefinite()) {
132
-            if ($identifier->isPrimitive()) {
133
-                throw new DecodeException(
134
-                    'Primitive type with indefinite length is not supported.');
135
-            }
136
-            while (!Element::fromDER($data, $idx)->isType(self::TYPE_EOC));
137
-            // EOC consists of two octets.
138
-            $value_length = $idx - $value_offset - 2;
139
-        } else {
140
-            $value_length = $length->intLength();
141
-            $idx += $value_length;
142
-        }
143
-        // late static binding since ApplicationType and PrivateType extend this class
144
-        $type = new static($identifier, $data, $offset, $value_offset,
145
-            $value_length, $length->isIndefinite());
146
-        $offset = $idx;
147
-        return $type;
148
-    }
121
+	/**
122
+	 * {@inheritdoc}
123
+	 */
124
+	protected static function _decodeFromDER(Identifier $identifier,
125
+		string $data, int &$offset): ElementBase
126
+	{
127
+		$idx = $offset;
128
+		$length = Length::expectFromDER($data, $idx);
129
+		// offset to inner value
130
+		$value_offset = $idx;
131
+		if ($length->isIndefinite()) {
132
+			if ($identifier->isPrimitive()) {
133
+				throw new DecodeException(
134
+					'Primitive type with indefinite length is not supported.');
135
+			}
136
+			while (!Element::fromDER($data, $idx)->isType(self::TYPE_EOC));
137
+			// EOC consists of two octets.
138
+			$value_length = $idx - $value_offset - 2;
139
+		} else {
140
+			$value_length = $length->intLength();
141
+			$idx += $value_length;
142
+		}
143
+		// late static binding since ApplicationType and PrivateType extend this class
144
+		$type = new static($identifier, $data, $offset, $value_offset,
145
+			$value_length, $length->isIndefinite());
146
+		$offset = $idx;
147
+		return $type;
148
+	}
149 149
 
150
-    /**
151
-     * {@inheritdoc}
152
-     */
153
-    protected function _encodedContentDER(): string
154
-    {
155
-        return substr($this->_data, $this->_valueOffset, $this->_valueLength);
156
-    }
150
+	/**
151
+	 * {@inheritdoc}
152
+	 */
153
+	protected function _encodedContentDER(): string
154
+	{
155
+		return substr($this->_data, $this->_valueOffset, $this->_valueLength);
156
+	}
157 157
 }
Please login to merge, or discard this patch.
lib/ASN1/Type/Tagged/ExplicitTagging.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -12,10 +12,10 @@
 block discarded – undo
12 12
  */
13 13
 interface ExplicitTagging extends ElementBase
14 14
 {
15
-    /**
16
-     * Get explicitly tagged wrapped element.
17
-     *
18
-     * @return UnspecifiedType
19
-     */
20
-    public function explicit(): UnspecifiedType;
15
+	/**
16
+	 * Get explicitly tagged wrapped element.
17
+	 *
18
+	 * @return UnspecifiedType
19
+	 */
20
+	public function explicit(): UnspecifiedType;
21 21
 }
Please login to merge, or discard this patch.
lib/ASN1/Type/Tagged/ExplicitlyTaggedType.php 1 patch
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -16,43 +16,43 @@
 block discarded – undo
16 16
  */
17 17
 class ExplicitlyTaggedType extends TaggedTypeWrap implements ExplicitTagging
18 18
 {
19
-    /**
20
-     * Constructor.
21
-     *
22
-     * @param int     $tag     Tag number
23
-     * @param Element $element Wrapped element
24
-     * @param int     $class   Type class
25
-     */
26
-    public function __construct(int $tag, Element $element,
27
-        int $class = Identifier::CLASS_CONTEXT_SPECIFIC)
28
-    {
29
-        $this->_typeTag = $tag;
30
-        $this->_element = $element;
31
-        $this->_class = $class;
32
-    }
19
+	/**
20
+	 * Constructor.
21
+	 *
22
+	 * @param int     $tag     Tag number
23
+	 * @param Element $element Wrapped element
24
+	 * @param int     $class   Type class
25
+	 */
26
+	public function __construct(int $tag, Element $element,
27
+		int $class = Identifier::CLASS_CONTEXT_SPECIFIC)
28
+	{
29
+		$this->_typeTag = $tag;
30
+		$this->_element = $element;
31
+		$this->_class = $class;
32
+	}
33 33
 
34
-    /**
35
-     * {@inheritdoc}
36
-     */
37
-    public function isConstructed(): bool
38
-    {
39
-        return true;
40
-    }
34
+	/**
35
+	 * {@inheritdoc}
36
+	 */
37
+	public function isConstructed(): bool
38
+	{
39
+		return true;
40
+	}
41 41
 
42
-    /**
43
-     * {@inheritdoc}
44
-     */
45
-    public function explicit(): UnspecifiedType
46
-    {
47
-        return $this->_element->asUnspecified();
48
-    }
42
+	/**
43
+	 * {@inheritdoc}
44
+	 */
45
+	public function explicit(): UnspecifiedType
46
+	{
47
+		return $this->_element->asUnspecified();
48
+	}
49 49
 
50
-    /**
51
-     * {@inheritdoc}
52
-     */
53
-    protected function _encodedContentDER(): string
54
-    {
55
-        // get the full encoding of the wrapped element
56
-        return $this->_element->toDER();
57
-    }
50
+	/**
51
+	 * {@inheritdoc}
52
+	 */
53
+	protected function _encodedContentDER(): string
54
+	{
55
+		// get the full encoding of the wrapped element
56
+		return $this->_element->toDER();
57
+	}
58 58
 }
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/Tagged/ImplicitlyTaggedType.php 1 patch
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -17,52 +17,52 @@
 block discarded – undo
17 17
  */
18 18
 class ImplicitlyTaggedType extends TaggedTypeWrap implements ImplicitTagging
19 19
 {
20
-    /**
21
-     * Constructor.
22
-     *
23
-     * @param int     $tag     Tag number
24
-     * @param Element $element Wrapped element
25
-     * @param int     $class   Type class
26
-     */
27
-    public function __construct(int $tag, Element $element,
28
-        int $class = Identifier::CLASS_CONTEXT_SPECIFIC)
29
-    {
30
-        $this->_typeTag = $tag;
31
-        $this->_element = $element;
32
-        $this->_class = $class;
33
-    }
20
+	/**
21
+	 * Constructor.
22
+	 *
23
+	 * @param int     $tag     Tag number
24
+	 * @param Element $element Wrapped element
25
+	 * @param int     $class   Type class
26
+	 */
27
+	public function __construct(int $tag, Element $element,
28
+		int $class = Identifier::CLASS_CONTEXT_SPECIFIC)
29
+	{
30
+		$this->_typeTag = $tag;
31
+		$this->_element = $element;
32
+		$this->_class = $class;
33
+	}
34 34
 
35
-    /**
36
-     * {@inheritdoc}
37
-     */
38
-    public function isConstructed(): bool
39
-    {
40
-        // depends on the underlying type
41
-        return $this->_element->isConstructed();
42
-    }
35
+	/**
36
+	 * {@inheritdoc}
37
+	 */
38
+	public function isConstructed(): bool
39
+	{
40
+		// depends on the underlying type
41
+		return $this->_element->isConstructed();
42
+	}
43 43
 
44
-    /**
45
-     * {@inheritdoc}
46
-     */
47
-    public function implicit(
48
-        int $tag, int $class = Identifier::CLASS_UNIVERSAL): UnspecifiedType
49
-    {
50
-        $this->_element->expectType($tag);
51
-        if ($this->_element->typeClass() !== $class) {
52
-            throw new \UnexpectedValueException(
53
-                sprintf('Type class %s expected, got %s.',
54
-                    Identifier::classToName($class),
55
-                    Identifier::classToName($this->_element->typeClass())));
56
-        }
57
-        return $this->_element->asUnspecified();
58
-    }
44
+	/**
45
+	 * {@inheritdoc}
46
+	 */
47
+	public function implicit(
48
+		int $tag, int $class = Identifier::CLASS_UNIVERSAL): UnspecifiedType
49
+	{
50
+		$this->_element->expectType($tag);
51
+		if ($this->_element->typeClass() !== $class) {
52
+			throw new \UnexpectedValueException(
53
+				sprintf('Type class %s expected, got %s.',
54
+					Identifier::classToName($class),
55
+					Identifier::classToName($this->_element->typeClass())));
56
+		}
57
+		return $this->_element->asUnspecified();
58
+	}
59 59
 
60
-    /**
61
-     * {@inheritdoc}
62
-     */
63
-    protected function _encodedContentDER(): string
64
-    {
65
-        // get only the content of the wrapped element.
66
-        return $this->_element->_encodedContentDER();
67
-    }
60
+	/**
61
+	 * {@inheritdoc}
62
+	 */
63
+	protected function _encodedContentDER(): string
64
+	{
65
+		// get only the content of the wrapped element.
66
+		return $this->_element->_encodedContentDER();
67
+	}
68 68
 }
Please login to merge, or discard this patch.
lib/ASN1/Type/Tagged/TaggedTypeWrap.php 1 patch
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -11,25 +11,25 @@
 block discarded – undo
11 11
  */
12 12
 abstract class TaggedTypeWrap extends TaggedType
13 13
 {
14
-    /**
15
-     * Wrapped element.
16
-     *
17
-     * @var \Sop\ASN1\Element
18
-     */
19
-    protected $_element;
14
+	/**
15
+	 * Wrapped element.
16
+	 *
17
+	 * @var \Sop\ASN1\Element
18
+	 */
19
+	protected $_element;
20 20
 
21
-    /**
22
-     * Type class.
23
-     *
24
-     * @var int
25
-     */
26
-    protected $_class;
21
+	/**
22
+	 * Type class.
23
+	 *
24
+	 * @var int
25
+	 */
26
+	protected $_class;
27 27
 
28
-    /**
29
-     * {@inheritdoc}
30
-     */
31
-    public function typeClass(): int
32
-    {
33
-        return $this->_class;
34
-    }
28
+	/**
29
+	 * {@inheritdoc}
30
+	 */
31
+	public function typeClass(): int
32
+	{
33
+		return $this->_class;
34
+	}
35 35
 }
Please login to merge, or discard this patch.
lib/ASN1/Type/Primitive/Real.php 1 patch
Indentation   +255 added lines, -255 removed lines patch added patch discarded remove patch
@@ -17,276 +17,276 @@
 block discarded – undo
17 17
  */
18 18
 class Real extends Element
19 19
 {
20
-    use UniversalClass;
21
-    use PrimitiveType;
20
+	use UniversalClass;
21
+	use PrimitiveType;
22 22
 
23
-    /**
24
-     * Regex pattern to parse NR3 form number conforming to DER.
25
-     *
26
-     * @var string
27
-     */
28
-    const NR3_REGEX = '/^(-?)(\d+)?\.E([+\-]?\d+)$/';
23
+	/**
24
+	 * Regex pattern to parse NR3 form number conforming to DER.
25
+	 *
26
+	 * @var string
27
+	 */
28
+	const NR3_REGEX = '/^(-?)(\d+)?\.E([+\-]?\d+)$/';
29 29
 
30
-    /**
31
-     * Regex pattern to parse PHP exponent number format.
32
-     *
33
-     * @see http://php.net/manual/en/language.types.float.php
34
-     *
35
-     * @var string
36
-     */
37
-    const PHP_EXPONENT_DNUM = '/^' .
38
-        '([+\-]?' . // sign
39
-        '(?:' .
40
-            '\d+' . // LNUM
41
-            '|' .
42
-            '(?:\d*\.\d+|\d+\.\d*)' . // DNUM
43
-        '))[eE]' .
44
-        '([+\-]?\d+)' . // exponent
45
-    '$/';
30
+	/**
31
+	 * Regex pattern to parse PHP exponent number format.
32
+	 *
33
+	 * @see http://php.net/manual/en/language.types.float.php
34
+	 *
35
+	 * @var string
36
+	 */
37
+	const PHP_EXPONENT_DNUM = '/^' .
38
+		'([+\-]?' . // sign
39
+		'(?:' .
40
+			'\d+' . // LNUM
41
+			'|' .
42
+			'(?:\d*\.\d+|\d+\.\d*)' . // DNUM
43
+		'))[eE]' .
44
+		'([+\-]?\d+)' . // exponent
45
+	'$/';
46 46
 
47
-    /**
48
-     * Number zero represented in NR3 form.
49
-     *
50
-     * @var string
51
-     */
52
-    const NR3_ZERO = '.E+0';
47
+	/**
48
+	 * Number zero represented in NR3 form.
49
+	 *
50
+	 * @var string
51
+	 */
52
+	const NR3_ZERO = '.E+0';
53 53
 
54
-    /**
55
-     * Number in NR3 form.
56
-     *
57
-     * @var string
58
-     */
59
-    private $_number;
54
+	/**
55
+	 * Number in NR3 form.
56
+	 *
57
+	 * @var string
58
+	 */
59
+	private $_number;
60 60
 
61
-    /**
62
-     * Constructor.
63
-     *
64
-     * @param string $number number in NR3 form
65
-     */
66
-    public function __construct(string $number)
67
-    {
68
-        $this->_typeTag = self::TYPE_REAL;
69
-        if (!self::_validateNumber($number)) {
70
-            throw new \InvalidArgumentException(
71
-                "'{$number}' is not a valid NR3 form real.");
72
-        }
73
-        $this->_number = $number;
74
-    }
61
+	/**
62
+	 * Constructor.
63
+	 *
64
+	 * @param string $number number in NR3 form
65
+	 */
66
+	public function __construct(string $number)
67
+	{
68
+		$this->_typeTag = self::TYPE_REAL;
69
+		if (!self::_validateNumber($number)) {
70
+			throw new \InvalidArgumentException(
71
+				"'{$number}' is not a valid NR3 form real.");
72
+		}
73
+		$this->_number = $number;
74
+	}
75 75
 
76
-    /**
77
-     * Initialize from float.
78
-     *
79
-     * @param float $number
80
-     *
81
-     * @return self
82
-     */
83
-    public static function fromFloat(float $number): self
84
-    {
85
-        return new self(self::_decimalToNR3(strval($number)));
86
-    }
76
+	/**
77
+	 * Initialize from float.
78
+	 *
79
+	 * @param float $number
80
+	 *
81
+	 * @return self
82
+	 */
83
+	public static function fromFloat(float $number): self
84
+	{
85
+		return new self(self::_decimalToNR3(strval($number)));
86
+	}
87 87
 
88
-    /**
89
-     * Get number as a float.
90
-     *
91
-     * @return float
92
-     */
93
-    public function float(): float
94
-    {
95
-        return self::_nr3ToDecimal($this->_number);
96
-    }
88
+	/**
89
+	 * Get number as a float.
90
+	 *
91
+	 * @return float
92
+	 */
93
+	public function float(): float
94
+	{
95
+		return self::_nr3ToDecimal($this->_number);
96
+	}
97 97
 
98
-    /**
99
-     * {@inheritdoc}
100
-     */
101
-    protected function _encodedContentDER(): string
102
-    {
103
-        /* if the real value is the value zero, there shall be no contents
98
+	/**
99
+	 * {@inheritdoc}
100
+	 */
101
+	protected function _encodedContentDER(): string
102
+	{
103
+		/* if the real value is the value zero, there shall be no contents
104 104
          octets in the encoding. (X.690 07-2002, section 8.5.2) */
105
-        if (self::NR3_ZERO === $this->_number) {
106
-            return '';
107
-        }
108
-        // encode in NR3 decimal encoding
109
-        return chr(0x03) . $this->_number;
110
-    }
105
+		if (self::NR3_ZERO === $this->_number) {
106
+			return '';
107
+		}
108
+		// encode in NR3 decimal encoding
109
+		return chr(0x03) . $this->_number;
110
+	}
111 111
 
112
-    /**
113
-     * {@inheritdoc}
114
-     */
115
-    protected static function _decodeFromDER(Identifier $identifier,
116
-        string $data, int &$offset): ElementBase
117
-    {
118
-        $idx = $offset;
119
-        $length = Length::expectFromDER($data, $idx)->intLength();
120
-        // if length is zero, value is zero (spec 8.5.2)
121
-        if (!$length) {
122
-            $obj = new self(self::NR3_ZERO);
123
-        } else {
124
-            $bytes = substr($data, $idx, $length);
125
-            $byte = ord($bytes[0]);
126
-            if (0x80 & $byte) { // bit 8 = 1
127
-                $obj = self::_decodeBinaryEncoding($bytes);
128
-            } elseif (0x00 === $byte >> 6) { // bit 8 = 0, bit 7 = 0
129
-                $obj = self::_decodeDecimalEncoding($bytes);
130
-            } else { // bit 8 = 0, bit 7 = 1
131
-                $obj = self::_decodeSpecialRealValue($bytes);
132
-            }
133
-        }
134
-        $offset = $idx + $length;
135
-        return $obj;
136
-    }
112
+	/**
113
+	 * {@inheritdoc}
114
+	 */
115
+	protected static function _decodeFromDER(Identifier $identifier,
116
+		string $data, int &$offset): ElementBase
117
+	{
118
+		$idx = $offset;
119
+		$length = Length::expectFromDER($data, $idx)->intLength();
120
+		// if length is zero, value is zero (spec 8.5.2)
121
+		if (!$length) {
122
+			$obj = new self(self::NR3_ZERO);
123
+		} else {
124
+			$bytes = substr($data, $idx, $length);
125
+			$byte = ord($bytes[0]);
126
+			if (0x80 & $byte) { // bit 8 = 1
127
+				$obj = self::_decodeBinaryEncoding($bytes);
128
+			} elseif (0x00 === $byte >> 6) { // bit 8 = 0, bit 7 = 0
129
+				$obj = self::_decodeDecimalEncoding($bytes);
130
+			} else { // bit 8 = 0, bit 7 = 1
131
+				$obj = self::_decodeSpecialRealValue($bytes);
132
+			}
133
+		}
134
+		$offset = $idx + $length;
135
+		return $obj;
136
+	}
137 137
 
138
-    /**
139
-     * @todo Implement
140
-     *
141
-     * @param string $data
142
-     */
143
-    protected static function _decodeBinaryEncoding(string $data)
144
-    {
145
-        throw new \RuntimeException(
146
-            'Binary encoding of REAL is not implemented.');
147
-    }
138
+	/**
139
+	 * @todo Implement
140
+	 *
141
+	 * @param string $data
142
+	 */
143
+	protected static function _decodeBinaryEncoding(string $data)
144
+	{
145
+		throw new \RuntimeException(
146
+			'Binary encoding of REAL is not implemented.');
147
+	}
148 148
 
149
-    /**
150
-     * @param string $data
151
-     *
152
-     * @throws \RuntimeException
153
-     *
154
-     * @return self
155
-     */
156
-    protected static function _decodeDecimalEncoding(string $data): self
157
-    {
158
-        $nr = ord($data[0]) & 0x03;
159
-        if (0x03 !== $nr) {
160
-            throw new \RuntimeException('Only NR3 form supported.');
161
-        }
162
-        $str = substr($data, 1);
163
-        return new self($str);
164
-    }
149
+	/**
150
+	 * @param string $data
151
+	 *
152
+	 * @throws \RuntimeException
153
+	 *
154
+	 * @return self
155
+	 */
156
+	protected static function _decodeDecimalEncoding(string $data): self
157
+	{
158
+		$nr = ord($data[0]) & 0x03;
159
+		if (0x03 !== $nr) {
160
+			throw new \RuntimeException('Only NR3 form supported.');
161
+		}
162
+		$str = substr($data, 1);
163
+		return new self($str);
164
+	}
165 165
 
166
-    /**
167
-     * @todo Implement
168
-     *
169
-     * @param string $data
170
-     */
171
-    protected static function _decodeSpecialRealValue(string $data)
172
-    {
173
-        if (1 !== strlen($data)) {
174
-            throw new DecodeException(
175
-                'SpecialRealValue must have one content octet.');
176
-        }
177
-        $byte = ord($data[0]);
178
-        if (0x40 === $byte) { // positive infinity
179
-            throw new \RuntimeException('PLUS-INFINITY not supported.');
180
-        }
181
-        if (0x41 === $byte) { // negative infinity
182
-            throw new \RuntimeException('MINUS-INFINITY not supported.');
183
-        }
184
-        throw new DecodeException('Invalid SpecialRealValue encoding.');
185
-    }
166
+	/**
167
+	 * @todo Implement
168
+	 *
169
+	 * @param string $data
170
+	 */
171
+	protected static function _decodeSpecialRealValue(string $data)
172
+	{
173
+		if (1 !== strlen($data)) {
174
+			throw new DecodeException(
175
+				'SpecialRealValue must have one content octet.');
176
+		}
177
+		$byte = ord($data[0]);
178
+		if (0x40 === $byte) { // positive infinity
179
+			throw new \RuntimeException('PLUS-INFINITY not supported.');
180
+		}
181
+		if (0x41 === $byte) { // negative infinity
182
+			throw new \RuntimeException('MINUS-INFINITY not supported.');
183
+		}
184
+		throw new DecodeException('Invalid SpecialRealValue encoding.');
185
+	}
186 186
 
187
-    /**
188
-     * Convert decimal number string to NR3 form.
189
-     *
190
-     * @param string $str
191
-     *
192
-     * @return string
193
-     */
194
-    private static function _decimalToNR3(string $str): string
195
-    {
196
-        // if number is in exponent form
197
-        /** @var string[] $match */
198
-        if (preg_match(self::PHP_EXPONENT_DNUM, $str, $match)) {
199
-            $parts = explode('.', $match[1]);
200
-            $m = ltrim($parts[0], '0');
201
-            $e = intval($match[2]);
202
-            // if mantissa had decimals
203
-            if (2 === count($parts)) {
204
-                $d = rtrim($parts[1], '0');
205
-                $e -= strlen($d);
206
-                $m .= $d;
207
-            }
208
-        } else {
209
-            // explode from decimal
210
-            $parts = explode('.', $str);
211
-            $m = ltrim($parts[0], '0');
212
-            // if number had decimals
213
-            if (2 === count($parts)) {
214
-                // exponent is negative number of the decimals
215
-                $e = -strlen($parts[1]);
216
-                // append decimals to the mantissa
217
-                $m .= $parts[1];
218
-            } else {
219
-                $e = 0;
220
-            }
221
-            // shift trailing zeroes from the mantissa to the exponent
222
-            while ('0' === substr($m, -1)) {
223
-                ++$e;
224
-                $m = substr($m, 0, -1);
225
-            }
226
-        }
227
-        /* if exponent is zero, it must be prefixed with a "+" sign
187
+	/**
188
+	 * Convert decimal number string to NR3 form.
189
+	 *
190
+	 * @param string $str
191
+	 *
192
+	 * @return string
193
+	 */
194
+	private static function _decimalToNR3(string $str): string
195
+	{
196
+		// if number is in exponent form
197
+		/** @var string[] $match */
198
+		if (preg_match(self::PHP_EXPONENT_DNUM, $str, $match)) {
199
+			$parts = explode('.', $match[1]);
200
+			$m = ltrim($parts[0], '0');
201
+			$e = intval($match[2]);
202
+			// if mantissa had decimals
203
+			if (2 === count($parts)) {
204
+				$d = rtrim($parts[1], '0');
205
+				$e -= strlen($d);
206
+				$m .= $d;
207
+			}
208
+		} else {
209
+			// explode from decimal
210
+			$parts = explode('.', $str);
211
+			$m = ltrim($parts[0], '0');
212
+			// if number had decimals
213
+			if (2 === count($parts)) {
214
+				// exponent is negative number of the decimals
215
+				$e = -strlen($parts[1]);
216
+				// append decimals to the mantissa
217
+				$m .= $parts[1];
218
+			} else {
219
+				$e = 0;
220
+			}
221
+			// shift trailing zeroes from the mantissa to the exponent
222
+			while ('0' === substr($m, -1)) {
223
+				++$e;
224
+				$m = substr($m, 0, -1);
225
+			}
226
+		}
227
+		/* if exponent is zero, it must be prefixed with a "+" sign
228 228
          (X.690 07-2002, section 11.3.2.6) */
229
-        if (0 === $e) {
230
-            $es = '+';
231
-        } else {
232
-            $es = $e < 0 ? '-' : '';
233
-        }
234
-        return sprintf('%s.E%s%d', $m, $es, abs($e));
235
-    }
229
+		if (0 === $e) {
230
+			$es = '+';
231
+		} else {
232
+			$es = $e < 0 ? '-' : '';
233
+		}
234
+		return sprintf('%s.E%s%d', $m, $es, abs($e));
235
+	}
236 236
 
237
-    /**
238
-     * Convert NR3 form number to decimal.
239
-     *
240
-     * @param string $str
241
-     *
242
-     * @throws \UnexpectedValueException
243
-     *
244
-     * @return float
245
-     */
246
-    private static function _nr3ToDecimal(string $str): float
247
-    {
248
-        /** @var string[] $match */
249
-        if (!preg_match(self::NR3_REGEX, $str, $match)) {
250
-            throw new \UnexpectedValueException(
251
-                "'{$str}' is not a valid NR3 form real.");
252
-        }
253
-        $m = $match[2];
254
-        // if number started with minus sign
255
-        $inv = '-' === $match[1];
256
-        $e = intval($match[3]);
257
-        // positive exponent
258
-        if ($e > 0) {
259
-            // pad with trailing zeroes
260
-            $num = $m . str_repeat('0', $e);
261
-        } elseif ($e < 0) {
262
-            // pad with leading zeroes
263
-            if (strlen($m) < abs($e)) {
264
-                $m = str_repeat('0', intval(abs($e)) - strlen($m)) . $m;
265
-            }
266
-            // insert decimal point
267
-            $num = substr($m, 0, $e) . '.' . substr($m, $e);
268
-        } else {
269
-            $num = empty($m) ? '0' : $m;
270
-        }
271
-        // if number is negative
272
-        if ($inv) {
273
-            $num = "-{$num}";
274
-        }
275
-        return floatval($num);
276
-    }
237
+	/**
238
+	 * Convert NR3 form number to decimal.
239
+	 *
240
+	 * @param string $str
241
+	 *
242
+	 * @throws \UnexpectedValueException
243
+	 *
244
+	 * @return float
245
+	 */
246
+	private static function _nr3ToDecimal(string $str): float
247
+	{
248
+		/** @var string[] $match */
249
+		if (!preg_match(self::NR3_REGEX, $str, $match)) {
250
+			throw new \UnexpectedValueException(
251
+				"'{$str}' is not a valid NR3 form real.");
252
+		}
253
+		$m = $match[2];
254
+		// if number started with minus sign
255
+		$inv = '-' === $match[1];
256
+		$e = intval($match[3]);
257
+		// positive exponent
258
+		if ($e > 0) {
259
+			// pad with trailing zeroes
260
+			$num = $m . str_repeat('0', $e);
261
+		} elseif ($e < 0) {
262
+			// pad with leading zeroes
263
+			if (strlen($m) < abs($e)) {
264
+				$m = str_repeat('0', intval(abs($e)) - strlen($m)) . $m;
265
+			}
266
+			// insert decimal point
267
+			$num = substr($m, 0, $e) . '.' . substr($m, $e);
268
+		} else {
269
+			$num = empty($m) ? '0' : $m;
270
+		}
271
+		// if number is negative
272
+		if ($inv) {
273
+			$num = "-{$num}";
274
+		}
275
+		return floatval($num);
276
+	}
277 277
 
278
-    /**
279
-     * Test that number is valid for this context.
280
-     *
281
-     * @param mixed $num
282
-     *
283
-     * @return bool
284
-     */
285
-    private static function _validateNumber($num): bool
286
-    {
287
-        if (!preg_match(self::NR3_REGEX, $num)) {
288
-            return false;
289
-        }
290
-        return true;
291
-    }
278
+	/**
279
+	 * Test that number is valid for this context.
280
+	 *
281
+	 * @param mixed $num
282
+	 *
283
+	 * @return bool
284
+	 */
285
+	private static function _validateNumber($num): bool
286
+	{
287
+		if (!preg_match(self::NR3_REGEX, $num)) {
288
+			return false;
289
+		}
290
+		return true;
291
+	}
292 292
 }
Please login to merge, or discard this patch.