@@ -12,34 +12,34 @@ |
||
12 | 12 | */ |
13 | 13 | class MapStep implements PrepareStep |
14 | 14 | { |
15 | - /** |
|
16 | - * Whether to apply case folding. |
|
17 | - * |
|
18 | - * @var bool $_fold |
|
19 | - */ |
|
20 | - protected $_fold; |
|
15 | + /** |
|
16 | + * Whether to apply case folding. |
|
17 | + * |
|
18 | + * @var bool $_fold |
|
19 | + */ |
|
20 | + protected $_fold; |
|
21 | 21 | |
22 | - /** |
|
23 | - * Constructor. |
|
24 | - * |
|
25 | - * @param bool $fold_case Whether to apply case folding |
|
26 | - */ |
|
27 | - public function __construct(bool $fold_case = false) |
|
28 | - { |
|
29 | - $this->_fold = $fold_case; |
|
30 | - } |
|
22 | + /** |
|
23 | + * Constructor. |
|
24 | + * |
|
25 | + * @param bool $fold_case Whether to apply case folding |
|
26 | + */ |
|
27 | + public function __construct(bool $fold_case = false) |
|
28 | + { |
|
29 | + $this->_fold = $fold_case; |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * |
|
34 | - * @param string $string UTF-8 encoded string |
|
35 | - * @return string |
|
36 | - */ |
|
37 | - public function apply(string $string): string |
|
38 | - { |
|
39 | - // @todo Implement character mappings |
|
40 | - if ($this->_fold) { |
|
41 | - $string = mb_convert_case($string, MB_CASE_LOWER, "UTF-8"); |
|
42 | - } |
|
43 | - return $string; |
|
44 | - } |
|
32 | + /** |
|
33 | + * |
|
34 | + * @param string $string UTF-8 encoded string |
|
35 | + * @return string |
|
36 | + */ |
|
37 | + public function apply(string $string): string |
|
38 | + { |
|
39 | + // @todo Implement character mappings |
|
40 | + if ($this->_fold) { |
|
41 | + $string = mb_convert_case($string, MB_CASE_LOWER, "UTF-8"); |
|
42 | + } |
|
43 | + return $string; |
|
44 | + } |
|
45 | 45 | } |
@@ -12,11 +12,11 @@ |
||
12 | 12 | */ |
13 | 13 | interface PrepareStep |
14 | 14 | { |
15 | - /** |
|
16 | - * Apply string preparation step. |
|
17 | - * |
|
18 | - * @param string $string String to prepare |
|
19 | - * @return string Prepared string |
|
20 | - */ |
|
21 | - public function apply(string $string): string; |
|
15 | + /** |
|
16 | + * Apply string preparation step. |
|
17 | + * |
|
18 | + * @param string $string String to prepare |
|
19 | + * @return string Prepared string |
|
20 | + */ |
|
21 | + public function apply(string $string): string; |
|
22 | 22 | } |
@@ -12,14 +12,14 @@ |
||
12 | 12 | */ |
13 | 13 | class CheckBidiStep implements PrepareStep |
14 | 14 | { |
15 | - /** |
|
16 | - * |
|
17 | - * @param string $string UTF-8 encoded string |
|
18 | - * @return string |
|
19 | - */ |
|
20 | - public function apply(string $string): string |
|
21 | - { |
|
22 | - // @todo Implement |
|
23 | - return $string; |
|
24 | - } |
|
15 | + /** |
|
16 | + * |
|
17 | + * @param string $string UTF-8 encoded string |
|
18 | + * @return string |
|
19 | + */ |
|
20 | + public function apply(string $string): string |
|
21 | + { |
|
22 | + // @todo Implement |
|
23 | + return $string; |
|
24 | + } |
|
25 | 25 | } |
@@ -12,16 +12,16 @@ |
||
12 | 12 | */ |
13 | 13 | class ProhibitStep implements PrepareStep |
14 | 14 | { |
15 | - /** |
|
16 | - * |
|
17 | - * @throws \UnexpectedValueException If string contains prohibited |
|
18 | - * characters |
|
19 | - * @param string $string UTF-8 encoded string |
|
20 | - * @return string |
|
21 | - */ |
|
22 | - public function apply(string $string): string |
|
23 | - { |
|
24 | - // @todo Implement |
|
25 | - return $string; |
|
26 | - } |
|
15 | + /** |
|
16 | + * |
|
17 | + * @throws \UnexpectedValueException If string contains prohibited |
|
18 | + * characters |
|
19 | + * @param string $string UTF-8 encoded string |
|
20 | + * @return string |
|
21 | + */ |
|
22 | + public function apply(string $string): string |
|
23 | + { |
|
24 | + // @todo Implement |
|
25 | + return $string; |
|
26 | + } |
|
27 | 27 | } |
@@ -14,22 +14,22 @@ |
||
14 | 14 | */ |
15 | 15 | class InsignificantNonSubstringSpaceStep implements PrepareStep |
16 | 16 | { |
17 | - /** |
|
18 | - * |
|
19 | - * @param string $string UTF-8 encoded string |
|
20 | - * @return string |
|
21 | - */ |
|
22 | - public function apply(string $string): string |
|
23 | - { |
|
24 | - // if value contains no non-space characters |
|
25 | - if (preg_match('/^\p{Zs}*$/u', $string)) { |
|
26 | - return " "; |
|
27 | - } |
|
28 | - // trim leading and trailing spaces |
|
29 | - $string = preg_replace('/^\p{Zs}+/u', '', $string); |
|
30 | - $string = preg_replace('/\p{Zs}+$/u', '', $string); |
|
31 | - // convert inner space sequences to two U+0020 characters |
|
32 | - $string = preg_replace('/\p{Zs}+/u', " ", $string); |
|
33 | - return " $string "; |
|
34 | - } |
|
17 | + /** |
|
18 | + * |
|
19 | + * @param string $string UTF-8 encoded string |
|
20 | + * @return string |
|
21 | + */ |
|
22 | + public function apply(string $string): string |
|
23 | + { |
|
24 | + // if value contains no non-space characters |
|
25 | + if (preg_match('/^\p{Zs}*$/u', $string)) { |
|
26 | + return " "; |
|
27 | + } |
|
28 | + // trim leading and trailing spaces |
|
29 | + $string = preg_replace('/^\p{Zs}+/u', '', $string); |
|
30 | + $string = preg_replace('/\p{Zs}+$/u', '', $string); |
|
31 | + // convert inner space sequences to two U+0020 characters |
|
32 | + $string = preg_replace('/\p{Zs}+/u', " ", $string); |
|
33 | + return " $string "; |
|
34 | + } |
|
35 | 35 | } |
@@ -11,30 +11,30 @@ |
||
11 | 11 | */ |
12 | 12 | trait TypedAttribute |
13 | 13 | { |
14 | - /** |
|
15 | - * Attribute type. |
|
16 | - * |
|
17 | - * @var AttributeType $_type |
|
18 | - */ |
|
19 | - protected $_type; |
|
14 | + /** |
|
15 | + * Attribute type. |
|
16 | + * |
|
17 | + * @var AttributeType $_type |
|
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 | } |
@@ -21,199 +21,199 @@ |
||
21 | 21 | */ |
22 | 22 | class Name implements \Countable, \IteratorAggregate |
23 | 23 | { |
24 | - /** |
|
25 | - * Relative distinguished name components. |
|
26 | - * |
|
27 | - * @var RDN[] $_rdns |
|
28 | - */ |
|
29 | - protected $_rdns; |
|
24 | + /** |
|
25 | + * Relative distinguished name components. |
|
26 | + * |
|
27 | + * @var RDN[] $_rdns |
|
28 | + */ |
|
29 | + protected $_rdns; |
|
30 | 30 | |
31 | - /** |
|
32 | - * Constructor. |
|
33 | - * |
|
34 | - * @param RDN ...$rdns RDN components |
|
35 | - */ |
|
36 | - public function __construct(RDN ...$rdns) |
|
37 | - { |
|
38 | - $this->_rdns = $rdns; |
|
39 | - } |
|
31 | + /** |
|
32 | + * Constructor. |
|
33 | + * |
|
34 | + * @param RDN ...$rdns RDN components |
|
35 | + */ |
|
36 | + public function __construct(RDN ...$rdns) |
|
37 | + { |
|
38 | + $this->_rdns = $rdns; |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * Initialize from ASN.1. |
|
43 | - * |
|
44 | - * @param Sequence $seq |
|
45 | - * @return self |
|
46 | - */ |
|
47 | - public static function fromASN1(Sequence $seq): self |
|
48 | - { |
|
49 | - $rdns = array_map( |
|
50 | - function (UnspecifiedType $el) { |
|
51 | - return RDN::fromASN1($el->asSet()); |
|
52 | - }, $seq->elements()); |
|
53 | - return new self(...$rdns); |
|
54 | - } |
|
41 | + /** |
|
42 | + * Initialize from ASN.1. |
|
43 | + * |
|
44 | + * @param Sequence $seq |
|
45 | + * @return self |
|
46 | + */ |
|
47 | + public static function fromASN1(Sequence $seq): self |
|
48 | + { |
|
49 | + $rdns = array_map( |
|
50 | + function (UnspecifiedType $el) { |
|
51 | + return RDN::fromASN1($el->asSet()); |
|
52 | + }, $seq->elements()); |
|
53 | + return new self(...$rdns); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * Initialize from distinguished name string. |
|
58 | - * |
|
59 | - * @link https://tools.ietf.org/html/rfc1779 |
|
60 | - * @param string $str |
|
61 | - * @return self |
|
62 | - */ |
|
63 | - public static function fromString(string $str): self |
|
64 | - { |
|
65 | - $rdns = array(); |
|
66 | - foreach (DNParser::parseString($str) as $nameComponent) { |
|
67 | - $attribs = array(); |
|
68 | - foreach ($nameComponent as list($name, $val)) { |
|
69 | - $type = AttributeType::fromName($name); |
|
70 | - // hexstrings are parsed to ASN.1 elements |
|
71 | - if ($val instanceof Element) { |
|
72 | - $el = $val; |
|
73 | - } else { |
|
74 | - $el = AttributeType::asn1StringForType($type->oid(), $val); |
|
75 | - } |
|
76 | - $value = AttributeValue::fromASN1ByOID($type->oid(), |
|
77 | - $el->asUnspecified()); |
|
78 | - $attribs[] = new AttributeTypeAndValue($type, $value); |
|
79 | - } |
|
80 | - $rdns[] = new RDN(...$attribs); |
|
81 | - } |
|
82 | - return new self(...$rdns); |
|
83 | - } |
|
56 | + /** |
|
57 | + * Initialize from distinguished name string. |
|
58 | + * |
|
59 | + * @link https://tools.ietf.org/html/rfc1779 |
|
60 | + * @param string $str |
|
61 | + * @return self |
|
62 | + */ |
|
63 | + public static function fromString(string $str): self |
|
64 | + { |
|
65 | + $rdns = array(); |
|
66 | + foreach (DNParser::parseString($str) as $nameComponent) { |
|
67 | + $attribs = array(); |
|
68 | + foreach ($nameComponent as list($name, $val)) { |
|
69 | + $type = AttributeType::fromName($name); |
|
70 | + // hexstrings are parsed to ASN.1 elements |
|
71 | + if ($val instanceof Element) { |
|
72 | + $el = $val; |
|
73 | + } else { |
|
74 | + $el = AttributeType::asn1StringForType($type->oid(), $val); |
|
75 | + } |
|
76 | + $value = AttributeValue::fromASN1ByOID($type->oid(), |
|
77 | + $el->asUnspecified()); |
|
78 | + $attribs[] = new AttributeTypeAndValue($type, $value); |
|
79 | + } |
|
80 | + $rdns[] = new RDN(...$attribs); |
|
81 | + } |
|
82 | + return new self(...$rdns); |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * Generate ASN.1 structure. |
|
87 | - * |
|
88 | - * @return Sequence |
|
89 | - */ |
|
90 | - public function toASN1(): Sequence |
|
91 | - { |
|
92 | - $elements = array_map( |
|
93 | - function (RDN $rdn) { |
|
94 | - return $rdn->toASN1(); |
|
95 | - }, $this->_rdns); |
|
96 | - return new Sequence(...$elements); |
|
97 | - } |
|
85 | + /** |
|
86 | + * Generate ASN.1 structure. |
|
87 | + * |
|
88 | + * @return Sequence |
|
89 | + */ |
|
90 | + public function toASN1(): Sequence |
|
91 | + { |
|
92 | + $elements = array_map( |
|
93 | + function (RDN $rdn) { |
|
94 | + return $rdn->toASN1(); |
|
95 | + }, $this->_rdns); |
|
96 | + return new Sequence(...$elements); |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * Get distinguised name string conforming to RFC 2253. |
|
101 | - * |
|
102 | - * @link https://tools.ietf.org/html/rfc2253#section-2.1 |
|
103 | - * @return string |
|
104 | - */ |
|
105 | - public function toString(): string |
|
106 | - { |
|
107 | - $parts = array_map( |
|
108 | - function (RDN $rdn) { |
|
109 | - return $rdn->toString(); |
|
110 | - }, array_reverse($this->_rdns)); |
|
111 | - return implode(",", $parts); |
|
112 | - } |
|
99 | + /** |
|
100 | + * Get distinguised name string conforming to RFC 2253. |
|
101 | + * |
|
102 | + * @link https://tools.ietf.org/html/rfc2253#section-2.1 |
|
103 | + * @return string |
|
104 | + */ |
|
105 | + public function toString(): string |
|
106 | + { |
|
107 | + $parts = array_map( |
|
108 | + function (RDN $rdn) { |
|
109 | + return $rdn->toString(); |
|
110 | + }, array_reverse($this->_rdns)); |
|
111 | + return implode(",", $parts); |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * Whether name is semantically equal to other. |
|
116 | - * Comparison conforms to RFC 4518 string preparation algorithm. |
|
117 | - * |
|
118 | - * @link https://tools.ietf.org/html/rfc4518 |
|
119 | - * @param Name $other Object to compare to |
|
120 | - * @return bool |
|
121 | - */ |
|
122 | - public function equals(Name $other): bool |
|
123 | - { |
|
124 | - // if RDN count doesn't match |
|
125 | - if (count($this) != count($other)) { |
|
126 | - return false; |
|
127 | - } |
|
128 | - for ($i = count($this) - 1; $i >= 0; --$i) { |
|
129 | - $rdn1 = $this->_rdns[$i]; |
|
130 | - $rdn2 = $other->_rdns[$i]; |
|
131 | - if (!$rdn1->equals($rdn2)) { |
|
132 | - return false; |
|
133 | - } |
|
134 | - } |
|
135 | - return true; |
|
136 | - } |
|
114 | + /** |
|
115 | + * Whether name is semantically equal to other. |
|
116 | + * Comparison conforms to RFC 4518 string preparation algorithm. |
|
117 | + * |
|
118 | + * @link https://tools.ietf.org/html/rfc4518 |
|
119 | + * @param Name $other Object to compare to |
|
120 | + * @return bool |
|
121 | + */ |
|
122 | + public function equals(Name $other): bool |
|
123 | + { |
|
124 | + // if RDN count doesn't match |
|
125 | + if (count($this) != count($other)) { |
|
126 | + return false; |
|
127 | + } |
|
128 | + for ($i = count($this) - 1; $i >= 0; --$i) { |
|
129 | + $rdn1 = $this->_rdns[$i]; |
|
130 | + $rdn2 = $other->_rdns[$i]; |
|
131 | + if (!$rdn1->equals($rdn2)) { |
|
132 | + return false; |
|
133 | + } |
|
134 | + } |
|
135 | + return true; |
|
136 | + } |
|
137 | 137 | |
138 | - /** |
|
139 | - * Get all RDN objects. |
|
140 | - * |
|
141 | - * @return RDN[] |
|
142 | - */ |
|
143 | - public function all(): array |
|
144 | - { |
|
145 | - return $this->_rdns; |
|
146 | - } |
|
138 | + /** |
|
139 | + * Get all RDN objects. |
|
140 | + * |
|
141 | + * @return RDN[] |
|
142 | + */ |
|
143 | + public function all(): array |
|
144 | + { |
|
145 | + return $this->_rdns; |
|
146 | + } |
|
147 | 147 | |
148 | - /** |
|
149 | - * Get the first AttributeValue of given type. |
|
150 | - * |
|
151 | - * Relative name components shall be traversed in encoding order, which is |
|
152 | - * reversed in regards to the string representation. |
|
153 | - * Multi-valued RDN with multiple attributes of the requested type is |
|
154 | - * ambiguous and shall throw an exception. |
|
155 | - * |
|
156 | - * @param string $name Attribute OID or name |
|
157 | - * @throws \RuntimeException If attribute cannot be resolved |
|
158 | - * @return AttributeValue |
|
159 | - */ |
|
160 | - public function firstValueOf(string $name): AttributeValue |
|
161 | - { |
|
162 | - $oid = AttributeType::attrNameToOID($name); |
|
163 | - foreach ($this->_rdns as $rdn) { |
|
164 | - $tvs = $rdn->allOf($oid); |
|
165 | - if (count($tvs) > 1) { |
|
166 | - throw new \RangeException("RDN with multiple $name attributes."); |
|
167 | - } |
|
168 | - if (1 == count($tvs)) { |
|
169 | - return $tvs[0]->value(); |
|
170 | - } |
|
171 | - } |
|
172 | - throw new \RangeException("Attribute $name not found."); |
|
173 | - } |
|
148 | + /** |
|
149 | + * Get the first AttributeValue of given type. |
|
150 | + * |
|
151 | + * Relative name components shall be traversed in encoding order, which is |
|
152 | + * reversed in regards to the string representation. |
|
153 | + * Multi-valued RDN with multiple attributes of the requested type is |
|
154 | + * ambiguous and shall throw an exception. |
|
155 | + * |
|
156 | + * @param string $name Attribute OID or name |
|
157 | + * @throws \RuntimeException If attribute cannot be resolved |
|
158 | + * @return AttributeValue |
|
159 | + */ |
|
160 | + public function firstValueOf(string $name): AttributeValue |
|
161 | + { |
|
162 | + $oid = AttributeType::attrNameToOID($name); |
|
163 | + foreach ($this->_rdns as $rdn) { |
|
164 | + $tvs = $rdn->allOf($oid); |
|
165 | + if (count($tvs) > 1) { |
|
166 | + throw new \RangeException("RDN with multiple $name attributes."); |
|
167 | + } |
|
168 | + if (1 == count($tvs)) { |
|
169 | + return $tvs[0]->value(); |
|
170 | + } |
|
171 | + } |
|
172 | + throw new \RangeException("Attribute $name not found."); |
|
173 | + } |
|
174 | 174 | |
175 | - /** |
|
176 | - * |
|
177 | - * @see \Countable::count() |
|
178 | - * @return int |
|
179 | - */ |
|
180 | - public function count(): int |
|
181 | - { |
|
182 | - return count($this->_rdns); |
|
183 | - } |
|
175 | + /** |
|
176 | + * |
|
177 | + * @see \Countable::count() |
|
178 | + * @return int |
|
179 | + */ |
|
180 | + public function count(): int |
|
181 | + { |
|
182 | + return count($this->_rdns); |
|
183 | + } |
|
184 | 184 | |
185 | - /** |
|
186 | - * Get the number of attributes of given type. |
|
187 | - * |
|
188 | - * @param string $name Attribute OID or name |
|
189 | - * @return int |
|
190 | - */ |
|
191 | - public function countOfType(string $name): int |
|
192 | - { |
|
193 | - $oid = AttributeType::attrNameToOID($name); |
|
194 | - return array_sum( |
|
195 | - array_map( |
|
196 | - function (RDN $rdn) use ($oid) { |
|
197 | - return count($rdn->allOf($oid)); |
|
198 | - }, $this->_rdns)); |
|
199 | - } |
|
185 | + /** |
|
186 | + * Get the number of attributes of given type. |
|
187 | + * |
|
188 | + * @param string $name Attribute OID or name |
|
189 | + * @return int |
|
190 | + */ |
|
191 | + public function countOfType(string $name): int |
|
192 | + { |
|
193 | + $oid = AttributeType::attrNameToOID($name); |
|
194 | + return array_sum( |
|
195 | + array_map( |
|
196 | + function (RDN $rdn) use ($oid) { |
|
197 | + return count($rdn->allOf($oid)); |
|
198 | + }, $this->_rdns)); |
|
199 | + } |
|
200 | 200 | |
201 | - /** |
|
202 | - * |
|
203 | - * @see \IteratorAggregate::getIterator() |
|
204 | - * @return \ArrayIterator |
|
205 | - */ |
|
206 | - public function getIterator(): \ArrayIterator |
|
207 | - { |
|
208 | - return new \ArrayIterator($this->_rdns); |
|
209 | - } |
|
201 | + /** |
|
202 | + * |
|
203 | + * @see \IteratorAggregate::getIterator() |
|
204 | + * @return \ArrayIterator |
|
205 | + */ |
|
206 | + public function getIterator(): \ArrayIterator |
|
207 | + { |
|
208 | + return new \ArrayIterator($this->_rdns); |
|
209 | + } |
|
210 | 210 | |
211 | - /** |
|
212 | - * |
|
213 | - * @return string |
|
214 | - */ |
|
215 | - public function __toString() |
|
216 | - { |
|
217 | - return $this->toString(); |
|
218 | - } |
|
211 | + /** |
|
212 | + * |
|
213 | + * @return string |
|
214 | + */ |
|
215 | + public function __toString() |
|
216 | + { |
|
217 | + return $this->toString(); |
|
218 | + } |
|
219 | 219 | } |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | public static function fromASN1(Sequence $seq): self |
48 | 48 | { |
49 | 49 | $rdns = array_map( |
50 | - function (UnspecifiedType $el) { |
|
50 | + function(UnspecifiedType $el) { |
|
51 | 51 | return RDN::fromASN1($el->asSet()); |
52 | 52 | }, $seq->elements()); |
53 | 53 | return new self(...$rdns); |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | public function toASN1(): Sequence |
91 | 91 | { |
92 | 92 | $elements = array_map( |
93 | - function (RDN $rdn) { |
|
93 | + function(RDN $rdn) { |
|
94 | 94 | return $rdn->toASN1(); |
95 | 95 | }, $this->_rdns); |
96 | 96 | return new Sequence(...$elements); |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | public function toString(): string |
106 | 106 | { |
107 | 107 | $parts = array_map( |
108 | - function (RDN $rdn) { |
|
108 | + function(RDN $rdn) { |
|
109 | 109 | return $rdn->toString(); |
110 | 110 | }, array_reverse($this->_rdns)); |
111 | 111 | return implode(",", $parts); |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | $oid = AttributeType::attrNameToOID($name); |
194 | 194 | return array_sum( |
195 | 195 | array_map( |
196 | - function (RDN $rdn) use ($oid) { |
|
196 | + function(RDN $rdn) use ($oid) { |
|
197 | 197 | return count($rdn->allOf($oid)); |
198 | 198 | }, $this->_rdns)); |
199 | 199 | } |
@@ -16,111 +16,111 @@ |
||
16 | 16 | */ |
17 | 17 | class AttributeTypeAndValue |
18 | 18 | { |
19 | - use TypedAttribute; |
|
19 | + use TypedAttribute; |
|
20 | 20 | |
21 | - /** |
|
22 | - * Attribute value. |
|
23 | - * |
|
24 | - * @var AttributeValue $_value |
|
25 | - */ |
|
26 | - protected $_value; |
|
21 | + /** |
|
22 | + * Attribute value. |
|
23 | + * |
|
24 | + * @var AttributeValue $_value |
|
25 | + */ |
|
26 | + protected $_value; |
|
27 | 27 | |
28 | - /** |
|
29 | - * Constructor. |
|
30 | - * |
|
31 | - * @param AttributeType $type Attribute type |
|
32 | - * @param AttributeValue $value Attribute value |
|
33 | - */ |
|
34 | - public function __construct(AttributeType $type, AttributeValue $value) |
|
35 | - { |
|
36 | - $this->_type = $type; |
|
37 | - $this->_value = $value; |
|
38 | - } |
|
28 | + /** |
|
29 | + * Constructor. |
|
30 | + * |
|
31 | + * @param AttributeType $type Attribute type |
|
32 | + * @param AttributeValue $value Attribute value |
|
33 | + */ |
|
34 | + public function __construct(AttributeType $type, AttributeValue $value) |
|
35 | + { |
|
36 | + $this->_type = $type; |
|
37 | + $this->_value = $value; |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * Initialize from ASN.1. |
|
42 | - * |
|
43 | - * @param Sequence $seq |
|
44 | - * @return self |
|
45 | - */ |
|
46 | - public static function fromASN1(Sequence $seq): self |
|
47 | - { |
|
48 | - $type = AttributeType::fromASN1($seq->at(0)->asObjectIdentifier()); |
|
49 | - $value = AttributeValue::fromASN1ByOID($type->oid(), $seq->at(1)); |
|
50 | - return new self($type, $value); |
|
51 | - } |
|
40 | + /** |
|
41 | + * Initialize from ASN.1. |
|
42 | + * |
|
43 | + * @param Sequence $seq |
|
44 | + * @return self |
|
45 | + */ |
|
46 | + public static function fromASN1(Sequence $seq): self |
|
47 | + { |
|
48 | + $type = AttributeType::fromASN1($seq->at(0)->asObjectIdentifier()); |
|
49 | + $value = AttributeValue::fromASN1ByOID($type->oid(), $seq->at(1)); |
|
50 | + return new self($type, $value); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Convenience method to initialize from attribute value. |
|
55 | - * |
|
56 | - * @param AttributeValue $value Attribute value |
|
57 | - * @return self |
|
58 | - */ |
|
59 | - public static function fromAttributeValue(AttributeValue $value): self |
|
60 | - { |
|
61 | - return new self(new AttributeType($value->oid()), $value); |
|
62 | - } |
|
53 | + /** |
|
54 | + * Convenience method to initialize from attribute value. |
|
55 | + * |
|
56 | + * @param AttributeValue $value Attribute value |
|
57 | + * @return self |
|
58 | + */ |
|
59 | + public static function fromAttributeValue(AttributeValue $value): self |
|
60 | + { |
|
61 | + return new self(new AttributeType($value->oid()), $value); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Get attribute value. |
|
66 | - * |
|
67 | - * @return AttributeValue |
|
68 | - */ |
|
69 | - public function value(): AttributeValue |
|
70 | - { |
|
71 | - return $this->_value; |
|
72 | - } |
|
64 | + /** |
|
65 | + * Get attribute value. |
|
66 | + * |
|
67 | + * @return AttributeValue |
|
68 | + */ |
|
69 | + public function value(): AttributeValue |
|
70 | + { |
|
71 | + return $this->_value; |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * Generate ASN.1 structure. |
|
76 | - * |
|
77 | - * @return Sequence |
|
78 | - */ |
|
79 | - public function toASN1(): Sequence |
|
80 | - { |
|
81 | - return new Sequence($this->_type->toASN1(), $this->_value->toASN1()); |
|
82 | - } |
|
74 | + /** |
|
75 | + * Generate ASN.1 structure. |
|
76 | + * |
|
77 | + * @return Sequence |
|
78 | + */ |
|
79 | + public function toASN1(): Sequence |
|
80 | + { |
|
81 | + return new Sequence($this->_type->toASN1(), $this->_value->toASN1()); |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * Get attributeTypeAndValue string conforming to RFC 2253. |
|
86 | - * |
|
87 | - * @link https://tools.ietf.org/html/rfc2253#section-2.3 |
|
88 | - * @return string |
|
89 | - */ |
|
90 | - public function toString(): string |
|
91 | - { |
|
92 | - return $this->_type->typeName() . "=" . $this->_value->rfc2253String(); |
|
93 | - } |
|
84 | + /** |
|
85 | + * Get attributeTypeAndValue string conforming to RFC 2253. |
|
86 | + * |
|
87 | + * @link https://tools.ietf.org/html/rfc2253#section-2.3 |
|
88 | + * @return string |
|
89 | + */ |
|
90 | + public function toString(): string |
|
91 | + { |
|
92 | + return $this->_type->typeName() . "=" . $this->_value->rfc2253String(); |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * Check whether attribute is semantically equal to other. |
|
97 | - * |
|
98 | - * @param AttributeTypeAndValue $other Object to compare to |
|
99 | - * @return bool |
|
100 | - */ |
|
101 | - public function equals(AttributeTypeAndValue $other): bool |
|
102 | - { |
|
103 | - // check that attribute types match |
|
104 | - if ($this->oid() !== $other->oid()) { |
|
105 | - return false; |
|
106 | - } |
|
107 | - $matcher = $this->_value->equalityMatchingRule(); |
|
108 | - $result = $matcher->compare($this->_value->stringValue(), |
|
109 | - $other->_value->stringValue()); |
|
110 | - // match |
|
111 | - if ($result) { |
|
112 | - return true; |
|
113 | - } |
|
114 | - // no match or Undefined |
|
115 | - return false; |
|
116 | - } |
|
95 | + /** |
|
96 | + * Check whether attribute is semantically equal to other. |
|
97 | + * |
|
98 | + * @param AttributeTypeAndValue $other Object to compare to |
|
99 | + * @return bool |
|
100 | + */ |
|
101 | + public function equals(AttributeTypeAndValue $other): bool |
|
102 | + { |
|
103 | + // check that attribute types match |
|
104 | + if ($this->oid() !== $other->oid()) { |
|
105 | + return false; |
|
106 | + } |
|
107 | + $matcher = $this->_value->equalityMatchingRule(); |
|
108 | + $result = $matcher->compare($this->_value->stringValue(), |
|
109 | + $other->_value->stringValue()); |
|
110 | + // match |
|
111 | + if ($result) { |
|
112 | + return true; |
|
113 | + } |
|
114 | + // no match or Undefined |
|
115 | + return false; |
|
116 | + } |
|
117 | 117 | |
118 | - /** |
|
119 | - * |
|
120 | - * @return string |
|
121 | - */ |
|
122 | - public function __toString() |
|
123 | - { |
|
124 | - return $this->toString(); |
|
125 | - } |
|
118 | + /** |
|
119 | + * |
|
120 | + * @return string |
|
121 | + */ |
|
122 | + public function __toString() |
|
123 | + { |
|
124 | + return $this->toString(); |
|
125 | + } |
|
126 | 126 | } |
@@ -16,169 +16,169 @@ |
||
16 | 16 | */ |
17 | 17 | class RDN implements \Countable, \IteratorAggregate |
18 | 18 | { |
19 | - /** |
|
20 | - * Attributes. |
|
21 | - * |
|
22 | - * @var AttributeTypeAndValue[] $_attribs |
|
23 | - */ |
|
24 | - protected $_attribs; |
|
19 | + /** |
|
20 | + * Attributes. |
|
21 | + * |
|
22 | + * @var AttributeTypeAndValue[] $_attribs |
|
23 | + */ |
|
24 | + protected $_attribs; |
|
25 | 25 | |
26 | - /** |
|
27 | - * Constructor. |
|
28 | - * |
|
29 | - * @param AttributeTypeAndValue ...$attribs One or more attributes |
|
30 | - */ |
|
31 | - public function __construct(AttributeTypeAndValue ...$attribs) |
|
32 | - { |
|
33 | - if (!count($attribs)) { |
|
34 | - throw new \UnexpectedValueException( |
|
35 | - "RDN must have at least one AttributeTypeAndValue."); |
|
36 | - } |
|
37 | - $this->_attribs = $attribs; |
|
38 | - } |
|
26 | + /** |
|
27 | + * Constructor. |
|
28 | + * |
|
29 | + * @param AttributeTypeAndValue ...$attribs One or more attributes |
|
30 | + */ |
|
31 | + public function __construct(AttributeTypeAndValue ...$attribs) |
|
32 | + { |
|
33 | + if (!count($attribs)) { |
|
34 | + throw new \UnexpectedValueException( |
|
35 | + "RDN must have at least one AttributeTypeAndValue."); |
|
36 | + } |
|
37 | + $this->_attribs = $attribs; |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * Convenience method to initialize RDN from AttributeValue objects. |
|
42 | - * |
|
43 | - * @param AttributeValue ...$values One or more attributes |
|
44 | - * @return self |
|
45 | - */ |
|
46 | - public static function fromAttributeValues(AttributeValue ...$values): self |
|
47 | - { |
|
48 | - $attribs = array_map( |
|
49 | - function (AttributeValue $value) { |
|
50 | - return new AttributeTypeAndValue( |
|
51 | - new AttributeType($value->oid()), $value); |
|
52 | - }, $values); |
|
53 | - return new self(...$attribs); |
|
54 | - } |
|
40 | + /** |
|
41 | + * Convenience method to initialize RDN from AttributeValue objects. |
|
42 | + * |
|
43 | + * @param AttributeValue ...$values One or more attributes |
|
44 | + * @return self |
|
45 | + */ |
|
46 | + public static function fromAttributeValues(AttributeValue ...$values): self |
|
47 | + { |
|
48 | + $attribs = array_map( |
|
49 | + function (AttributeValue $value) { |
|
50 | + return new AttributeTypeAndValue( |
|
51 | + new AttributeType($value->oid()), $value); |
|
52 | + }, $values); |
|
53 | + return new self(...$attribs); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * Initialize from ASN.1. |
|
58 | - * |
|
59 | - * @param Set $set |
|
60 | - * @return self |
|
61 | - */ |
|
62 | - public static function fromASN1(Set $set): self |
|
63 | - { |
|
64 | - $attribs = array_map( |
|
65 | - function (UnspecifiedType $el) { |
|
66 | - return AttributeTypeAndValue::fromASN1($el->asSequence()); |
|
67 | - }, $set->elements()); |
|
68 | - return new self(...$attribs); |
|
69 | - } |
|
56 | + /** |
|
57 | + * Initialize from ASN.1. |
|
58 | + * |
|
59 | + * @param Set $set |
|
60 | + * @return self |
|
61 | + */ |
|
62 | + public static function fromASN1(Set $set): self |
|
63 | + { |
|
64 | + $attribs = array_map( |
|
65 | + function (UnspecifiedType $el) { |
|
66 | + return AttributeTypeAndValue::fromASN1($el->asSequence()); |
|
67 | + }, $set->elements()); |
|
68 | + return new self(...$attribs); |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * Generate ASN.1 structure. |
|
73 | - * |
|
74 | - * @return Set |
|
75 | - */ |
|
76 | - public function toASN1(): Set |
|
77 | - { |
|
78 | - $elements = array_map( |
|
79 | - function (AttributeTypeAndValue $tv) { |
|
80 | - return $tv->toASN1(); |
|
81 | - }, $this->_attribs); |
|
82 | - $set = new Set(...$elements); |
|
83 | - return $set->sortedSetOf(); |
|
84 | - } |
|
71 | + /** |
|
72 | + * Generate ASN.1 structure. |
|
73 | + * |
|
74 | + * @return Set |
|
75 | + */ |
|
76 | + public function toASN1(): Set |
|
77 | + { |
|
78 | + $elements = array_map( |
|
79 | + function (AttributeTypeAndValue $tv) { |
|
80 | + return $tv->toASN1(); |
|
81 | + }, $this->_attribs); |
|
82 | + $set = new Set(...$elements); |
|
83 | + return $set->sortedSetOf(); |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Get name-component string conforming to RFC 2253. |
|
88 | - * |
|
89 | - * @link https://tools.ietf.org/html/rfc2253#section-2.2 |
|
90 | - * @return string |
|
91 | - */ |
|
92 | - public function toString(): string |
|
93 | - { |
|
94 | - $parts = array_map( |
|
95 | - function (AttributeTypeAndValue $tv) { |
|
96 | - return $tv->toString(); |
|
97 | - }, $this->_attribs); |
|
98 | - return implode("+", $parts); |
|
99 | - } |
|
86 | + /** |
|
87 | + * Get name-component string conforming to RFC 2253. |
|
88 | + * |
|
89 | + * @link https://tools.ietf.org/html/rfc2253#section-2.2 |
|
90 | + * @return string |
|
91 | + */ |
|
92 | + public function toString(): string |
|
93 | + { |
|
94 | + $parts = array_map( |
|
95 | + function (AttributeTypeAndValue $tv) { |
|
96 | + return $tv->toString(); |
|
97 | + }, $this->_attribs); |
|
98 | + return implode("+", $parts); |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Check whether RDN is semantically equal to other. |
|
103 | - * |
|
104 | - * @param RDN $other Object to compare to |
|
105 | - * @return bool |
|
106 | - */ |
|
107 | - public function equals(RDN $other): bool |
|
108 | - { |
|
109 | - // if attribute count doesn't match |
|
110 | - if (count($this) != count($other)) { |
|
111 | - return false; |
|
112 | - } |
|
113 | - $attribs1 = $this->_attribs; |
|
114 | - $attribs2 = $other->_attribs; |
|
115 | - // if there's multiple attributes, sort using SET OF rules |
|
116 | - if (count($attribs1) > 1) { |
|
117 | - $attribs1 = self::fromASN1($this->toASN1())->_attribs; |
|
118 | - $attribs2 = self::fromASN1($other->toASN1())->_attribs; |
|
119 | - } |
|
120 | - for ($i = count($attribs1) - 1; $i >= 0; --$i) { |
|
121 | - $tv1 = $attribs1[$i]; |
|
122 | - $tv2 = $attribs2[$i]; |
|
123 | - if (!$tv1->equals($tv2)) { |
|
124 | - return false; |
|
125 | - } |
|
126 | - } |
|
127 | - return true; |
|
128 | - } |
|
101 | + /** |
|
102 | + * Check whether RDN is semantically equal to other. |
|
103 | + * |
|
104 | + * @param RDN $other Object to compare to |
|
105 | + * @return bool |
|
106 | + */ |
|
107 | + public function equals(RDN $other): bool |
|
108 | + { |
|
109 | + // if attribute count doesn't match |
|
110 | + if (count($this) != count($other)) { |
|
111 | + return false; |
|
112 | + } |
|
113 | + $attribs1 = $this->_attribs; |
|
114 | + $attribs2 = $other->_attribs; |
|
115 | + // if there's multiple attributes, sort using SET OF rules |
|
116 | + if (count($attribs1) > 1) { |
|
117 | + $attribs1 = self::fromASN1($this->toASN1())->_attribs; |
|
118 | + $attribs2 = self::fromASN1($other->toASN1())->_attribs; |
|
119 | + } |
|
120 | + for ($i = count($attribs1) - 1; $i >= 0; --$i) { |
|
121 | + $tv1 = $attribs1[$i]; |
|
122 | + $tv2 = $attribs2[$i]; |
|
123 | + if (!$tv1->equals($tv2)) { |
|
124 | + return false; |
|
125 | + } |
|
126 | + } |
|
127 | + return true; |
|
128 | + } |
|
129 | 129 | |
130 | - /** |
|
131 | - * Get all AttributeTypeAndValue objects. |
|
132 | - * |
|
133 | - * @return AttributeTypeAndValue[] |
|
134 | - */ |
|
135 | - public function all(): array |
|
136 | - { |
|
137 | - return $this->_attribs; |
|
138 | - } |
|
130 | + /** |
|
131 | + * Get all AttributeTypeAndValue objects. |
|
132 | + * |
|
133 | + * @return AttributeTypeAndValue[] |
|
134 | + */ |
|
135 | + public function all(): array |
|
136 | + { |
|
137 | + return $this->_attribs; |
|
138 | + } |
|
139 | 139 | |
140 | - /** |
|
141 | - * Get all AttributeTypeAndValue objects of the given attribute type. |
|
142 | - * |
|
143 | - * @param string $name Attribute OID or name |
|
144 | - * @return AttributeTypeAndValue[] |
|
145 | - */ |
|
146 | - public function allOf(string $name): array |
|
147 | - { |
|
148 | - $oid = AttributeType::attrNameToOID($name); |
|
149 | - $attribs = array_filter($this->_attribs, |
|
150 | - function (AttributeTypeAndValue $tv) use ($oid) { |
|
151 | - return $tv->oid() == $oid; |
|
152 | - }); |
|
153 | - return array_values($attribs); |
|
154 | - } |
|
140 | + /** |
|
141 | + * Get all AttributeTypeAndValue objects of the given attribute type. |
|
142 | + * |
|
143 | + * @param string $name Attribute OID or name |
|
144 | + * @return AttributeTypeAndValue[] |
|
145 | + */ |
|
146 | + public function allOf(string $name): array |
|
147 | + { |
|
148 | + $oid = AttributeType::attrNameToOID($name); |
|
149 | + $attribs = array_filter($this->_attribs, |
|
150 | + function (AttributeTypeAndValue $tv) use ($oid) { |
|
151 | + return $tv->oid() == $oid; |
|
152 | + }); |
|
153 | + return array_values($attribs); |
|
154 | + } |
|
155 | 155 | |
156 | - /** |
|
157 | - * |
|
158 | - * @see \Countable::count() |
|
159 | - * @return int |
|
160 | - */ |
|
161 | - public function count(): int |
|
162 | - { |
|
163 | - return count($this->_attribs); |
|
164 | - } |
|
156 | + /** |
|
157 | + * |
|
158 | + * @see \Countable::count() |
|
159 | + * @return int |
|
160 | + */ |
|
161 | + public function count(): int |
|
162 | + { |
|
163 | + return count($this->_attribs); |
|
164 | + } |
|
165 | 165 | |
166 | - /** |
|
167 | - * |
|
168 | - * @see \IteratorAggregate::getIterator() |
|
169 | - * @return \ArrayIterator |
|
170 | - */ |
|
171 | - public function getIterator(): \ArrayIterator |
|
172 | - { |
|
173 | - return new \ArrayIterator($this->_attribs); |
|
174 | - } |
|
166 | + /** |
|
167 | + * |
|
168 | + * @see \IteratorAggregate::getIterator() |
|
169 | + * @return \ArrayIterator |
|
170 | + */ |
|
171 | + public function getIterator(): \ArrayIterator |
|
172 | + { |
|
173 | + return new \ArrayIterator($this->_attribs); |
|
174 | + } |
|
175 | 175 | |
176 | - /** |
|
177 | - * |
|
178 | - * @return string |
|
179 | - */ |
|
180 | - public function __toString() |
|
181 | - { |
|
182 | - return $this->toString(); |
|
183 | - } |
|
176 | + /** |
|
177 | + * |
|
178 | + * @return string |
|
179 | + */ |
|
180 | + public function __toString() |
|
181 | + { |
|
182 | + return $this->toString(); |
|
183 | + } |
|
184 | 184 | } |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | public static function fromAttributeValues(AttributeValue ...$values): self |
47 | 47 | { |
48 | 48 | $attribs = array_map( |
49 | - function (AttributeValue $value) { |
|
49 | + function(AttributeValue $value) { |
|
50 | 50 | return new AttributeTypeAndValue( |
51 | 51 | new AttributeType($value->oid()), $value); |
52 | 52 | }, $values); |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | public static function fromASN1(Set $set): self |
63 | 63 | { |
64 | 64 | $attribs = array_map( |
65 | - function (UnspecifiedType $el) { |
|
65 | + function(UnspecifiedType $el) { |
|
66 | 66 | return AttributeTypeAndValue::fromASN1($el->asSequence()); |
67 | 67 | }, $set->elements()); |
68 | 68 | return new self(...$attribs); |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | public function toASN1(): Set |
77 | 77 | { |
78 | 78 | $elements = array_map( |
79 | - function (AttributeTypeAndValue $tv) { |
|
79 | + function(AttributeTypeAndValue $tv) { |
|
80 | 80 | return $tv->toASN1(); |
81 | 81 | }, $this->_attribs); |
82 | 82 | $set = new Set(...$elements); |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | public function toString(): string |
93 | 93 | { |
94 | 94 | $parts = array_map( |
95 | - function (AttributeTypeAndValue $tv) { |
|
95 | + function(AttributeTypeAndValue $tv) { |
|
96 | 96 | return $tv->toString(); |
97 | 97 | }, $this->_attribs); |
98 | 98 | return implode("+", $parts); |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | { |
148 | 148 | $oid = AttributeType::attrNameToOID($name); |
149 | 149 | $attribs = array_filter($this->_attribs, |
150 | - function (AttributeTypeAndValue $tv) use ($oid) { |
|
150 | + function(AttributeTypeAndValue $tv) use ($oid) { |
|
151 | 151 | return $tv->oid() == $oid; |
152 | 152 | }); |
153 | 153 | return array_values($attribs); |