Passed
Push — master ( d10e8c...c6bdb0 )
by Joni
03:28
created
lib/X501/ASN1/AttributeValue/Feature/PrintableStringValue.php 2 patches
Indentation   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -17,72 +17,72 @@
 block discarded – undo
17 17
  */
18 18
 abstract class PrintableStringValue extends AttributeValue
19 19
 {
20
-    /**
21
-     * String value.
22
-     *
23
-     * @var string
24
-     */
25
-    protected $_string;
20
+	/**
21
+	 * String value.
22
+	 *
23
+	 * @var string
24
+	 */
25
+	protected $_string;
26 26
 
27
-    /**
28
-     * Constructor.
29
-     *
30
-     * @param string $value String value
31
-     */
32
-    public function __construct(string $value)
33
-    {
34
-        $this->_string = $value;
35
-    }
27
+	/**
28
+	 * Constructor.
29
+	 *
30
+	 * @param string $value String value
31
+	 */
32
+	public function __construct(string $value)
33
+	{
34
+		$this->_string = $value;
35
+	}
36 36
 
37
-    /**
38
-     * {@inheritdoc}
39
-     *
40
-     * @return self
41
-     */
42
-    public static function fromASN1(UnspecifiedType $el): AttributeValue
43
-    {
44
-        return new static($el->asPrintableString()->string());
45
-    }
37
+	/**
38
+	 * {@inheritdoc}
39
+	 *
40
+	 * @return self
41
+	 */
42
+	public static function fromASN1(UnspecifiedType $el): AttributeValue
43
+	{
44
+		return new static($el->asPrintableString()->string());
45
+	}
46 46
 
47
-    /**
48
-     * {@inheritdoc}
49
-     */
50
-    public function toASN1(): Element
51
-    {
52
-        return new PrintableString($this->_string);
53
-    }
47
+	/**
48
+	 * {@inheritdoc}
49
+	 */
50
+	public function toASN1(): Element
51
+	{
52
+		return new PrintableString($this->_string);
53
+	}
54 54
 
55
-    /**
56
-     * {@inheritdoc}
57
-     */
58
-    public function stringValue(): string
59
-    {
60
-        return $this->_string;
61
-    }
55
+	/**
56
+	 * {@inheritdoc}
57
+	 */
58
+	public function stringValue(): string
59
+	{
60
+		return $this->_string;
61
+	}
62 62
 
63
-    /**
64
-     * {@inheritdoc}
65
-     */
66
-    public function equalityMatchingRule(): MatchingRule
67
-    {
68
-        // default to caseIgnoreMatch
69
-        return new CaseIgnoreMatch(Element::TYPE_PRINTABLE_STRING);
70
-    }
63
+	/**
64
+	 * {@inheritdoc}
65
+	 */
66
+	public function equalityMatchingRule(): MatchingRule
67
+	{
68
+		// default to caseIgnoreMatch
69
+		return new CaseIgnoreMatch(Element::TYPE_PRINTABLE_STRING);
70
+	}
71 71
 
72
-    /**
73
-     * {@inheritdoc}
74
-     */
75
-    public function rfc2253String(): string
76
-    {
77
-        return DNParser::escapeString($this->_transcodedString());
78
-    }
72
+	/**
73
+	 * {@inheritdoc}
74
+	 */
75
+	public function rfc2253String(): string
76
+	{
77
+		return DNParser::escapeString($this->_transcodedString());
78
+	}
79 79
 
80
-    /**
81
-     * {@inheritdoc}
82
-     */
83
-    protected function _transcodedString(): string
84
-    {
85
-        // PrintableString maps directly to UTF-8
86
-        return $this->_string;
87
-    }
80
+	/**
81
+	 * {@inheritdoc}
82
+	 */
83
+	protected function _transcodedString(): string
84
+	{
85
+		// PrintableString maps directly to UTF-8
86
+		return $this->_string;
87
+	}
88 88
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Sop\X501\ASN1\AttributeValue\Feature;
6 6
 
Please login to merge, or discard this patch.
lib/X501/ASN1/AttributeValue/SurnameValue.php 2 patches
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -14,16 +14,16 @@
 block discarded – undo
14 14
  */
15 15
 class SurnameValue extends DirectoryString
16 16
 {
17
-    /**
18
-     * Constructor.
19
-     *
20
-     * @param string $value      String value
21
-     * @param int    $string_tag Syntax choice
22
-     */
23
-    public function __construct(string $value,
24
-        int $string_tag = DirectoryString::UTF8)
25
-    {
26
-        $this->_oid = AttributeType::OID_SURNAME;
27
-        parent::__construct($value, $string_tag);
28
-    }
17
+	/**
18
+	 * Constructor.
19
+	 *
20
+	 * @param string $value      String value
21
+	 * @param int    $string_tag Syntax choice
22
+	 */
23
+	public function __construct(string $value,
24
+		int $string_tag = DirectoryString::UTF8)
25
+	{
26
+		$this->_oid = AttributeType::OID_SURNAME;
27
+		parent::__construct($value, $string_tag);
28
+	}
29 29
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Sop\X501\ASN1\AttributeValue;
6 6
 
Please login to merge, or discard this patch.
lib/X501/ASN1/AttributeValue/UnknownAttributeValue.php 2 patches
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -13,63 +13,63 @@
 block discarded – undo
13 13
  */
14 14
 class UnknownAttributeValue extends AttributeValue
15 15
 {
16
-    /**
17
-     * ASN.1 element.
18
-     *
19
-     * @var Element
20
-     */
21
-    protected $_element;
16
+	/**
17
+	 * ASN.1 element.
18
+	 *
19
+	 * @var Element
20
+	 */
21
+	protected $_element;
22 22
 
23
-    /**
24
-     * Constructor.
25
-     *
26
-     * @param string  $oid
27
-     * @param Element $el
28
-     */
29
-    public function __construct(string $oid, Element $el)
30
-    {
31
-        $this->_oid = $oid;
32
-        $this->_element = $el;
33
-    }
23
+	/**
24
+	 * Constructor.
25
+	 *
26
+	 * @param string  $oid
27
+	 * @param Element $el
28
+	 */
29
+	public function __construct(string $oid, Element $el)
30
+	{
31
+		$this->_oid = $oid;
32
+		$this->_element = $el;
33
+	}
34 34
 
35
-    /**
36
-     * {@inheritdoc}
37
-     */
38
-    public function toASN1(): Element
39
-    {
40
-        return $this->_element;
41
-    }
35
+	/**
36
+	 * {@inheritdoc}
37
+	 */
38
+	public function toASN1(): Element
39
+	{
40
+		return $this->_element;
41
+	}
42 42
 
43
-    /**
44
-     * {@inheritdoc}
45
-     */
46
-    public function stringValue(): string
47
-    {
48
-        // return DER encoding as a hexstring
49
-        return '#' . bin2hex($this->_element->toDER());
50
-    }
43
+	/**
44
+	 * {@inheritdoc}
45
+	 */
46
+	public function stringValue(): string
47
+	{
48
+		// return DER encoding as a hexstring
49
+		return '#' . bin2hex($this->_element->toDER());
50
+	}
51 51
 
52
-    /**
53
-     * {@inheritdoc}
54
-     */
55
-    public function equalityMatchingRule(): MatchingRule
56
-    {
57
-        return new BinaryMatch();
58
-    }
52
+	/**
53
+	 * {@inheritdoc}
54
+	 */
55
+	public function equalityMatchingRule(): MatchingRule
56
+	{
57
+		return new BinaryMatch();
58
+	}
59 59
 
60
-    /**
61
-     * {@inheritdoc}
62
-     */
63
-    public function rfc2253String(): string
64
-    {
65
-        return $this->stringValue();
66
-    }
60
+	/**
61
+	 * {@inheritdoc}
62
+	 */
63
+	public function rfc2253String(): string
64
+	{
65
+		return $this->stringValue();
66
+	}
67 67
 
68
-    /**
69
-     * {@inheritdoc}
70
-     */
71
-    protected function _transcodedString(): string
72
-    {
73
-        return $this->stringValue();
74
-    }
68
+	/**
69
+	 * {@inheritdoc}
70
+	 */
71
+	protected function _transcodedString(): string
72
+	{
73
+		return $this->stringValue();
74
+	}
75 75
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Sop\X501\ASN1\AttributeValue;
6 6
 
Please login to merge, or discard this patch.
lib/X501/ASN1/AttributeValue/PseudonymValue.php 2 patches
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -14,16 +14,16 @@
 block discarded – undo
14 14
  */
15 15
 class PseudonymValue extends DirectoryString
16 16
 {
17
-    /**
18
-     * Constructor.
19
-     *
20
-     * @param string $value      String value
21
-     * @param int    $string_tag Syntax choice
22
-     */
23
-    public function __construct(string $value,
24
-        int $string_tag = DirectoryString::UTF8)
25
-    {
26
-        $this->_oid = AttributeType::OID_PSEUDONYM;
27
-        parent::__construct($value, $string_tag);
28
-    }
17
+	/**
18
+	 * Constructor.
19
+	 *
20
+	 * @param string $value      String value
21
+	 * @param int    $string_tag Syntax choice
22
+	 */
23
+	public function __construct(string $value,
24
+		int $string_tag = DirectoryString::UTF8)
25
+	{
26
+		$this->_oid = AttributeType::OID_PSEUDONYM;
27
+		parent::__construct($value, $string_tag);
28
+	}
29 29
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Sop\X501\ASN1\AttributeValue;
6 6
 
Please login to merge, or discard this patch.
lib/X501/ASN1/AttributeValue/StateOrProvinceNameValue.php 2 patches
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -14,16 +14,16 @@
 block discarded – undo
14 14
  */
15 15
 class StateOrProvinceNameValue extends DirectoryString
16 16
 {
17
-    /**
18
-     * Constructor.
19
-     *
20
-     * @param string $value      String value
21
-     * @param int    $string_tag Syntax choice
22
-     */
23
-    public function __construct(string $value,
24
-        int $string_tag = DirectoryString::UTF8)
25
-    {
26
-        $this->_oid = AttributeType::OID_STATE_OR_PROVINCE_NAME;
27
-        parent::__construct($value, $string_tag);
28
-    }
17
+	/**
18
+	 * Constructor.
19
+	 *
20
+	 * @param string $value      String value
21
+	 * @param int    $string_tag Syntax choice
22
+	 */
23
+	public function __construct(string $value,
24
+		int $string_tag = DirectoryString::UTF8)
25
+	{
26
+		$this->_oid = AttributeType::OID_STATE_OR_PROVINCE_NAME;
27
+		parent::__construct($value, $string_tag);
28
+	}
29 29
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Sop\X501\ASN1\AttributeValue;
6 6
 
Please login to merge, or discard this patch.
lib/X501/ASN1/Feature/TypedAttribute.php 2 patches
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -11,30 +11,30 @@
 block discarded – undo
11 11
  */
12 12
 trait TypedAttribute
13 13
 {
14
-    /**
15
-     * Attribute type.
16
-     *
17
-     * @var AttributeType
18
-     */
19
-    protected $_type;
14
+	/**
15
+	 * Attribute type.
16
+	 *
17
+	 * @var AttributeType
18
+	 */
19
+	protected $_type;
20 20
 
21
-    /**
22
-     * Get attribute type.
23
-     *
24
-     * @return AttributeType
25
-     */
26
-    public function type(): AttributeType
27
-    {
28
-        return $this->_type;
29
-    }
21
+	/**
22
+	 * Get attribute type.
23
+	 *
24
+	 * @return AttributeType
25
+	 */
26
+	public function type(): AttributeType
27
+	{
28
+		return $this->_type;
29
+	}
30 30
 
31
-    /**
32
-     * Get OID of the attribute.
33
-     *
34
-     * @return string
35
-     */
36
-    public function oid(): string
37
-    {
38
-        return $this->_type->oid();
39
-    }
31
+	/**
32
+	 * Get OID of the attribute.
33
+	 *
34
+	 * @return string
35
+	 */
36
+	public function oid(): string
37
+	{
38
+		return $this->_type->oid();
39
+	}
40 40
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Sop\X501\ASN1\Feature;
6 6
 
Please login to merge, or discard this patch.
lib/X501/MatchingRule/CaseIgnoreMatch.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Sop\X501\MatchingRule;
6 6
 
Please login to merge, or discard this patch.
lib/X501/MatchingRule/MatchingRule.php 2 patches
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -11,14 +11,14 @@
 block discarded – undo
11 11
  */
12 12
 abstract class MatchingRule
13 13
 {
14
-    /**
15
-     * Compare attribute value to assertion.
16
-     *
17
-     * @param mixed $assertion Value to assert
18
-     * @param mixed $value     Attribute value
19
-     *
20
-     * @return null|bool True if value matches. Null shall be returned if match
21
-     *                   evaluates to Undefined.
22
-     */
23
-    abstract public function compare($assertion, $value): ?bool;
14
+	/**
15
+	 * Compare attribute value to assertion.
16
+	 *
17
+	 * @param mixed $assertion Value to assert
18
+	 * @param mixed $value     Attribute value
19
+	 *
20
+	 * @return null|bool True if value matches. Null shall be returned if match
21
+	 *                   evaluates to Undefined.
22
+	 */
23
+	abstract public function compare($assertion, $value): ?bool;
24 24
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Sop\X501\MatchingRule;
6 6
 
Please login to merge, or discard this patch.
lib/X501/DN/DNParser.php 2 patches
Indentation   +393 added lines, -393 removed lines patch added patch discarded remove patch
@@ -15,414 +15,414 @@
 block discarded – undo
15 15
  */
16 16
 class DNParser
17 17
 {
18
-    /**
19
-     * RFC 2253 special characters.
20
-     *
21
-     * @var string
22
-     */
23
-    const SPECIAL_CHARS = ',=+<>#;';
18
+	/**
19
+	 * RFC 2253 special characters.
20
+	 *
21
+	 * @var string
22
+	 */
23
+	const SPECIAL_CHARS = ',=+<>#;';
24 24
 
25
-    /**
26
-     * DN string.
27
-     *
28
-     * @var string
29
-     */
30
-    private $_dn;
25
+	/**
26
+	 * DN string.
27
+	 *
28
+	 * @var string
29
+	 */
30
+	private $_dn;
31 31
 
32
-    /**
33
-     * DN string length.
34
-     *
35
-     * @var int
36
-     */
37
-    private $_len;
32
+	/**
33
+	 * DN string length.
34
+	 *
35
+	 * @var int
36
+	 */
37
+	private $_len;
38 38
 
39
-    /**
40
-     * Constructor.
41
-     *
42
-     * @param string $dn Distinguised name
43
-     */
44
-    protected function __construct(string $dn)
45
-    {
46
-        $this->_dn = $dn;
47
-        $this->_len = strlen($dn);
48
-    }
39
+	/**
40
+	 * Constructor.
41
+	 *
42
+	 * @param string $dn Distinguised name
43
+	 */
44
+	protected function __construct(string $dn)
45
+	{
46
+		$this->_dn = $dn;
47
+		$this->_len = strlen($dn);
48
+	}
49 49
 
50
-    /**
51
-     * Parse distinguished name string to name-components.
52
-     *
53
-     * @param string $dn
54
-     *
55
-     * @return array
56
-     */
57
-    public static function parseString(string $dn): array
58
-    {
59
-        $parser = new self($dn);
60
-        return $parser->parse();
61
-    }
50
+	/**
51
+	 * Parse distinguished name string to name-components.
52
+	 *
53
+	 * @param string $dn
54
+	 *
55
+	 * @return array
56
+	 */
57
+	public static function parseString(string $dn): array
58
+	{
59
+		$parser = new self($dn);
60
+		return $parser->parse();
61
+	}
62 62
 
63
-    /**
64
-     * Escape a AttributeValue string conforming to RFC 2253.
65
-     *
66
-     * @see https://tools.ietf.org/html/rfc2253#section-2.4
67
-     *
68
-     * @param string $str
69
-     *
70
-     * @return string
71
-     */
72
-    public static function escapeString(string $str): string
73
-    {
74
-        // one of the characters ",", "+", """, "\", "<", ">" or ";"
75
-        $str = preg_replace('/([,\+"\\\<\>;])/u', '\\\\$1', $str);
76
-        // a space character occurring at the end of the string
77
-        $str = preg_replace('/( )$/u', '\\\\$1', $str);
78
-        // a space or "#" character occurring at the beginning of the string
79
-        $str = preg_replace('/^([ #])/u', '\\\\$1', $str);
80
-        // implementation specific special characters
81
-        $str = preg_replace_callback('/([\pC])/u',
82
-            function ($m) {
83
-                $octets = str_split(bin2hex($m[1]), 2);
84
-                return implode('',
85
-                    array_map(
86
-                        function ($octet) {
87
-                            return '\\' . strtoupper($octet);
88
-                        }, $octets));
89
-            }, $str);
90
-        return $str;
91
-    }
63
+	/**
64
+	 * Escape a AttributeValue string conforming to RFC 2253.
65
+	 *
66
+	 * @see https://tools.ietf.org/html/rfc2253#section-2.4
67
+	 *
68
+	 * @param string $str
69
+	 *
70
+	 * @return string
71
+	 */
72
+	public static function escapeString(string $str): string
73
+	{
74
+		// one of the characters ",", "+", """, "\", "<", ">" or ";"
75
+		$str = preg_replace('/([,\+"\\\<\>;])/u', '\\\\$1', $str);
76
+		// a space character occurring at the end of the string
77
+		$str = preg_replace('/( )$/u', '\\\\$1', $str);
78
+		// a space or "#" character occurring at the beginning of the string
79
+		$str = preg_replace('/^([ #])/u', '\\\\$1', $str);
80
+		// implementation specific special characters
81
+		$str = preg_replace_callback('/([\pC])/u',
82
+			function ($m) {
83
+				$octets = str_split(bin2hex($m[1]), 2);
84
+				return implode('',
85
+					array_map(
86
+						function ($octet) {
87
+							return '\\' . strtoupper($octet);
88
+						}, $octets));
89
+			}, $str);
90
+		return $str;
91
+	}
92 92
 
93
-    /**
94
-     * Parse DN to name-components.
95
-     *
96
-     * @throws \RuntimeException
97
-     *
98
-     * @return array
99
-     */
100
-    protected function parse(): array
101
-    {
102
-        $offset = 0;
103
-        $name = $this->_parseName($offset);
104
-        if ($offset < $this->_len) {
105
-            $remains = substr($this->_dn, $offset);
106
-            throw new \UnexpectedValueException(
107
-                'Parser finished before the end of string' .
108
-                     ", remaining: '{$remains}'.");
109
-        }
110
-        return $name;
111
-    }
93
+	/**
94
+	 * Parse DN to name-components.
95
+	 *
96
+	 * @throws \RuntimeException
97
+	 *
98
+	 * @return array
99
+	 */
100
+	protected function parse(): array
101
+	{
102
+		$offset = 0;
103
+		$name = $this->_parseName($offset);
104
+		if ($offset < $this->_len) {
105
+			$remains = substr($this->_dn, $offset);
106
+			throw new \UnexpectedValueException(
107
+				'Parser finished before the end of string' .
108
+					 ", remaining: '{$remains}'.");
109
+		}
110
+		return $name;
111
+	}
112 112
 
113
-    /**
114
-     * Parse 'name'.
115
-     *
116
-     * name-component *("," name-component)
117
-     *
118
-     * @param int $offset
119
-     *
120
-     * @return array Array of name-components
121
-     */
122
-    private function _parseName(int &$offset): array
123
-    {
124
-        $idx = $offset;
125
-        $names = [];
126
-        while ($idx < $this->_len) {
127
-            $names[] = $this->_parseNameComponent($idx);
128
-            if ($idx >= $this->_len) {
129
-                break;
130
-            }
131
-            $this->_skipWs($idx);
132
-            if (',' != $this->_dn[$idx] && ';' != $this->_dn[$idx]) {
133
-                break;
134
-            }
135
-            ++$idx;
136
-            $this->_skipWs($idx);
137
-        }
138
-        $offset = $idx;
139
-        return array_reverse($names);
140
-    }
113
+	/**
114
+	 * Parse 'name'.
115
+	 *
116
+	 * name-component *("," name-component)
117
+	 *
118
+	 * @param int $offset
119
+	 *
120
+	 * @return array Array of name-components
121
+	 */
122
+	private function _parseName(int &$offset): array
123
+	{
124
+		$idx = $offset;
125
+		$names = [];
126
+		while ($idx < $this->_len) {
127
+			$names[] = $this->_parseNameComponent($idx);
128
+			if ($idx >= $this->_len) {
129
+				break;
130
+			}
131
+			$this->_skipWs($idx);
132
+			if (',' != $this->_dn[$idx] && ';' != $this->_dn[$idx]) {
133
+				break;
134
+			}
135
+			++$idx;
136
+			$this->_skipWs($idx);
137
+		}
138
+		$offset = $idx;
139
+		return array_reverse($names);
140
+	}
141 141
 
142
-    /**
143
-     * Parse 'name-component'.
144
-     *
145
-     * attributeTypeAndValue *("+" attributeTypeAndValue)
146
-     *
147
-     * @param int $offset
148
-     *
149
-     * @return array Array of [type, value] tuples
150
-     */
151
-    private function _parseNameComponent(int &$offset): array
152
-    {
153
-        $idx = $offset;
154
-        $tvpairs = [];
155
-        while ($idx < $this->_len) {
156
-            $tvpairs[] = $this->_parseAttrTypeAndValue($idx);
157
-            $this->_skipWs($idx);
158
-            if ($idx >= $this->_len || '+' != $this->_dn[$idx]) {
159
-                break;
160
-            }
161
-            ++$idx;
162
-            $this->_skipWs($idx);
163
-        }
164
-        $offset = $idx;
165
-        return $tvpairs;
166
-    }
142
+	/**
143
+	 * Parse 'name-component'.
144
+	 *
145
+	 * attributeTypeAndValue *("+" attributeTypeAndValue)
146
+	 *
147
+	 * @param int $offset
148
+	 *
149
+	 * @return array Array of [type, value] tuples
150
+	 */
151
+	private function _parseNameComponent(int &$offset): array
152
+	{
153
+		$idx = $offset;
154
+		$tvpairs = [];
155
+		while ($idx < $this->_len) {
156
+			$tvpairs[] = $this->_parseAttrTypeAndValue($idx);
157
+			$this->_skipWs($idx);
158
+			if ($idx >= $this->_len || '+' != $this->_dn[$idx]) {
159
+				break;
160
+			}
161
+			++$idx;
162
+			$this->_skipWs($idx);
163
+		}
164
+		$offset = $idx;
165
+		return $tvpairs;
166
+	}
167 167
 
168
-    /**
169
-     * Parse 'attributeTypeAndValue'.
170
-     *
171
-     * attributeType "=" attributeValue
172
-     *
173
-     * @param int $offset
174
-     *
175
-     * @throws \UnexpectedValueException
176
-     *
177
-     * @return array A tuple of [type, value]. Value may be either a string or
178
-     *               an Element, if it's encoded as hexstring.
179
-     */
180
-    private function _parseAttrTypeAndValue(int &$offset): array
181
-    {
182
-        $idx = $offset;
183
-        $type = $this->_parseAttrType($idx);
184
-        $this->_skipWs($idx);
185
-        if ($idx >= $this->_len || '=' != $this->_dn[$idx++]) {
186
-            throw new \UnexpectedValueException('Invalid type and value pair.');
187
-        }
188
-        $this->_skipWs($idx);
189
-        // hexstring
190
-        if ($idx < $this->_len && '#' == $this->_dn[$idx]) {
191
-            ++$idx;
192
-            $data = $this->_parseAttrHexValue($idx);
193
-            try {
194
-                $value = Element::fromDER($data);
195
-            } catch (DecodeException $e) {
196
-                throw new \UnexpectedValueException(
197
-                    'Invalid DER encoding from hexstring.', 0, $e);
198
-            }
199
-        } else {
200
-            $value = $this->_parseAttrStringValue($idx);
201
-        }
202
-        $offset = $idx;
203
-        return [$type, $value];
204
-    }
168
+	/**
169
+	 * Parse 'attributeTypeAndValue'.
170
+	 *
171
+	 * attributeType "=" attributeValue
172
+	 *
173
+	 * @param int $offset
174
+	 *
175
+	 * @throws \UnexpectedValueException
176
+	 *
177
+	 * @return array A tuple of [type, value]. Value may be either a string or
178
+	 *               an Element, if it's encoded as hexstring.
179
+	 */
180
+	private function _parseAttrTypeAndValue(int &$offset): array
181
+	{
182
+		$idx = $offset;
183
+		$type = $this->_parseAttrType($idx);
184
+		$this->_skipWs($idx);
185
+		if ($idx >= $this->_len || '=' != $this->_dn[$idx++]) {
186
+			throw new \UnexpectedValueException('Invalid type and value pair.');
187
+		}
188
+		$this->_skipWs($idx);
189
+		// hexstring
190
+		if ($idx < $this->_len && '#' == $this->_dn[$idx]) {
191
+			++$idx;
192
+			$data = $this->_parseAttrHexValue($idx);
193
+			try {
194
+				$value = Element::fromDER($data);
195
+			} catch (DecodeException $e) {
196
+				throw new \UnexpectedValueException(
197
+					'Invalid DER encoding from hexstring.', 0, $e);
198
+			}
199
+		} else {
200
+			$value = $this->_parseAttrStringValue($idx);
201
+		}
202
+		$offset = $idx;
203
+		return [$type, $value];
204
+	}
205 205
 
206
-    /**
207
-     * Parse 'attributeType'.
208
-     *
209
-     * (ALPHA 1*keychar) / oid
210
-     *
211
-     * @param int $offset
212
-     *
213
-     * @throws \UnexpectedValueException
214
-     *
215
-     * @return string
216
-     */
217
-    private function _parseAttrType(int &$offset): string
218
-    {
219
-        $idx = $offset;
220
-        // dotted OID
221
-        $type = $this->_regexMatch('/^(?:oid\.)?([0-9]+(?:\.[0-9]+)*)/i', $idx);
222
-        if (null === $type) {
223
-            // name
224
-            $type = $this->_regexMatch('/^[a-z][a-z0-9\-]*/i', $idx);
225
-            if (null === $type) {
226
-                throw new \UnexpectedValueException('Invalid attribute type.');
227
-            }
228
-        }
229
-        $offset = $idx;
230
-        return $type;
231
-    }
206
+	/**
207
+	 * Parse 'attributeType'.
208
+	 *
209
+	 * (ALPHA 1*keychar) / oid
210
+	 *
211
+	 * @param int $offset
212
+	 *
213
+	 * @throws \UnexpectedValueException
214
+	 *
215
+	 * @return string
216
+	 */
217
+	private function _parseAttrType(int &$offset): string
218
+	{
219
+		$idx = $offset;
220
+		// dotted OID
221
+		$type = $this->_regexMatch('/^(?:oid\.)?([0-9]+(?:\.[0-9]+)*)/i', $idx);
222
+		if (null === $type) {
223
+			// name
224
+			$type = $this->_regexMatch('/^[a-z][a-z0-9\-]*/i', $idx);
225
+			if (null === $type) {
226
+				throw new \UnexpectedValueException('Invalid attribute type.');
227
+			}
228
+		}
229
+		$offset = $idx;
230
+		return $type;
231
+	}
232 232
 
233
-    /**
234
-     * Parse 'attributeValue' of string type.
235
-     *
236
-     * @param int $offset
237
-     *
238
-     * @throws \UnexpectedValueException
239
-     *
240
-     * @return string
241
-     */
242
-    private function _parseAttrStringValue(int &$offset): string
243
-    {
244
-        $idx = $offset;
245
-        if ($idx >= $this->_len) {
246
-            return '';
247
-        }
248
-        if ('"' == $this->_dn[$idx]) { // quoted string
249
-            $val = $this->_parseQuotedAttrString($idx);
250
-        } else { // string
251
-            $val = $this->_parseAttrString($idx);
252
-        }
253
-        $offset = $idx;
254
-        return $val;
255
-    }
233
+	/**
234
+	 * Parse 'attributeValue' of string type.
235
+	 *
236
+	 * @param int $offset
237
+	 *
238
+	 * @throws \UnexpectedValueException
239
+	 *
240
+	 * @return string
241
+	 */
242
+	private function _parseAttrStringValue(int &$offset): string
243
+	{
244
+		$idx = $offset;
245
+		if ($idx >= $this->_len) {
246
+			return '';
247
+		}
248
+		if ('"' == $this->_dn[$idx]) { // quoted string
249
+			$val = $this->_parseQuotedAttrString($idx);
250
+		} else { // string
251
+			$val = $this->_parseAttrString($idx);
252
+		}
253
+		$offset = $idx;
254
+		return $val;
255
+	}
256 256
 
257
-    /**
258
-     * Parse plain 'attributeValue' string.
259
-     *
260
-     * @param int $offset
261
-     *
262
-     * @throws \UnexpectedValueException
263
-     *
264
-     * @return string
265
-     */
266
-    private function _parseAttrString(int &$offset): string
267
-    {
268
-        $idx = $offset;
269
-        $val = '';
270
-        $wsidx = null;
271
-        while ($idx < $this->_len) {
272
-            $c = $this->_dn[$idx];
273
-            // pair (escape sequence)
274
-            if ('\\' == $c) {
275
-                ++$idx;
276
-                $val .= $this->_parsePairAfterSlash($idx);
277
-                $wsidx = null;
278
-                continue;
279
-            }
280
-            if ('"' == $c) {
281
-                throw new \UnexpectedValueException('Unexpected quotation.');
282
-            }
283
-            if (false !== strpos(self::SPECIAL_CHARS, $c)) {
284
-                break;
285
-            }
286
-            // keep track of the first consecutive whitespace
287
-            if (' ' == $c) {
288
-                if (null === $wsidx) {
289
-                    $wsidx = $idx;
290
-                }
291
-            } else {
292
-                $wsidx = null;
293
-            }
294
-            // stringchar
295
-            $val .= $c;
296
-            ++$idx;
297
-        }
298
-        // if there was non-escaped whitespace in the end of the value
299
-        if (null !== $wsidx) {
300
-            $val = substr($val, 0, -($idx - $wsidx));
301
-        }
302
-        $offset = $idx;
303
-        return $val;
304
-    }
257
+	/**
258
+	 * Parse plain 'attributeValue' string.
259
+	 *
260
+	 * @param int $offset
261
+	 *
262
+	 * @throws \UnexpectedValueException
263
+	 *
264
+	 * @return string
265
+	 */
266
+	private function _parseAttrString(int &$offset): string
267
+	{
268
+		$idx = $offset;
269
+		$val = '';
270
+		$wsidx = null;
271
+		while ($idx < $this->_len) {
272
+			$c = $this->_dn[$idx];
273
+			// pair (escape sequence)
274
+			if ('\\' == $c) {
275
+				++$idx;
276
+				$val .= $this->_parsePairAfterSlash($idx);
277
+				$wsidx = null;
278
+				continue;
279
+			}
280
+			if ('"' == $c) {
281
+				throw new \UnexpectedValueException('Unexpected quotation.');
282
+			}
283
+			if (false !== strpos(self::SPECIAL_CHARS, $c)) {
284
+				break;
285
+			}
286
+			// keep track of the first consecutive whitespace
287
+			if (' ' == $c) {
288
+				if (null === $wsidx) {
289
+					$wsidx = $idx;
290
+				}
291
+			} else {
292
+				$wsidx = null;
293
+			}
294
+			// stringchar
295
+			$val .= $c;
296
+			++$idx;
297
+		}
298
+		// if there was non-escaped whitespace in the end of the value
299
+		if (null !== $wsidx) {
300
+			$val = substr($val, 0, -($idx - $wsidx));
301
+		}
302
+		$offset = $idx;
303
+		return $val;
304
+	}
305 305
 
306
-    /**
307
-     * Parse quoted 'attributeValue' string.
308
-     *
309
-     * @param int $offset Offset to starting quote
310
-     *
311
-     * @throws \UnexpectedValueException
312
-     *
313
-     * @return string
314
-     */
315
-    private function _parseQuotedAttrString(int &$offset): string
316
-    {
317
-        $idx = $offset + 1;
318
-        $val = '';
319
-        while ($idx < $this->_len) {
320
-            $c = $this->_dn[$idx];
321
-            if ('\\' == $c) { // pair
322
-                ++$idx;
323
-                $val .= $this->_parsePairAfterSlash($idx);
324
-                continue;
325
-            }
326
-            if ('"' == $c) {
327
-                ++$idx;
328
-                break;
329
-            }
330
-            $val .= $c;
331
-            ++$idx;
332
-        }
333
-        $offset = $idx;
334
-        return $val;
335
-    }
306
+	/**
307
+	 * Parse quoted 'attributeValue' string.
308
+	 *
309
+	 * @param int $offset Offset to starting quote
310
+	 *
311
+	 * @throws \UnexpectedValueException
312
+	 *
313
+	 * @return string
314
+	 */
315
+	private function _parseQuotedAttrString(int &$offset): string
316
+	{
317
+		$idx = $offset + 1;
318
+		$val = '';
319
+		while ($idx < $this->_len) {
320
+			$c = $this->_dn[$idx];
321
+			if ('\\' == $c) { // pair
322
+				++$idx;
323
+				$val .= $this->_parsePairAfterSlash($idx);
324
+				continue;
325
+			}
326
+			if ('"' == $c) {
327
+				++$idx;
328
+				break;
329
+			}
330
+			$val .= $c;
331
+			++$idx;
332
+		}
333
+		$offset = $idx;
334
+		return $val;
335
+	}
336 336
 
337
-    /**
338
-     * Parse 'attributeValue' of binary type.
339
-     *
340
-     * @param int $offset
341
-     *
342
-     * @throws \UnexpectedValueException
343
-     *
344
-     * @return string
345
-     */
346
-    private function _parseAttrHexValue(int &$offset): string
347
-    {
348
-        $idx = $offset;
349
-        $hexstr = $this->_regexMatch('/^(?:[0-9a-f]{2})+/i', $idx);
350
-        if (null === $hexstr) {
351
-            throw new \UnexpectedValueException('Invalid hexstring.');
352
-        }
353
-        $data = hex2bin($hexstr);
354
-        $offset = $idx;
355
-        return $data;
356
-    }
337
+	/**
338
+	 * Parse 'attributeValue' of binary type.
339
+	 *
340
+	 * @param int $offset
341
+	 *
342
+	 * @throws \UnexpectedValueException
343
+	 *
344
+	 * @return string
345
+	 */
346
+	private function _parseAttrHexValue(int &$offset): string
347
+	{
348
+		$idx = $offset;
349
+		$hexstr = $this->_regexMatch('/^(?:[0-9a-f]{2})+/i', $idx);
350
+		if (null === $hexstr) {
351
+			throw new \UnexpectedValueException('Invalid hexstring.');
352
+		}
353
+		$data = hex2bin($hexstr);
354
+		$offset = $idx;
355
+		return $data;
356
+	}
357 357
 
358
-    /**
359
-     * Parse 'pair' after leading slash.
360
-     *
361
-     * @param int $offset
362
-     *
363
-     * @throws \UnexpectedValueException
364
-     *
365
-     * @return string
366
-     */
367
-    private function _parsePairAfterSlash(int &$offset): string
368
-    {
369
-        $idx = $offset;
370
-        if ($idx >= $this->_len) {
371
-            throw new \UnexpectedValueException(
372
-                'Unexpected end of escape sequence.');
373
-        }
374
-        $c = $this->_dn[$idx++];
375
-        // special | \ | " | SPACE
376
-        if (false !== strpos(self::SPECIAL_CHARS . '\\" ', $c)) {
377
-            $val = $c;
378
-        } else { // hexpair
379
-            if ($idx >= $this->_len) {
380
-                throw new \UnexpectedValueException('Unexpected end of hexpair.');
381
-            }
382
-            $val = @hex2bin($c . $this->_dn[$idx++]);
383
-            if (false === $val) {
384
-                throw new \UnexpectedValueException('Invalid hexpair.');
385
-            }
386
-        }
387
-        $offset = $idx;
388
-        return $val;
389
-    }
358
+	/**
359
+	 * Parse 'pair' after leading slash.
360
+	 *
361
+	 * @param int $offset
362
+	 *
363
+	 * @throws \UnexpectedValueException
364
+	 *
365
+	 * @return string
366
+	 */
367
+	private function _parsePairAfterSlash(int &$offset): string
368
+	{
369
+		$idx = $offset;
370
+		if ($idx >= $this->_len) {
371
+			throw new \UnexpectedValueException(
372
+				'Unexpected end of escape sequence.');
373
+		}
374
+		$c = $this->_dn[$idx++];
375
+		// special | \ | " | SPACE
376
+		if (false !== strpos(self::SPECIAL_CHARS . '\\" ', $c)) {
377
+			$val = $c;
378
+		} else { // hexpair
379
+			if ($idx >= $this->_len) {
380
+				throw new \UnexpectedValueException('Unexpected end of hexpair.');
381
+			}
382
+			$val = @hex2bin($c . $this->_dn[$idx++]);
383
+			if (false === $val) {
384
+				throw new \UnexpectedValueException('Invalid hexpair.');
385
+			}
386
+		}
387
+		$offset = $idx;
388
+		return $val;
389
+	}
390 390
 
391
-    /**
392
-     * Match DN to pattern and extract the last capture group.
393
-     *
394
-     * Updates offset to fully matched pattern.
395
-     *
396
-     * @param string $pattern
397
-     * @param int    $offset
398
-     *
399
-     * @return null|string Null if pattern doesn't match
400
-     */
401
-    private function _regexMatch(string $pattern, int &$offset): ?string
402
-    {
403
-        $idx = $offset;
404
-        if (!preg_match($pattern, substr($this->_dn, $idx), $match)) {
405
-            return null;
406
-        }
407
-        $idx += strlen($match[0]);
408
-        $offset = $idx;
409
-        return end($match);
410
-    }
391
+	/**
392
+	 * Match DN to pattern and extract the last capture group.
393
+	 *
394
+	 * Updates offset to fully matched pattern.
395
+	 *
396
+	 * @param string $pattern
397
+	 * @param int    $offset
398
+	 *
399
+	 * @return null|string Null if pattern doesn't match
400
+	 */
401
+	private function _regexMatch(string $pattern, int &$offset): ?string
402
+	{
403
+		$idx = $offset;
404
+		if (!preg_match($pattern, substr($this->_dn, $idx), $match)) {
405
+			return null;
406
+		}
407
+		$idx += strlen($match[0]);
408
+		$offset = $idx;
409
+		return end($match);
410
+	}
411 411
 
412
-    /**
413
-     * Skip consecutive spaces.
414
-     *
415
-     * @param int $offset
416
-     */
417
-    private function _skipWs(int &$offset): void
418
-    {
419
-        $idx = $offset;
420
-        while ($idx < $this->_len) {
421
-            if (' ' != $this->_dn[$idx]) {
422
-                break;
423
-            }
424
-            ++$idx;
425
-        }
426
-        $offset = $idx;
427
-    }
412
+	/**
413
+	 * Skip consecutive spaces.
414
+	 *
415
+	 * @param int $offset
416
+	 */
417
+	private function _skipWs(int &$offset): void
418
+	{
419
+		$idx = $offset;
420
+		while ($idx < $this->_len) {
421
+			if (' ' != $this->_dn[$idx]) {
422
+				break;
423
+			}
424
+			++$idx;
425
+		}
426
+		$offset = $idx;
427
+	}
428 428
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Sop\X501\DN;
6 6
 
@@ -79,11 +79,11 @@  discard block
 block discarded – undo
79 79
         $str = preg_replace('/^([ #])/u', '\\\\$1', $str);
80 80
         // implementation specific special characters
81 81
         $str = preg_replace_callback('/([\pC])/u',
82
-            function ($m) {
82
+            function($m) {
83 83
                 $octets = str_split(bin2hex($m[1]), 2);
84 84
                 return implode('',
85 85
                     array_map(
86
-                        function ($octet) {
86
+                        function($octet) {
87 87
                             return '\\' . strtoupper($octet);
88 88
                         }, $octets));
89 89
             }, $str);
Please login to merge, or discard this patch.