1 | <?php |
||
31 | class Extensions implements \Countable, \IteratorAggregate |
||
32 | { |
||
33 | /** |
||
34 | * Extensions |
||
35 | * |
||
36 | * @var Extension[] $_extensions |
||
37 | */ |
||
38 | protected $_extensions; |
||
39 | |||
40 | /** |
||
41 | * Constructor |
||
42 | * |
||
43 | * @param Extension ...$extensions Extension objects |
||
44 | */ |
||
45 | 62 | public function __construct(Extension ...$extensions) { |
|
46 | 62 | $this->_extensions = array(); |
|
47 | 62 | foreach ($extensions as $ext) { |
|
48 | 38 | $this->_extensions[$ext->oid()] = $ext; |
|
49 | 62 | } |
|
50 | 62 | } |
|
51 | |||
52 | /** |
||
53 | * Initialize from ASN.1. |
||
54 | * |
||
55 | * @param Sequence $seq |
||
56 | * @return self |
||
57 | */ |
||
58 | 24 | public static function fromASN1(Sequence $seq) { |
|
59 | 24 | $extensions = array_map( |
|
60 | function (UnspecifiedType $el) { |
||
61 | 21 | return Extension::fromASN1($el->asSequence()); |
|
62 | 24 | }, $seq->elements()); |
|
63 | 24 | return new self(...$extensions); |
|
64 | } |
||
65 | |||
66 | /** |
||
67 | * Generate ASN.1 structure. |
||
68 | * |
||
69 | * @return Sequence |
||
70 | */ |
||
71 | 56 | public function toASN1() { |
|
78 | |||
79 | /** |
||
80 | * Get self with extensions added. |
||
81 | * |
||
82 | * @param Extension ...$ext One or more extensions to add |
||
83 | * @return self |
||
84 | */ |
||
85 | 5 | public function withExtensions(Extension ...$exts) { |
|
92 | |||
93 | /** |
||
94 | * Check whether extension is present. |
||
95 | * |
||
96 | * @param string $oid Extensions OID |
||
97 | * @return bool |
||
98 | */ |
||
99 | 96 | public function has($oid) { |
|
102 | |||
103 | /** |
||
104 | * Get extension by OID. |
||
105 | * |
||
106 | * @param string $oid |
||
107 | * @throws \LogicException |
||
108 | * @return Extension |
||
109 | */ |
||
110 | 75 | public function get($oid) { |
|
116 | |||
117 | /** |
||
118 | * Check whether 'Authority Key Identifier' extension is present. |
||
119 | * |
||
120 | * @return bool |
||
121 | */ |
||
122 | 10 | public function hasAuthorityKeyIdentifier() { |
|
125 | |||
126 | /** |
||
127 | * Get 'Authority Key Identifier' extension. |
||
128 | * |
||
129 | * @return AuthorityKeyIdentifierExtension |
||
130 | */ |
||
131 | 11 | public function authorityKeyIdentifier() { |
|
134 | |||
135 | /** |
||
136 | * Check whether 'Subject Key Identifier' extension is present. |
||
137 | * |
||
138 | * @return bool |
||
139 | */ |
||
140 | 12 | public function hasSubjectKeyIdentifier() { |
|
143 | |||
144 | /** |
||
145 | * Get 'Subject Key Identifier' extension. |
||
146 | * |
||
147 | * @return SubjectKeyIdentifierExtension |
||
148 | */ |
||
149 | 11 | public function subjectKeyIdentifier() { |
|
152 | |||
153 | /** |
||
154 | * Check whether 'Key Usage' extension is present. |
||
155 | * |
||
156 | * @return bool |
||
157 | */ |
||
158 | 33 | public function hasKeyUsage() { |
|
161 | |||
162 | /** |
||
163 | * Get 'Key Usage' extension. |
||
164 | * |
||
165 | * @return KeyUsageExtension |
||
166 | */ |
||
167 | 21 | public function keyUsage() { |
|
170 | |||
171 | /** |
||
172 | * Check whether 'Certificate Policies' extension is present. |
||
173 | * |
||
174 | * @return bool |
||
175 | */ |
||
176 | 36 | public function hasCertificatePolicies() { |
|
179 | |||
180 | /** |
||
181 | * Get 'Certificate Policies' extension. |
||
182 | * |
||
183 | * @return CertificatePoliciesExtension |
||
184 | */ |
||
185 | 1 | public function certificatePolicies() { |
|
188 | |||
189 | /** |
||
190 | * Check whether 'Policy Mappings' extension is present. |
||
191 | * |
||
192 | * @return bool |
||
193 | */ |
||
194 | 36 | public function hasPolicyMappings() { |
|
197 | |||
198 | /** |
||
199 | * Get 'Policy Mappings' extension. |
||
200 | * |
||
201 | * @return PolicyMappingsExtension |
||
202 | */ |
||
203 | 4 | public function policyMappings() { |
|
206 | |||
207 | /** |
||
208 | * Check whether 'Subject Alternative Name' extension is present. |
||
209 | * |
||
210 | * @return bool |
||
211 | */ |
||
212 | 3 | public function hasSubjectAlternativeName() { |
|
213 | 3 | return $this->has(Extension::OID_SUBJECT_ALT_NAME); |
|
214 | } |
||
215 | |||
216 | /** |
||
217 | * Get 'Subject Alternative Name' extension. |
||
218 | * |
||
219 | * @return SubjectAlternativeNameExtension |
||
220 | */ |
||
221 | 4 | public function subjectAlternativeName() { |
|
224 | |||
225 | /** |
||
226 | * Check whether 'Issuer Alternative Name' extension is present. |
||
227 | * |
||
228 | * @return bool |
||
229 | */ |
||
230 | 1 | public function hasIssuerAlternativeName() { |
|
233 | |||
234 | /** |
||
235 | * Get 'Issuer Alternative Name' extension. |
||
236 | * |
||
237 | * @return IssuerAlternativeNameExtension |
||
238 | */ |
||
239 | 1 | public function issuerAlternativeName() { |
|
242 | |||
243 | /** |
||
244 | * Check whether 'Basic Constraints' extension is present. |
||
245 | * |
||
246 | * @return bool |
||
247 | */ |
||
248 | 35 | public function hasBasicConstraints() { |
|
251 | |||
252 | /** |
||
253 | * Get 'Basic Constraints' extension. |
||
254 | * |
||
255 | * @return BasicConstraintsExtension |
||
256 | */ |
||
257 | 32 | public function basicConstraints() { |
|
260 | |||
261 | /** |
||
262 | * Check whether 'Name Constraints' extension is present. |
||
263 | * |
||
264 | * @return bool |
||
265 | */ |
||
266 | 35 | public function hasNameConstraints() { |
|
269 | |||
270 | /** |
||
271 | * Get 'Name Constraints' extension. |
||
272 | * |
||
273 | * @return NameConstraintsExtension |
||
274 | */ |
||
275 | 1 | public function nameConstraints() { |
|
278 | |||
279 | /** |
||
280 | * Check whether 'Policy Constraints' extension is present. |
||
281 | * |
||
282 | * @return bool |
||
283 | */ |
||
284 | 35 | public function hasPolicyConstraints() { |
|
287 | |||
288 | /** |
||
289 | * Get 'Policy Constraints' extension. |
||
290 | * |
||
291 | * @return PolicyConstraintsExtension |
||
292 | */ |
||
293 | 16 | public function policyConstraints() { |
|
296 | |||
297 | /** |
||
298 | * Check whether 'Extended Key Usage' extension is present. |
||
299 | * |
||
300 | * @return bool |
||
301 | */ |
||
302 | 1 | public function hasExtendedKeyUsage() { |
|
305 | |||
306 | /** |
||
307 | * Get 'Extended Key Usage' extension. |
||
308 | * |
||
309 | * @return ExtendedKeyUsageExtension |
||
310 | */ |
||
311 | 1 | public function extendedKeyUsage() { |
|
314 | |||
315 | /** |
||
316 | * Check whether 'CRL Distribution Points' extension is present. |
||
317 | * |
||
318 | * @return bool |
||
319 | */ |
||
320 | 1 | public function hasCRLDistributionPoints() { |
|
323 | |||
324 | /** |
||
325 | * Get 'CRL Distribution Points' extension. |
||
326 | * |
||
327 | * @return CRLDistributionPointsExtension |
||
328 | */ |
||
329 | 1 | public function crlDistributionPoints() { |
|
332 | |||
333 | /** |
||
334 | * Check whether 'Inhibit anyPolicy' extension is present. |
||
335 | * |
||
336 | * @return bool |
||
337 | */ |
||
338 | 35 | public function hasInhibitAnyPolicy() { |
|
341 | |||
342 | /** |
||
343 | * Get 'Inhibit anyPolicy' extension. |
||
344 | * |
||
345 | * @return InhibitAnyPolicyExtension |
||
346 | */ |
||
347 | 2 | public function inhibitAnyPolicy() { |
|
350 | |||
351 | /** |
||
352 | * |
||
353 | * @see Countable::count() |
||
354 | * @return int |
||
355 | */ |
||
356 | 67 | public function count() { |
|
359 | |||
360 | /** |
||
361 | * Get iterator for extensions. |
||
362 | * |
||
363 | * @see IteratorAggregate::getIterator() |
||
364 | * @return \Traversable |
||
365 | */ |
||
366 | 1 | public function getIterator() { |
|
369 | } |
||
370 |