@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types=1); |
|
3 | +declare(strict_types = 1); |
|
4 | 4 | |
5 | 5 | namespace X509\GeneralName; |
6 | 6 |
@@ -15,60 +15,60 @@ |
||
15 | 15 | */ |
16 | 16 | class RegisteredID extends GeneralName |
17 | 17 | { |
18 | - /** |
|
19 | - * Object identifier. |
|
20 | - * |
|
21 | - * @var string $_oid |
|
22 | - */ |
|
23 | - protected $_oid; |
|
18 | + /** |
|
19 | + * Object identifier. |
|
20 | + * |
|
21 | + * @var string $_oid |
|
22 | + */ |
|
23 | + protected $_oid; |
|
24 | 24 | |
25 | - /** |
|
26 | - * Constructor. |
|
27 | - * |
|
28 | - * @param string $oid OID in dotted format |
|
29 | - */ |
|
30 | - public function __construct(string $oid) |
|
31 | - { |
|
32 | - $this->_tag = self::TAG_REGISTERED_ID; |
|
33 | - $this->_oid = $oid; |
|
34 | - } |
|
25 | + /** |
|
26 | + * Constructor. |
|
27 | + * |
|
28 | + * @param string $oid OID in dotted format |
|
29 | + */ |
|
30 | + public function __construct(string $oid) |
|
31 | + { |
|
32 | + $this->_tag = self::TAG_REGISTERED_ID; |
|
33 | + $this->_oid = $oid; |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * |
|
38 | - * @param UnspecifiedType $el |
|
39 | - * @return self |
|
40 | - */ |
|
41 | - public static function fromChosenASN1(UnspecifiedType $el) |
|
42 | - { |
|
43 | - return new self($el->asObjectIdentifier()->oid()); |
|
44 | - } |
|
36 | + /** |
|
37 | + * |
|
38 | + * @param UnspecifiedType $el |
|
39 | + * @return self |
|
40 | + */ |
|
41 | + public static function fromChosenASN1(UnspecifiedType $el) |
|
42 | + { |
|
43 | + return new self($el->asObjectIdentifier()->oid()); |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * |
|
48 | - * {@inheritdoc} |
|
49 | - */ |
|
50 | - public function string(): string |
|
51 | - { |
|
52 | - return $this->_oid; |
|
53 | - } |
|
46 | + /** |
|
47 | + * |
|
48 | + * {@inheritdoc} |
|
49 | + */ |
|
50 | + public function string(): string |
|
51 | + { |
|
52 | + return $this->_oid; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * Get object identifier in dotted format. |
|
57 | - * |
|
58 | - * @return string OID |
|
59 | - */ |
|
60 | - public function oid(): string |
|
61 | - { |
|
62 | - return $this->_oid; |
|
63 | - } |
|
55 | + /** |
|
56 | + * Get object identifier in dotted format. |
|
57 | + * |
|
58 | + * @return string OID |
|
59 | + */ |
|
60 | + public function oid(): string |
|
61 | + { |
|
62 | + return $this->_oid; |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * |
|
67 | - * {@inheritdoc} |
|
68 | - */ |
|
69 | - protected function _choiceASN1() |
|
70 | - { |
|
71 | - return new ImplicitlyTaggedType($this->_tag, |
|
72 | - new ObjectIdentifier($this->_oid)); |
|
73 | - } |
|
65 | + /** |
|
66 | + * |
|
67 | + * {@inheritdoc} |
|
68 | + */ |
|
69 | + protected function _choiceASN1() |
|
70 | + { |
|
71 | + return new ImplicitlyTaggedType($this->_tag, |
|
72 | + new ObjectIdentifier($this->_oid)); |
|
73 | + } |
|
74 | 74 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types=1); |
|
3 | +declare(strict_types = 1); |
|
4 | 4 | |
5 | 5 | namespace X509\GeneralName; |
6 | 6 |
@@ -17,183 +17,183 @@ |
||
17 | 17 | */ |
18 | 18 | class GeneralNames implements \Countable, \IteratorAggregate |
19 | 19 | { |
20 | - /** |
|
21 | - * GeneralName objects. |
|
22 | - * |
|
23 | - * @var GeneralName[] $_names |
|
24 | - */ |
|
25 | - protected $_names; |
|
20 | + /** |
|
21 | + * GeneralName objects. |
|
22 | + * |
|
23 | + * @var GeneralName[] $_names |
|
24 | + */ |
|
25 | + protected $_names; |
|
26 | 26 | |
27 | - /** |
|
28 | - * Constructor. |
|
29 | - * |
|
30 | - * @param GeneralName ...$names One or more GeneralName objects |
|
31 | - */ |
|
32 | - public function __construct(GeneralName ...$names) |
|
33 | - { |
|
34 | - $this->_names = $names; |
|
35 | - } |
|
27 | + /** |
|
28 | + * Constructor. |
|
29 | + * |
|
30 | + * @param GeneralName ...$names One or more GeneralName objects |
|
31 | + */ |
|
32 | + public function __construct(GeneralName ...$names) |
|
33 | + { |
|
34 | + $this->_names = $names; |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * Initialize from ASN.1. |
|
39 | - * |
|
40 | - * @param Sequence $seq |
|
41 | - * @throws \UnexpectedValueException |
|
42 | - * @return self |
|
43 | - */ |
|
44 | - public static function fromASN1(Sequence $seq) |
|
45 | - { |
|
46 | - if (!count($seq)) { |
|
47 | - throw new \UnexpectedValueException( |
|
48 | - "GeneralNames must have at least one GeneralName."); |
|
49 | - } |
|
50 | - $names = array_map( |
|
51 | - function (UnspecifiedType $el) { |
|
52 | - return GeneralName::fromASN1($el->asTagged()); |
|
53 | - }, $seq->elements()); |
|
54 | - return new self(...$names); |
|
55 | - } |
|
37 | + /** |
|
38 | + * Initialize from ASN.1. |
|
39 | + * |
|
40 | + * @param Sequence $seq |
|
41 | + * @throws \UnexpectedValueException |
|
42 | + * @return self |
|
43 | + */ |
|
44 | + public static function fromASN1(Sequence $seq) |
|
45 | + { |
|
46 | + if (!count($seq)) { |
|
47 | + throw new \UnexpectedValueException( |
|
48 | + "GeneralNames must have at least one GeneralName."); |
|
49 | + } |
|
50 | + $names = array_map( |
|
51 | + function (UnspecifiedType $el) { |
|
52 | + return GeneralName::fromASN1($el->asTagged()); |
|
53 | + }, $seq->elements()); |
|
54 | + return new self(...$names); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Find first GeneralName by given tag. |
|
59 | - * |
|
60 | - * @param int $tag |
|
61 | - * @return GeneralName|null |
|
62 | - */ |
|
63 | - protected function _findFirst($tag) |
|
64 | - { |
|
65 | - foreach ($this->_names as $name) { |
|
66 | - if ($name->tag() == $tag) { |
|
67 | - return $name; |
|
68 | - } |
|
69 | - } |
|
70 | - return null; |
|
71 | - } |
|
57 | + /** |
|
58 | + * Find first GeneralName by given tag. |
|
59 | + * |
|
60 | + * @param int $tag |
|
61 | + * @return GeneralName|null |
|
62 | + */ |
|
63 | + protected function _findFirst($tag) |
|
64 | + { |
|
65 | + foreach ($this->_names as $name) { |
|
66 | + if ($name->tag() == $tag) { |
|
67 | + return $name; |
|
68 | + } |
|
69 | + } |
|
70 | + return null; |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * Check whether GeneralNames contains a GeneralName of given type. |
|
75 | - * |
|
76 | - * @param int $tag One of <code>GeneralName::TAG_*</code> enumerations |
|
77 | - * @return bool |
|
78 | - */ |
|
79 | - public function has($tag): bool |
|
80 | - { |
|
81 | - return null !== $this->_findFirst($tag); |
|
82 | - } |
|
73 | + /** |
|
74 | + * Check whether GeneralNames contains a GeneralName of given type. |
|
75 | + * |
|
76 | + * @param int $tag One of <code>GeneralName::TAG_*</code> enumerations |
|
77 | + * @return bool |
|
78 | + */ |
|
79 | + public function has($tag): bool |
|
80 | + { |
|
81 | + return null !== $this->_findFirst($tag); |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * Get first GeneralName of given type. |
|
86 | - * |
|
87 | - * @param int $tag One of <code>GeneralName::TAG_*</code> enumerations |
|
88 | - * @throws \OutOfBoundsException |
|
89 | - * @return GeneralName |
|
90 | - */ |
|
91 | - public function firstOf($tag): GeneralName |
|
92 | - { |
|
93 | - $name = $this->_findFirst($tag); |
|
94 | - if (!$name) { |
|
95 | - throw new \UnexpectedValueException("No GeneralName by tag $tag."); |
|
96 | - } |
|
97 | - return $name; |
|
98 | - } |
|
84 | + /** |
|
85 | + * Get first GeneralName of given type. |
|
86 | + * |
|
87 | + * @param int $tag One of <code>GeneralName::TAG_*</code> enumerations |
|
88 | + * @throws \OutOfBoundsException |
|
89 | + * @return GeneralName |
|
90 | + */ |
|
91 | + public function firstOf($tag): GeneralName |
|
92 | + { |
|
93 | + $name = $this->_findFirst($tag); |
|
94 | + if (!$name) { |
|
95 | + throw new \UnexpectedValueException("No GeneralName by tag $tag."); |
|
96 | + } |
|
97 | + return $name; |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * Get all GeneralName objects of given type. |
|
102 | - * |
|
103 | - * @param int $tag One of <code>GeneralName::TAG_*</code> enumerations |
|
104 | - * @return GeneralName[] |
|
105 | - */ |
|
106 | - public function allOf($tag): array |
|
107 | - { |
|
108 | - $names = array_filter($this->_names, |
|
109 | - function (GeneralName $name) use ($tag) { |
|
110 | - return $name->tag() == $tag; |
|
111 | - }); |
|
112 | - return array_values($names); |
|
113 | - } |
|
100 | + /** |
|
101 | + * Get all GeneralName objects of given type. |
|
102 | + * |
|
103 | + * @param int $tag One of <code>GeneralName::TAG_*</code> enumerations |
|
104 | + * @return GeneralName[] |
|
105 | + */ |
|
106 | + public function allOf($tag): array |
|
107 | + { |
|
108 | + $names = array_filter($this->_names, |
|
109 | + function (GeneralName $name) use ($tag) { |
|
110 | + return $name->tag() == $tag; |
|
111 | + }); |
|
112 | + return array_values($names); |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * Get value of the first 'dNSName' type. |
|
117 | - * |
|
118 | - * @return string |
|
119 | - */ |
|
120 | - public function firstDNS(): string |
|
121 | - { |
|
122 | - $gn = $this->firstOf(GeneralName::TAG_DNS_NAME); |
|
123 | - if (!$gn instanceof DNSName) { |
|
124 | - throw new \RuntimeException( |
|
125 | - DNSName::class . " expected, got " . get_class($gn)); |
|
126 | - } |
|
127 | - return $gn->name(); |
|
128 | - } |
|
115 | + /** |
|
116 | + * Get value of the first 'dNSName' type. |
|
117 | + * |
|
118 | + * @return string |
|
119 | + */ |
|
120 | + public function firstDNS(): string |
|
121 | + { |
|
122 | + $gn = $this->firstOf(GeneralName::TAG_DNS_NAME); |
|
123 | + if (!$gn instanceof DNSName) { |
|
124 | + throw new \RuntimeException( |
|
125 | + DNSName::class . " expected, got " . get_class($gn)); |
|
126 | + } |
|
127 | + return $gn->name(); |
|
128 | + } |
|
129 | 129 | |
130 | - /** |
|
131 | - * Get value of the first 'directoryName' type. |
|
132 | - * |
|
133 | - * @return \X501\ASN1\Name |
|
134 | - */ |
|
135 | - public function firstDN(): \X501\ASN1\Name |
|
136 | - { |
|
137 | - $gn = $this->firstOf(GeneralName::TAG_DIRECTORY_NAME); |
|
138 | - if (!$gn instanceof DirectoryName) { |
|
139 | - throw new \RuntimeException( |
|
140 | - DirectoryName::class . " expected, got " . get_class($gn)); |
|
141 | - } |
|
142 | - return $gn->dn(); |
|
143 | - } |
|
130 | + /** |
|
131 | + * Get value of the first 'directoryName' type. |
|
132 | + * |
|
133 | + * @return \X501\ASN1\Name |
|
134 | + */ |
|
135 | + public function firstDN(): \X501\ASN1\Name |
|
136 | + { |
|
137 | + $gn = $this->firstOf(GeneralName::TAG_DIRECTORY_NAME); |
|
138 | + if (!$gn instanceof DirectoryName) { |
|
139 | + throw new \RuntimeException( |
|
140 | + DirectoryName::class . " expected, got " . get_class($gn)); |
|
141 | + } |
|
142 | + return $gn->dn(); |
|
143 | + } |
|
144 | 144 | |
145 | - /** |
|
146 | - * Get value of the first 'uniformResourceIdentifier' type. |
|
147 | - * |
|
148 | - * @return string |
|
149 | - */ |
|
150 | - public function firstURI(): string |
|
151 | - { |
|
152 | - $gn = $this->firstOf(GeneralName::TAG_URI); |
|
153 | - if (!$gn instanceof UniformResourceIdentifier) { |
|
154 | - throw new \RuntimeException( |
|
155 | - UniformResourceIdentifier::class . " expected, got " . |
|
156 | - get_class($gn)); |
|
157 | - } |
|
158 | - return $gn->uri(); |
|
159 | - } |
|
145 | + /** |
|
146 | + * Get value of the first 'uniformResourceIdentifier' type. |
|
147 | + * |
|
148 | + * @return string |
|
149 | + */ |
|
150 | + public function firstURI(): string |
|
151 | + { |
|
152 | + $gn = $this->firstOf(GeneralName::TAG_URI); |
|
153 | + if (!$gn instanceof UniformResourceIdentifier) { |
|
154 | + throw new \RuntimeException( |
|
155 | + UniformResourceIdentifier::class . " expected, got " . |
|
156 | + get_class($gn)); |
|
157 | + } |
|
158 | + return $gn->uri(); |
|
159 | + } |
|
160 | 160 | |
161 | - /** |
|
162 | - * Generate ASN.1 structure. |
|
163 | - * |
|
164 | - * @return Sequence |
|
165 | - */ |
|
166 | - public function toASN1(): Sequence |
|
167 | - { |
|
168 | - if (!count($this->_names)) { |
|
169 | - throw new \LogicException( |
|
170 | - "GeneralNames must have at least one GeneralName."); |
|
171 | - } |
|
172 | - $elements = array_map( |
|
173 | - function (GeneralName $name) { |
|
174 | - return $name->toASN1(); |
|
175 | - }, $this->_names); |
|
176 | - return new Sequence(...$elements); |
|
177 | - } |
|
161 | + /** |
|
162 | + * Generate ASN.1 structure. |
|
163 | + * |
|
164 | + * @return Sequence |
|
165 | + */ |
|
166 | + public function toASN1(): Sequence |
|
167 | + { |
|
168 | + if (!count($this->_names)) { |
|
169 | + throw new \LogicException( |
|
170 | + "GeneralNames must have at least one GeneralName."); |
|
171 | + } |
|
172 | + $elements = array_map( |
|
173 | + function (GeneralName $name) { |
|
174 | + return $name->toASN1(); |
|
175 | + }, $this->_names); |
|
176 | + return new Sequence(...$elements); |
|
177 | + } |
|
178 | 178 | |
179 | - /** |
|
180 | - * |
|
181 | - * @see \Countable::count() |
|
182 | - * @return int |
|
183 | - */ |
|
184 | - public function count(): int |
|
185 | - { |
|
186 | - return count($this->_names); |
|
187 | - } |
|
179 | + /** |
|
180 | + * |
|
181 | + * @see \Countable::count() |
|
182 | + * @return int |
|
183 | + */ |
|
184 | + public function count(): int |
|
185 | + { |
|
186 | + return count($this->_names); |
|
187 | + } |
|
188 | 188 | |
189 | - /** |
|
190 | - * Get iterator for GeneralName objects. |
|
191 | - * |
|
192 | - * @see \IteratorAggregate::getIterator() |
|
193 | - * @return \ArrayIterator |
|
194 | - */ |
|
195 | - public function getIterator(): \ArrayIterator |
|
196 | - { |
|
197 | - return new \ArrayIterator($this->_names); |
|
198 | - } |
|
189 | + /** |
|
190 | + * Get iterator for GeneralName objects. |
|
191 | + * |
|
192 | + * @see \IteratorAggregate::getIterator() |
|
193 | + * @return \ArrayIterator |
|
194 | + */ |
|
195 | + public function getIterator(): \ArrayIterator |
|
196 | + { |
|
197 | + return new \ArrayIterator($this->_names); |
|
198 | + } |
|
199 | 199 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types=1); |
|
3 | +declare(strict_types = 1); |
|
4 | 4 | |
5 | 5 | namespace X509\GeneralName; |
6 | 6 | |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | "GeneralNames must have at least one GeneralName."); |
49 | 49 | } |
50 | 50 | $names = array_map( |
51 | - function (UnspecifiedType $el) { |
|
51 | + function(UnspecifiedType $el) { |
|
52 | 52 | return GeneralName::fromASN1($el->asTagged()); |
53 | 53 | }, $seq->elements()); |
54 | 54 | return new self(...$names); |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | public function allOf($tag): array |
107 | 107 | { |
108 | 108 | $names = array_filter($this->_names, |
109 | - function (GeneralName $name) use ($tag) { |
|
109 | + function(GeneralName $name) use ($tag) { |
|
110 | 110 | return $name->tag() == $tag; |
111 | 111 | }); |
112 | 112 | return array_values($names); |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | "GeneralNames must have at least one GeneralName."); |
171 | 171 | } |
172 | 172 | $elements = array_map( |
173 | - function (GeneralName $name) { |
|
173 | + function(GeneralName $name) { |
|
174 | 174 | return $name->toASN1(); |
175 | 175 | }, $this->_names); |
176 | 176 | return new Sequence(...$elements); |
@@ -15,59 +15,59 @@ |
||
15 | 15 | */ |
16 | 16 | class RFC822Name extends GeneralName |
17 | 17 | { |
18 | - /** |
|
19 | - * Email. |
|
20 | - * |
|
21 | - * @var string $_email |
|
22 | - */ |
|
23 | - protected $_email; |
|
18 | + /** |
|
19 | + * Email. |
|
20 | + * |
|
21 | + * @var string $_email |
|
22 | + */ |
|
23 | + protected $_email; |
|
24 | 24 | |
25 | - /** |
|
26 | - * Constructor. |
|
27 | - * |
|
28 | - * @param string $email |
|
29 | - */ |
|
30 | - public function __construct(string $email) |
|
31 | - { |
|
32 | - $this->_tag = self::TAG_RFC822_NAME; |
|
33 | - $this->_email = $email; |
|
34 | - } |
|
25 | + /** |
|
26 | + * Constructor. |
|
27 | + * |
|
28 | + * @param string $email |
|
29 | + */ |
|
30 | + public function __construct(string $email) |
|
31 | + { |
|
32 | + $this->_tag = self::TAG_RFC822_NAME; |
|
33 | + $this->_email = $email; |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * |
|
38 | - * @param UnspecifiedType $el |
|
39 | - * @return self |
|
40 | - */ |
|
41 | - public static function fromChosenASN1(UnspecifiedType $el) |
|
42 | - { |
|
43 | - return new self($el->asIA5String()->string()); |
|
44 | - } |
|
36 | + /** |
|
37 | + * |
|
38 | + * @param UnspecifiedType $el |
|
39 | + * @return self |
|
40 | + */ |
|
41 | + public static function fromChosenASN1(UnspecifiedType $el) |
|
42 | + { |
|
43 | + return new self($el->asIA5String()->string()); |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * |
|
48 | - * {@inheritdoc} |
|
49 | - */ |
|
50 | - public function string(): string |
|
51 | - { |
|
52 | - return $this->_email; |
|
53 | - } |
|
46 | + /** |
|
47 | + * |
|
48 | + * {@inheritdoc} |
|
49 | + */ |
|
50 | + public function string(): string |
|
51 | + { |
|
52 | + return $this->_email; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * Get email. |
|
57 | - * |
|
58 | - * @return string |
|
59 | - */ |
|
60 | - public function email(): string |
|
61 | - { |
|
62 | - return $this->_email; |
|
63 | - } |
|
55 | + /** |
|
56 | + * Get email. |
|
57 | + * |
|
58 | + * @return string |
|
59 | + */ |
|
60 | + public function email(): string |
|
61 | + { |
|
62 | + return $this->_email; |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * |
|
67 | - * {@inheritdoc} |
|
68 | - */ |
|
69 | - protected function _choiceASN1() |
|
70 | - { |
|
71 | - return new ImplicitlyTaggedType($this->_tag, new IA5String($this->_email)); |
|
72 | - } |
|
65 | + /** |
|
66 | + * |
|
67 | + * {@inheritdoc} |
|
68 | + */ |
|
69 | + protected function _choiceASN1() |
|
70 | + { |
|
71 | + return new ImplicitlyTaggedType($this->_tag, new IA5String($this->_email)); |
|
72 | + } |
|
73 | 73 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types=1); |
|
3 | +declare(strict_types = 1); |
|
4 | 4 | |
5 | 5 | namespace X509\GeneralName; |
6 | 6 |
@@ -15,72 +15,72 @@ |
||
15 | 15 | */ |
16 | 16 | class DirectoryName extends GeneralName |
17 | 17 | { |
18 | - /** |
|
19 | - * Directory name. |
|
20 | - * |
|
21 | - * @var Name $_dn |
|
22 | - */ |
|
23 | - protected $_dn; |
|
18 | + /** |
|
19 | + * Directory name. |
|
20 | + * |
|
21 | + * @var Name $_dn |
|
22 | + */ |
|
23 | + protected $_dn; |
|
24 | 24 | |
25 | - /** |
|
26 | - * Constructor. |
|
27 | - * |
|
28 | - * @param Name $dn |
|
29 | - */ |
|
30 | - public function __construct(Name $dn) |
|
31 | - { |
|
32 | - $this->_tag = self::TAG_DIRECTORY_NAME; |
|
33 | - $this->_dn = $dn; |
|
34 | - } |
|
25 | + /** |
|
26 | + * Constructor. |
|
27 | + * |
|
28 | + * @param Name $dn |
|
29 | + */ |
|
30 | + public function __construct(Name $dn) |
|
31 | + { |
|
32 | + $this->_tag = self::TAG_DIRECTORY_NAME; |
|
33 | + $this->_dn = $dn; |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * |
|
38 | - * @param UnspecifiedType $el |
|
39 | - * @return self |
|
40 | - */ |
|
41 | - public static function fromChosenASN1(UnspecifiedType $el) |
|
42 | - { |
|
43 | - return new self(Name::fromASN1($el->asSequence())); |
|
44 | - } |
|
36 | + /** |
|
37 | + * |
|
38 | + * @param UnspecifiedType $el |
|
39 | + * @return self |
|
40 | + */ |
|
41 | + public static function fromChosenASN1(UnspecifiedType $el) |
|
42 | + { |
|
43 | + return new self(Name::fromASN1($el->asSequence())); |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Initialize from distinguished name string. |
|
48 | - * |
|
49 | - * @param string $str |
|
50 | - * @return self |
|
51 | - */ |
|
52 | - public static function fromDNString($str) |
|
53 | - { |
|
54 | - return new self(Name::fromString($str)); |
|
55 | - } |
|
46 | + /** |
|
47 | + * Initialize from distinguished name string. |
|
48 | + * |
|
49 | + * @param string $str |
|
50 | + * @return self |
|
51 | + */ |
|
52 | + public static function fromDNString($str) |
|
53 | + { |
|
54 | + return new self(Name::fromString($str)); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * |
|
59 | - * {@inheritdoc} |
|
60 | - */ |
|
61 | - public function string(): string |
|
62 | - { |
|
63 | - return $this->_dn->toString(); |
|
64 | - } |
|
57 | + /** |
|
58 | + * |
|
59 | + * {@inheritdoc} |
|
60 | + */ |
|
61 | + public function string(): string |
|
62 | + { |
|
63 | + return $this->_dn->toString(); |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * Get directory name. |
|
68 | - * |
|
69 | - * @return Name |
|
70 | - */ |
|
71 | - public function dn(): Name |
|
72 | - { |
|
73 | - return $this->_dn; |
|
74 | - } |
|
66 | + /** |
|
67 | + * Get directory name. |
|
68 | + * |
|
69 | + * @return Name |
|
70 | + */ |
|
71 | + public function dn(): Name |
|
72 | + { |
|
73 | + return $this->_dn; |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * |
|
78 | - * {@inheritdoc} |
|
79 | - */ |
|
80 | - protected function _choiceASN1() |
|
81 | - { |
|
82 | - // Name type is itself a CHOICE, so explicit tagging must be |
|
83 | - // employed to avoid ambiguities |
|
84 | - return new ExplicitlyTaggedType($this->_tag, $this->_dn->toASN1()); |
|
85 | - } |
|
76 | + /** |
|
77 | + * |
|
78 | + * {@inheritdoc} |
|
79 | + */ |
|
80 | + protected function _choiceASN1() |
|
81 | + { |
|
82 | + // Name type is itself a CHOICE, so explicit tagging must be |
|
83 | + // employed to avoid ambiguities |
|
84 | + return new ExplicitlyTaggedType($this->_tag, $this->_dn->toASN1()); |
|
85 | + } |
|
86 | 86 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types=1); |
|
3 | +declare(strict_types = 1); |
|
4 | 4 | |
5 | 5 | namespace X509\GeneralName; |
6 | 6 |
@@ -15,47 +15,47 @@ |
||
15 | 15 | */ |
16 | 16 | class EDIPartyName extends GeneralName |
17 | 17 | { |
18 | - /** |
|
19 | - * |
|
20 | - * @var \ASN1\Element |
|
21 | - */ |
|
22 | - protected $_element; |
|
18 | + /** |
|
19 | + * |
|
20 | + * @var \ASN1\Element |
|
21 | + */ |
|
22 | + protected $_element; |
|
23 | 23 | |
24 | - /** |
|
25 | - * Constructor. |
|
26 | - */ |
|
27 | - protected function __construct() |
|
28 | - { |
|
29 | - $this->_tag = self::TAG_EDI_PARTY_NAME; |
|
30 | - } |
|
24 | + /** |
|
25 | + * Constructor. |
|
26 | + */ |
|
27 | + protected function __construct() |
|
28 | + { |
|
29 | + $this->_tag = self::TAG_EDI_PARTY_NAME; |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * |
|
34 | - * @param UnspecifiedType $el |
|
35 | - * @return self |
|
36 | - */ |
|
37 | - public static function fromChosenASN1(UnspecifiedType $el) |
|
38 | - { |
|
39 | - $obj = new self(); |
|
40 | - $obj->_element = $el->asSequence(); |
|
41 | - return $obj; |
|
42 | - } |
|
32 | + /** |
|
33 | + * |
|
34 | + * @param UnspecifiedType $el |
|
35 | + * @return self |
|
36 | + */ |
|
37 | + public static function fromChosenASN1(UnspecifiedType $el) |
|
38 | + { |
|
39 | + $obj = new self(); |
|
40 | + $obj->_element = $el->asSequence(); |
|
41 | + return $obj; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * |
|
46 | - * {@inheritdoc} |
|
47 | - */ |
|
48 | - public function string(): string |
|
49 | - { |
|
50 | - return bin2hex($this->_element->toDER()); |
|
51 | - } |
|
44 | + /** |
|
45 | + * |
|
46 | + * {@inheritdoc} |
|
47 | + */ |
|
48 | + public function string(): string |
|
49 | + { |
|
50 | + return bin2hex($this->_element->toDER()); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * |
|
55 | - * {@inheritdoc} |
|
56 | - */ |
|
57 | - protected function _choiceASN1() |
|
58 | - { |
|
59 | - return new ImplicitlyTaggedType($this->_tag, $this->_element); |
|
60 | - } |
|
53 | + /** |
|
54 | + * |
|
55 | + * {@inheritdoc} |
|
56 | + */ |
|
57 | + protected function _choiceASN1() |
|
58 | + { |
|
59 | + return new ImplicitlyTaggedType($this->_tag, $this->_element); |
|
60 | + } |
|
61 | 61 | } |
@@ -17,47 +17,47 @@ |
||
17 | 17 | */ |
18 | 18 | class X400Address extends GeneralName |
19 | 19 | { |
20 | - /** |
|
21 | - * |
|
22 | - * @var \ASN1\Element |
|
23 | - */ |
|
24 | - protected $_element; |
|
20 | + /** |
|
21 | + * |
|
22 | + * @var \ASN1\Element |
|
23 | + */ |
|
24 | + protected $_element; |
|
25 | 25 | |
26 | - /** |
|
27 | - * Constructor. |
|
28 | - */ |
|
29 | - protected function __construct() |
|
30 | - { |
|
31 | - $this->_tag = self::TAG_X400_ADDRESS; |
|
32 | - } |
|
26 | + /** |
|
27 | + * Constructor. |
|
28 | + */ |
|
29 | + protected function __construct() |
|
30 | + { |
|
31 | + $this->_tag = self::TAG_X400_ADDRESS; |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * |
|
36 | - * @param UnspecifiedType $el |
|
37 | - * @return self |
|
38 | - */ |
|
39 | - public static function fromChosenASN1(UnspecifiedType $el) |
|
40 | - { |
|
41 | - $obj = new self(); |
|
42 | - $obj->_element = $el->asSequence(); |
|
43 | - return $obj; |
|
44 | - } |
|
34 | + /** |
|
35 | + * |
|
36 | + * @param UnspecifiedType $el |
|
37 | + * @return self |
|
38 | + */ |
|
39 | + public static function fromChosenASN1(UnspecifiedType $el) |
|
40 | + { |
|
41 | + $obj = new self(); |
|
42 | + $obj->_element = $el->asSequence(); |
|
43 | + return $obj; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * |
|
48 | - * {@inheritdoc} |
|
49 | - */ |
|
50 | - public function string(): string |
|
51 | - { |
|
52 | - return bin2hex($this->_element->toDER()); |
|
53 | - } |
|
46 | + /** |
|
47 | + * |
|
48 | + * {@inheritdoc} |
|
49 | + */ |
|
50 | + public function string(): string |
|
51 | + { |
|
52 | + return bin2hex($this->_element->toDER()); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * |
|
57 | - * {@inheritdoc} |
|
58 | - */ |
|
59 | - protected function _choiceASN1() |
|
60 | - { |
|
61 | - return new ImplicitlyTaggedType($this->_tag, $this->_element); |
|
62 | - } |
|
55 | + /** |
|
56 | + * |
|
57 | + * {@inheritdoc} |
|
58 | + */ |
|
59 | + protected function _choiceASN1() |
|
60 | + { |
|
61 | + return new ImplicitlyTaggedType($this->_tag, $this->_element); |
|
62 | + } |
|
63 | 63 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types=1); |
|
3 | +declare(strict_types = 1); |
|
4 | 4 | |
5 | 5 | namespace X509\GeneralName; |
6 | 6 |
@@ -6,57 +6,57 @@ |
||
6 | 6 | |
7 | 7 | class IPv6Address extends IPAddress |
8 | 8 | { |
9 | - /** |
|
10 | - * Initialize from octets. |
|
11 | - * |
|
12 | - * @param string $octets |
|
13 | - * @throws \InvalidArgumentException |
|
14 | - * @return self |
|
15 | - */ |
|
16 | - public static function fromOctets(string $octets) |
|
17 | - { |
|
18 | - $mask = null; |
|
19 | - $words = unpack("n*", $octets); |
|
20 | - switch (count($words)) { |
|
21 | - case 8: |
|
22 | - $ip = self::_wordsToIPv6String($words); |
|
23 | - break; |
|
24 | - case 16: |
|
25 | - $ip = self::_wordsToIPv6String(array_slice($words, 0, 8)); |
|
26 | - $mask = self::_wordsToIPv6String(array_slice($words, 8, 8)); |
|
27 | - break; |
|
28 | - default: |
|
29 | - throw new \UnexpectedValueException("Invalid IPv6 octet length."); |
|
30 | - } |
|
31 | - return new self($ip, $mask); |
|
32 | - } |
|
9 | + /** |
|
10 | + * Initialize from octets. |
|
11 | + * |
|
12 | + * @param string $octets |
|
13 | + * @throws \InvalidArgumentException |
|
14 | + * @return self |
|
15 | + */ |
|
16 | + public static function fromOctets(string $octets) |
|
17 | + { |
|
18 | + $mask = null; |
|
19 | + $words = unpack("n*", $octets); |
|
20 | + switch (count($words)) { |
|
21 | + case 8: |
|
22 | + $ip = self::_wordsToIPv6String($words); |
|
23 | + break; |
|
24 | + case 16: |
|
25 | + $ip = self::_wordsToIPv6String(array_slice($words, 0, 8)); |
|
26 | + $mask = self::_wordsToIPv6String(array_slice($words, 8, 8)); |
|
27 | + break; |
|
28 | + default: |
|
29 | + throw new \UnexpectedValueException("Invalid IPv6 octet length."); |
|
30 | + } |
|
31 | + return new self($ip, $mask); |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * Convert an array of 16 bit words to an IPv6 string representation. |
|
36 | - * |
|
37 | - * @param int[] $words |
|
38 | - * @return string |
|
39 | - */ |
|
40 | - protected static function _wordsToIPv6String(array $words): string |
|
41 | - { |
|
42 | - $groups = array_map( |
|
43 | - function ($word) { |
|
44 | - return sprintf("%04x", $word); |
|
45 | - }, $words); |
|
46 | - return implode(":", $groups); |
|
47 | - } |
|
34 | + /** |
|
35 | + * Convert an array of 16 bit words to an IPv6 string representation. |
|
36 | + * |
|
37 | + * @param int[] $words |
|
38 | + * @return string |
|
39 | + */ |
|
40 | + protected static function _wordsToIPv6String(array $words): string |
|
41 | + { |
|
42 | + $groups = array_map( |
|
43 | + function ($word) { |
|
44 | + return sprintf("%04x", $word); |
|
45 | + }, $words); |
|
46 | + return implode(":", $groups); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * |
|
51 | - * {@inheritdoc} |
|
52 | - */ |
|
53 | - protected function _octets(): string |
|
54 | - { |
|
55 | - $words = array_map("hexdec", explode(":", $this->_ip)); |
|
56 | - if (isset($this->_mask)) { |
|
57 | - $words = array_merge($words, |
|
58 | - array_map("hexdec", explode(":", $this->_mask))); |
|
59 | - } |
|
60 | - return pack("n*", ...$words); |
|
61 | - } |
|
49 | + /** |
|
50 | + * |
|
51 | + * {@inheritdoc} |
|
52 | + */ |
|
53 | + protected function _octets(): string |
|
54 | + { |
|
55 | + $words = array_map("hexdec", explode(":", $this->_ip)); |
|
56 | + if (isset($this->_mask)) { |
|
57 | + $words = array_merge($words, |
|
58 | + array_map("hexdec", explode(":", $this->_mask))); |
|
59 | + } |
|
60 | + return pack("n*", ...$words); |
|
61 | + } |
|
62 | 62 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types=1); |
|
3 | +declare(strict_types = 1); |
|
4 | 4 | |
5 | 5 | namespace X509\GeneralName; |
6 | 6 | |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | protected static function _wordsToIPv6String(array $words): string |
41 | 41 | { |
42 | 42 | $groups = array_map( |
43 | - function ($word) { |
|
43 | + function($word) { |
|
44 | 44 | return sprintf("%04x", $word); |
45 | 45 | }, $words); |
46 | 46 | return implode(":", $groups); |
@@ -18,97 +18,97 @@ |
||
18 | 18 | */ |
19 | 19 | abstract class IPAddress extends GeneralName |
20 | 20 | { |
21 | - /** |
|
22 | - * IP address. |
|
23 | - * |
|
24 | - * @var string $_ip |
|
25 | - */ |
|
26 | - protected $_ip; |
|
21 | + /** |
|
22 | + * IP address. |
|
23 | + * |
|
24 | + * @var string $_ip |
|
25 | + */ |
|
26 | + protected $_ip; |
|
27 | 27 | |
28 | - /** |
|
29 | - * Subnet mask. |
|
30 | - * |
|
31 | - * @var string|null $_mask |
|
32 | - */ |
|
33 | - protected $_mask; |
|
28 | + /** |
|
29 | + * Subnet mask. |
|
30 | + * |
|
31 | + * @var string|null $_mask |
|
32 | + */ |
|
33 | + protected $_mask; |
|
34 | 34 | |
35 | - /** |
|
36 | - * Get octet representation of the IP address. |
|
37 | - * |
|
38 | - * @return string |
|
39 | - */ |
|
40 | - abstract protected function _octets(); |
|
35 | + /** |
|
36 | + * Get octet representation of the IP address. |
|
37 | + * |
|
38 | + * @return string |
|
39 | + */ |
|
40 | + abstract protected function _octets(); |
|
41 | 41 | |
42 | - /** |
|
43 | - * Constructor. |
|
44 | - * |
|
45 | - * @param string $ip |
|
46 | - * @param string|null $mask |
|
47 | - */ |
|
48 | - public function __construct(string $ip, $mask = null) |
|
49 | - { |
|
50 | - $this->_tag = self::TAG_IP_ADDRESS; |
|
51 | - $this->_ip = $ip; |
|
52 | - $this->_mask = $mask; |
|
53 | - } |
|
42 | + /** |
|
43 | + * Constructor. |
|
44 | + * |
|
45 | + * @param string $ip |
|
46 | + * @param string|null $mask |
|
47 | + */ |
|
48 | + public function __construct(string $ip, $mask = null) |
|
49 | + { |
|
50 | + $this->_tag = self::TAG_IP_ADDRESS; |
|
51 | + $this->_ip = $ip; |
|
52 | + $this->_mask = $mask; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * |
|
57 | - * @param UnspecifiedType $el |
|
58 | - * @return self |
|
59 | - */ |
|
60 | - public static function fromChosenASN1(UnspecifiedType $el) |
|
61 | - { |
|
62 | - $octets = $el->asOctetString()->string(); |
|
63 | - switch (strlen($octets)) { |
|
64 | - case 4: |
|
65 | - case 8: |
|
66 | - return IPv4Address::fromOctets($octets); |
|
67 | - case 16: |
|
68 | - case 32: |
|
69 | - return IPv6Address::fromOctets($octets); |
|
70 | - default: |
|
71 | - throw new \UnexpectedValueException( |
|
72 | - "Invalid octet length for IP address."); |
|
73 | - } |
|
74 | - } |
|
55 | + /** |
|
56 | + * |
|
57 | + * @param UnspecifiedType $el |
|
58 | + * @return self |
|
59 | + */ |
|
60 | + public static function fromChosenASN1(UnspecifiedType $el) |
|
61 | + { |
|
62 | + $octets = $el->asOctetString()->string(); |
|
63 | + switch (strlen($octets)) { |
|
64 | + case 4: |
|
65 | + case 8: |
|
66 | + return IPv4Address::fromOctets($octets); |
|
67 | + case 16: |
|
68 | + case 32: |
|
69 | + return IPv6Address::fromOctets($octets); |
|
70 | + default: |
|
71 | + throw new \UnexpectedValueException( |
|
72 | + "Invalid octet length for IP address."); |
|
73 | + } |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * |
|
78 | - * {@inheritdoc} |
|
79 | - */ |
|
80 | - public function string(): string |
|
81 | - { |
|
82 | - return $this->_ip . (isset($this->_mask) ? "/" . $this->_mask : ""); |
|
83 | - } |
|
76 | + /** |
|
77 | + * |
|
78 | + * {@inheritdoc} |
|
79 | + */ |
|
80 | + public function string(): string |
|
81 | + { |
|
82 | + return $this->_ip . (isset($this->_mask) ? "/" . $this->_mask : ""); |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * Get IP address as a string. |
|
87 | - * |
|
88 | - * @return string |
|
89 | - */ |
|
90 | - public function address(): string |
|
91 | - { |
|
92 | - return $this->_ip; |
|
93 | - } |
|
85 | + /** |
|
86 | + * Get IP address as a string. |
|
87 | + * |
|
88 | + * @return string |
|
89 | + */ |
|
90 | + public function address(): string |
|
91 | + { |
|
92 | + return $this->_ip; |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * Get subnet mask as a string. |
|
97 | - * |
|
98 | - * @return string |
|
99 | - */ |
|
100 | - public function mask(): string |
|
101 | - { |
|
102 | - return $this->_mask; |
|
103 | - } |
|
95 | + /** |
|
96 | + * Get subnet mask as a string. |
|
97 | + * |
|
98 | + * @return string |
|
99 | + */ |
|
100 | + public function mask(): string |
|
101 | + { |
|
102 | + return $this->_mask; |
|
103 | + } |
|
104 | 104 | |
105 | - /** |
|
106 | - * |
|
107 | - * {@inheritdoc} |
|
108 | - */ |
|
109 | - protected function _choiceASN1() |
|
110 | - { |
|
111 | - return new ImplicitlyTaggedType($this->_tag, |
|
112 | - new OctetString($this->_octets())); |
|
113 | - } |
|
105 | + /** |
|
106 | + * |
|
107 | + * {@inheritdoc} |
|
108 | + */ |
|
109 | + protected function _choiceASN1() |
|
110 | + { |
|
111 | + return new ImplicitlyTaggedType($this->_tag, |
|
112 | + new OctetString($this->_octets())); |
|
113 | + } |
|
114 | 114 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types=1); |
|
3 | +declare(strict_types = 1); |
|
4 | 4 | |
5 | 5 | namespace X509\GeneralName; |
6 | 6 |