@@ -12,112 +12,112 @@ |
||
12 | 12 | */ |
13 | 13 | class ACValidationConfig |
14 | 14 | { |
15 | - /** |
|
16 | - * Certification path of the AC holder. |
|
17 | - * |
|
18 | - * @var CertificationPath |
|
19 | - */ |
|
20 | - protected $_holderPath; |
|
15 | + /** |
|
16 | + * Certification path of the AC holder. |
|
17 | + * |
|
18 | + * @var CertificationPath |
|
19 | + */ |
|
20 | + protected $_holderPath; |
|
21 | 21 | |
22 | - /** |
|
23 | - * Certification path of the AC issuer. |
|
24 | - * |
|
25 | - * @var CertificationPath |
|
26 | - */ |
|
27 | - protected $_issuerPath; |
|
22 | + /** |
|
23 | + * Certification path of the AC issuer. |
|
24 | + * |
|
25 | + * @var CertificationPath |
|
26 | + */ |
|
27 | + protected $_issuerPath; |
|
28 | 28 | |
29 | - /** |
|
30 | - * Evaluation reference time. |
|
31 | - * |
|
32 | - * @var \DateTimeImmutable |
|
33 | - */ |
|
34 | - protected $_evalTime; |
|
29 | + /** |
|
30 | + * Evaluation reference time. |
|
31 | + * |
|
32 | + * @var \DateTimeImmutable |
|
33 | + */ |
|
34 | + protected $_evalTime; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Permitted targets. |
|
38 | - * |
|
39 | - * @var Target[] |
|
40 | - */ |
|
41 | - protected $_targets; |
|
36 | + /** |
|
37 | + * Permitted targets. |
|
38 | + * |
|
39 | + * @var Target[] |
|
40 | + */ |
|
41 | + protected $_targets; |
|
42 | 42 | |
43 | - /** |
|
44 | - * Constructor. |
|
45 | - * |
|
46 | - * @param CertificationPath $holder_path Certification path of the AC holder |
|
47 | - * @param CertificationPath $issuer_path Certification path of the AC issuer |
|
48 | - */ |
|
49 | - public function __construct(CertificationPath $holder_path, |
|
50 | - CertificationPath $issuer_path) |
|
51 | - { |
|
52 | - $this->_holderPath = $holder_path; |
|
53 | - $this->_issuerPath = $issuer_path; |
|
54 | - $this->_evalTime = new \DateTimeImmutable(); |
|
55 | - $this->_targets = array(); |
|
56 | - } |
|
43 | + /** |
|
44 | + * Constructor. |
|
45 | + * |
|
46 | + * @param CertificationPath $holder_path Certification path of the AC holder |
|
47 | + * @param CertificationPath $issuer_path Certification path of the AC issuer |
|
48 | + */ |
|
49 | + public function __construct(CertificationPath $holder_path, |
|
50 | + CertificationPath $issuer_path) |
|
51 | + { |
|
52 | + $this->_holderPath = $holder_path; |
|
53 | + $this->_issuerPath = $issuer_path; |
|
54 | + $this->_evalTime = new \DateTimeImmutable(); |
|
55 | + $this->_targets = array(); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * Get certification path of the AC's holder. |
|
60 | - * |
|
61 | - * @return CertificationPath |
|
62 | - */ |
|
63 | - public function holderPath(): CertificationPath |
|
64 | - { |
|
65 | - return $this->_holderPath; |
|
66 | - } |
|
58 | + /** |
|
59 | + * Get certification path of the AC's holder. |
|
60 | + * |
|
61 | + * @return CertificationPath |
|
62 | + */ |
|
63 | + public function holderPath(): CertificationPath |
|
64 | + { |
|
65 | + return $this->_holderPath; |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * Get certification path of the AC's issuer. |
|
70 | - * |
|
71 | - * @return CertificationPath |
|
72 | - */ |
|
73 | - public function issuerPath(): CertificationPath |
|
74 | - { |
|
75 | - return $this->_issuerPath; |
|
76 | - } |
|
68 | + /** |
|
69 | + * Get certification path of the AC's issuer. |
|
70 | + * |
|
71 | + * @return CertificationPath |
|
72 | + */ |
|
73 | + public function issuerPath(): CertificationPath |
|
74 | + { |
|
75 | + return $this->_issuerPath; |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * Get self with given evaluation reference time. |
|
80 | - * |
|
81 | - * @param \DateTimeImmutable $dt |
|
82 | - * @return self |
|
83 | - */ |
|
84 | - public function withEvaluationTime(\DateTimeImmutable $dt): self |
|
85 | - { |
|
86 | - $obj = clone $this; |
|
87 | - $obj->_evalTime = $dt; |
|
88 | - return $obj; |
|
89 | - } |
|
78 | + /** |
|
79 | + * Get self with given evaluation reference time. |
|
80 | + * |
|
81 | + * @param \DateTimeImmutable $dt |
|
82 | + * @return self |
|
83 | + */ |
|
84 | + public function withEvaluationTime(\DateTimeImmutable $dt): self |
|
85 | + { |
|
86 | + $obj = clone $this; |
|
87 | + $obj->_evalTime = $dt; |
|
88 | + return $obj; |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * Get the evaluation reference time. |
|
93 | - * |
|
94 | - * @return \DateTimeImmutable |
|
95 | - */ |
|
96 | - public function evaluationTime(): \DateTimeImmutable |
|
97 | - { |
|
98 | - return $this->_evalTime; |
|
99 | - } |
|
91 | + /** |
|
92 | + * Get the evaluation reference time. |
|
93 | + * |
|
94 | + * @return \DateTimeImmutable |
|
95 | + */ |
|
96 | + public function evaluationTime(): \DateTimeImmutable |
|
97 | + { |
|
98 | + return $this->_evalTime; |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Get self with permitted targets. |
|
103 | - * |
|
104 | - * @param Target ...$targets |
|
105 | - * @return self |
|
106 | - */ |
|
107 | - public function withTargets(Target ...$targets): self |
|
108 | - { |
|
109 | - $obj = clone $this; |
|
110 | - $obj->_targets = $targets; |
|
111 | - return $obj; |
|
112 | - } |
|
101 | + /** |
|
102 | + * Get self with permitted targets. |
|
103 | + * |
|
104 | + * @param Target ...$targets |
|
105 | + * @return self |
|
106 | + */ |
|
107 | + public function withTargets(Target ...$targets): self |
|
108 | + { |
|
109 | + $obj = clone $this; |
|
110 | + $obj->_targets = $targets; |
|
111 | + return $obj; |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * Get array of permitted targets |
|
116 | - * |
|
117 | - * @return Target[] |
|
118 | - */ |
|
119 | - public function targets(): array |
|
120 | - { |
|
121 | - return $this->_targets; |
|
122 | - } |
|
114 | + /** |
|
115 | + * Get array of permitted targets |
|
116 | + * |
|
117 | + * @return Target[] |
|
118 | + */ |
|
119 | + public function targets(): array |
|
120 | + { |
|
121 | + return $this->_targets; |
|
122 | + } |
|
123 | 123 | } |
@@ -21,178 +21,178 @@ |
||
21 | 21 | */ |
22 | 22 | class ACValidator |
23 | 23 | { |
24 | - /** |
|
25 | - * Attribute certificate. |
|
26 | - * |
|
27 | - * @var AttributeCertificate |
|
28 | - */ |
|
29 | - protected $_ac; |
|
24 | + /** |
|
25 | + * Attribute certificate. |
|
26 | + * |
|
27 | + * @var AttributeCertificate |
|
28 | + */ |
|
29 | + protected $_ac; |
|
30 | 30 | |
31 | - /** |
|
32 | - * Validation configuration. |
|
33 | - * |
|
34 | - * @var ACValidationConfig |
|
35 | - */ |
|
36 | - protected $_config; |
|
31 | + /** |
|
32 | + * Validation configuration. |
|
33 | + * |
|
34 | + * @var ACValidationConfig |
|
35 | + */ |
|
36 | + protected $_config; |
|
37 | 37 | |
38 | - /** |
|
39 | - * Crypto engine. |
|
40 | - * |
|
41 | - * @var Crypto |
|
42 | - */ |
|
43 | - protected $_crypto; |
|
38 | + /** |
|
39 | + * Crypto engine. |
|
40 | + * |
|
41 | + * @var Crypto |
|
42 | + */ |
|
43 | + protected $_crypto; |
|
44 | 44 | |
45 | - /** |
|
46 | - * Constructor. |
|
47 | - * |
|
48 | - * @param AttributeCertificate $ac Attribute certificate to validate |
|
49 | - * @param ACValidationConfig $config Validation configuration |
|
50 | - * @param Crypto|null $crypto Crypto engine, use default if not set |
|
51 | - */ |
|
52 | - public function __construct(AttributeCertificate $ac, |
|
53 | - ACValidationConfig $config, Crypto $crypto = null) |
|
54 | - { |
|
55 | - $this->_ac = $ac; |
|
56 | - $this->_config = $config; |
|
57 | - $this->_crypto = $crypto ?: Crypto::getDefault(); |
|
58 | - } |
|
45 | + /** |
|
46 | + * Constructor. |
|
47 | + * |
|
48 | + * @param AttributeCertificate $ac Attribute certificate to validate |
|
49 | + * @param ACValidationConfig $config Validation configuration |
|
50 | + * @param Crypto|null $crypto Crypto engine, use default if not set |
|
51 | + */ |
|
52 | + public function __construct(AttributeCertificate $ac, |
|
53 | + ACValidationConfig $config, Crypto $crypto = null) |
|
54 | + { |
|
55 | + $this->_ac = $ac; |
|
56 | + $this->_config = $config; |
|
57 | + $this->_crypto = $crypto ?: Crypto::getDefault(); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Validate attribute certificate. |
|
62 | - * |
|
63 | - * @throws ACValidationException If validation fails |
|
64 | - * @return AttributeCertificate Validated AC |
|
65 | - */ |
|
66 | - public function validate(): AttributeCertificate |
|
67 | - { |
|
68 | - $this->_validateHolder(); |
|
69 | - $issuer = $this->_verifyIssuer(); |
|
70 | - $this->_validateIssuerProfile($issuer); |
|
71 | - $this->_validateTime(); |
|
72 | - $this->_validateTargeting(); |
|
73 | - return $this->_ac; |
|
74 | - } |
|
60 | + /** |
|
61 | + * Validate attribute certificate. |
|
62 | + * |
|
63 | + * @throws ACValidationException If validation fails |
|
64 | + * @return AttributeCertificate Validated AC |
|
65 | + */ |
|
66 | + public function validate(): AttributeCertificate |
|
67 | + { |
|
68 | + $this->_validateHolder(); |
|
69 | + $issuer = $this->_verifyIssuer(); |
|
70 | + $this->_validateIssuerProfile($issuer); |
|
71 | + $this->_validateTime(); |
|
72 | + $this->_validateTargeting(); |
|
73 | + return $this->_ac; |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * Validate AC holder's certification. |
|
78 | - * |
|
79 | - * @throws ACValidationException |
|
80 | - * @return Certificate Certificate of the AC's holder |
|
81 | - */ |
|
82 | - private function _validateHolder(): Certificate |
|
83 | - { |
|
84 | - $path = $this->_config->holderPath(); |
|
85 | - $config = PathValidationConfig::defaultConfig()->withMaxLength( |
|
86 | - count($path))->withDateTime($this->_config->evaluationTime()); |
|
87 | - try { |
|
88 | - $holder = $path->validate($config, $this->_crypto)->certificate(); |
|
89 | - } catch (PathValidationException $e) { |
|
90 | - throw new ACValidationException( |
|
91 | - "Failed to validate holder PKC's certification path.", 0, $e); |
|
92 | - } |
|
93 | - if (!$this->_ac->isHeldBy($holder)) { |
|
94 | - throw new ACValidationException("Name mismatch of AC's holder PKC."); |
|
95 | - } |
|
96 | - return $holder; |
|
97 | - } |
|
76 | + /** |
|
77 | + * Validate AC holder's certification. |
|
78 | + * |
|
79 | + * @throws ACValidationException |
|
80 | + * @return Certificate Certificate of the AC's holder |
|
81 | + */ |
|
82 | + private function _validateHolder(): Certificate |
|
83 | + { |
|
84 | + $path = $this->_config->holderPath(); |
|
85 | + $config = PathValidationConfig::defaultConfig()->withMaxLength( |
|
86 | + count($path))->withDateTime($this->_config->evaluationTime()); |
|
87 | + try { |
|
88 | + $holder = $path->validate($config, $this->_crypto)->certificate(); |
|
89 | + } catch (PathValidationException $e) { |
|
90 | + throw new ACValidationException( |
|
91 | + "Failed to validate holder PKC's certification path.", 0, $e); |
|
92 | + } |
|
93 | + if (!$this->_ac->isHeldBy($holder)) { |
|
94 | + throw new ACValidationException("Name mismatch of AC's holder PKC."); |
|
95 | + } |
|
96 | + return $holder; |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * Verify AC's signature and issuer's certification. |
|
101 | - * |
|
102 | - * @throws ACValidationException |
|
103 | - * @return Certificate Certificate of the AC's issuer |
|
104 | - */ |
|
105 | - private function _verifyIssuer(): Certificate |
|
106 | - { |
|
107 | - $path = $this->_config->issuerPath(); |
|
108 | - $config = PathValidationConfig::defaultConfig()->withMaxLength( |
|
109 | - count($path))->withDateTime($this->_config->evaluationTime()); |
|
110 | - try { |
|
111 | - $issuer = $path->validate($config, $this->_crypto)->certificate(); |
|
112 | - } catch (PathValidationException $e) { |
|
113 | - throw new ACValidationException( |
|
114 | - "Failed to validate issuer PKC's certification path.", 0, $e); |
|
115 | - } |
|
116 | - if (!$this->_ac->isIssuedBy($issuer)) { |
|
117 | - throw new ACValidationException("Name mismatch of AC's issuer PKC."); |
|
118 | - } |
|
119 | - $pubkey_info = $issuer->tbsCertificate()->subjectPublicKeyInfo(); |
|
120 | - if (!$this->_ac->verify($pubkey_info, $this->_crypto)) { |
|
121 | - throw new ACValidationException("Failed to verify signature."); |
|
122 | - } |
|
123 | - return $issuer; |
|
124 | - } |
|
99 | + /** |
|
100 | + * Verify AC's signature and issuer's certification. |
|
101 | + * |
|
102 | + * @throws ACValidationException |
|
103 | + * @return Certificate Certificate of the AC's issuer |
|
104 | + */ |
|
105 | + private function _verifyIssuer(): Certificate |
|
106 | + { |
|
107 | + $path = $this->_config->issuerPath(); |
|
108 | + $config = PathValidationConfig::defaultConfig()->withMaxLength( |
|
109 | + count($path))->withDateTime($this->_config->evaluationTime()); |
|
110 | + try { |
|
111 | + $issuer = $path->validate($config, $this->_crypto)->certificate(); |
|
112 | + } catch (PathValidationException $e) { |
|
113 | + throw new ACValidationException( |
|
114 | + "Failed to validate issuer PKC's certification path.", 0, $e); |
|
115 | + } |
|
116 | + if (!$this->_ac->isIssuedBy($issuer)) { |
|
117 | + throw new ACValidationException("Name mismatch of AC's issuer PKC."); |
|
118 | + } |
|
119 | + $pubkey_info = $issuer->tbsCertificate()->subjectPublicKeyInfo(); |
|
120 | + if (!$this->_ac->verify($pubkey_info, $this->_crypto)) { |
|
121 | + throw new ACValidationException("Failed to verify signature."); |
|
122 | + } |
|
123 | + return $issuer; |
|
124 | + } |
|
125 | 125 | |
126 | - /** |
|
127 | - * Validate AC issuer's profile. |
|
128 | - * |
|
129 | - * @link https://tools.ietf.org/html/rfc5755#section-4.5 |
|
130 | - * @param Certificate $cert |
|
131 | - * @throws ACValidationException |
|
132 | - */ |
|
133 | - private function _validateIssuerProfile(Certificate $cert) |
|
134 | - { |
|
135 | - $exts = $cert->tbsCertificate()->extensions(); |
|
136 | - if ($exts->hasKeyUsage() && !$exts->keyUsage()->isDigitalSignature()) { |
|
137 | - throw new ACValidationException( |
|
138 | - "Issuer PKC's Key Usage extension doesn't permit" . |
|
139 | - " verification of digital signatures."); |
|
140 | - } |
|
141 | - if ($exts->hasBasicConstraints() && $exts->basicConstraints()->isCA()) { |
|
142 | - throw new ACValidationException("Issuer PKC must not be a CA."); |
|
143 | - } |
|
144 | - } |
|
126 | + /** |
|
127 | + * Validate AC issuer's profile. |
|
128 | + * |
|
129 | + * @link https://tools.ietf.org/html/rfc5755#section-4.5 |
|
130 | + * @param Certificate $cert |
|
131 | + * @throws ACValidationException |
|
132 | + */ |
|
133 | + private function _validateIssuerProfile(Certificate $cert) |
|
134 | + { |
|
135 | + $exts = $cert->tbsCertificate()->extensions(); |
|
136 | + if ($exts->hasKeyUsage() && !$exts->keyUsage()->isDigitalSignature()) { |
|
137 | + throw new ACValidationException( |
|
138 | + "Issuer PKC's Key Usage extension doesn't permit" . |
|
139 | + " verification of digital signatures."); |
|
140 | + } |
|
141 | + if ($exts->hasBasicConstraints() && $exts->basicConstraints()->isCA()) { |
|
142 | + throw new ACValidationException("Issuer PKC must not be a CA."); |
|
143 | + } |
|
144 | + } |
|
145 | 145 | |
146 | - /** |
|
147 | - * Validate AC's validity period. |
|
148 | - * |
|
149 | - * @throws ACValidationException |
|
150 | - */ |
|
151 | - private function _validateTime() |
|
152 | - { |
|
153 | - $t = $this->_config->evaluationTime(); |
|
154 | - $validity = $this->_ac->acinfo()->validityPeriod(); |
|
155 | - if ($validity->notBeforeTime()->diff($t)->invert) { |
|
156 | - throw new ACValidationException("Validity period has not started."); |
|
157 | - } |
|
158 | - if ($t->diff($validity->notAfterTime())->invert) { |
|
159 | - throw new ACValidationException("Attribute certificate has expired."); |
|
160 | - } |
|
161 | - } |
|
146 | + /** |
|
147 | + * Validate AC's validity period. |
|
148 | + * |
|
149 | + * @throws ACValidationException |
|
150 | + */ |
|
151 | + private function _validateTime() |
|
152 | + { |
|
153 | + $t = $this->_config->evaluationTime(); |
|
154 | + $validity = $this->_ac->acinfo()->validityPeriod(); |
|
155 | + if ($validity->notBeforeTime()->diff($t)->invert) { |
|
156 | + throw new ACValidationException("Validity period has not started."); |
|
157 | + } |
|
158 | + if ($t->diff($validity->notAfterTime())->invert) { |
|
159 | + throw new ACValidationException("Attribute certificate has expired."); |
|
160 | + } |
|
161 | + } |
|
162 | 162 | |
163 | - /** |
|
164 | - * Validate AC's target information. |
|
165 | - * |
|
166 | - * @throws ACValidationException |
|
167 | - */ |
|
168 | - private function _validateTargeting() |
|
169 | - { |
|
170 | - $exts = $this->_ac->acinfo()->extensions(); |
|
171 | - // if target information extension is not present |
|
172 | - if (!$exts->has(Extension::OID_TARGET_INFORMATION)) { |
|
173 | - return; |
|
174 | - } |
|
175 | - $ext = $exts->get(Extension::OID_TARGET_INFORMATION); |
|
176 | - if ($ext instanceof TargetInformationExtension && |
|
177 | - !$this->_hasMatchingTarget($ext->targets())) { |
|
178 | - throw new ACValidationException( |
|
179 | - "Attribute certificate doesn't have a matching target."); |
|
180 | - } |
|
181 | - } |
|
163 | + /** |
|
164 | + * Validate AC's target information. |
|
165 | + * |
|
166 | + * @throws ACValidationException |
|
167 | + */ |
|
168 | + private function _validateTargeting() |
|
169 | + { |
|
170 | + $exts = $this->_ac->acinfo()->extensions(); |
|
171 | + // if target information extension is not present |
|
172 | + if (!$exts->has(Extension::OID_TARGET_INFORMATION)) { |
|
173 | + return; |
|
174 | + } |
|
175 | + $ext = $exts->get(Extension::OID_TARGET_INFORMATION); |
|
176 | + if ($ext instanceof TargetInformationExtension && |
|
177 | + !$this->_hasMatchingTarget($ext->targets())) { |
|
178 | + throw new ACValidationException( |
|
179 | + "Attribute certificate doesn't have a matching target."); |
|
180 | + } |
|
181 | + } |
|
182 | 182 | |
183 | - /** |
|
184 | - * Check whether validation configuration has matching targets. |
|
185 | - * |
|
186 | - * @param Targets $targets Set of eligible targets |
|
187 | - * @return boolean |
|
188 | - */ |
|
189 | - private function _hasMatchingTarget(Targets $targets): bool |
|
190 | - { |
|
191 | - foreach ($this->_config->targets() as $target) { |
|
192 | - if ($targets->hasTarget($target)) { |
|
193 | - return true; |
|
194 | - } |
|
195 | - } |
|
196 | - return false; |
|
197 | - } |
|
183 | + /** |
|
184 | + * Check whether validation configuration has matching targets. |
|
185 | + * |
|
186 | + * @param Targets $targets Set of eligible targets |
|
187 | + * @return boolean |
|
188 | + */ |
|
189 | + private function _hasMatchingTarget(Targets $targets): bool |
|
190 | + { |
|
191 | + foreach ($this->_config->targets() as $target) { |
|
192 | + if ($targets->hasTarget($target)) { |
|
193 | + return true; |
|
194 | + } |
|
195 | + } |
|
196 | + return false; |
|
197 | + } |
|
198 | 198 | } |
@@ -18,66 +18,66 @@ |
||
18 | 18 | */ |
19 | 19 | abstract class AttCertIssuer |
20 | 20 | { |
21 | - /** |
|
22 | - * Generate ASN.1 element. |
|
23 | - * |
|
24 | - * @return Element |
|
25 | - */ |
|
26 | - abstract public function toASN1(); |
|
21 | + /** |
|
22 | + * Generate ASN.1 element. |
|
23 | + * |
|
24 | + * @return Element |
|
25 | + */ |
|
26 | + abstract public function toASN1(); |
|
27 | 27 | |
28 | - /** |
|
29 | - * Check whether AttCertIssuer identifies given certificate. |
|
30 | - * |
|
31 | - * @param Certificate $cert |
|
32 | - * @return bool |
|
33 | - */ |
|
34 | - abstract public function identifiesPKC(Certificate $cert): bool; |
|
28 | + /** |
|
29 | + * Check whether AttCertIssuer identifies given certificate. |
|
30 | + * |
|
31 | + * @param Certificate $cert |
|
32 | + * @return bool |
|
33 | + */ |
|
34 | + abstract public function identifiesPKC(Certificate $cert): bool; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Initialize from distinguished name. |
|
38 | - * |
|
39 | - * This conforms to RFC 5755 which states that only v2Form must be used, |
|
40 | - * and issuerName must contain exactly one GeneralName of DirectoryName |
|
41 | - * type. |
|
42 | - * |
|
43 | - * @link https://tools.ietf.org/html/rfc5755#section-4.2.3 |
|
44 | - * @param Name $name |
|
45 | - * @return self |
|
46 | - */ |
|
47 | - public static function fromName(Name $name): self |
|
48 | - { |
|
49 | - return new V2Form(new GeneralNames(new DirectoryName($name))); |
|
50 | - } |
|
36 | + /** |
|
37 | + * Initialize from distinguished name. |
|
38 | + * |
|
39 | + * This conforms to RFC 5755 which states that only v2Form must be used, |
|
40 | + * and issuerName must contain exactly one GeneralName of DirectoryName |
|
41 | + * type. |
|
42 | + * |
|
43 | + * @link https://tools.ietf.org/html/rfc5755#section-4.2.3 |
|
44 | + * @param Name $name |
|
45 | + * @return self |
|
46 | + */ |
|
47 | + public static function fromName(Name $name): self |
|
48 | + { |
|
49 | + return new V2Form(new GeneralNames(new DirectoryName($name))); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Initialize from an issuer's public key certificate. |
|
54 | - * |
|
55 | - * @param Certificate $cert |
|
56 | - * @return self |
|
57 | - */ |
|
58 | - public static function fromPKC(Certificate $cert): self |
|
59 | - { |
|
60 | - return self::fromName($cert->tbsCertificate()->subject()); |
|
61 | - } |
|
52 | + /** |
|
53 | + * Initialize from an issuer's public key certificate. |
|
54 | + * |
|
55 | + * @param Certificate $cert |
|
56 | + * @return self |
|
57 | + */ |
|
58 | + public static function fromPKC(Certificate $cert): self |
|
59 | + { |
|
60 | + return self::fromName($cert->tbsCertificate()->subject()); |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * Initialize from ASN.1. |
|
65 | - * |
|
66 | - * @param UnspecifiedType $el CHOICE |
|
67 | - * @throws \UnexpectedValueException |
|
68 | - * @return self |
|
69 | - */ |
|
70 | - public static function fromASN1(UnspecifiedType $el): self |
|
71 | - { |
|
72 | - if (!$el->isTagged()) { |
|
73 | - throw new \UnexpectedValueException("v1Form issuer not supported."); |
|
74 | - } |
|
75 | - $tagged = $el->asTagged(); |
|
76 | - switch ($tagged->tag()) { |
|
77 | - case 0: |
|
78 | - return V2Form::fromV2ASN1( |
|
79 | - $tagged->asImplicit(Element::TYPE_SEQUENCE)->asSequence()); |
|
80 | - } |
|
81 | - throw new \UnexpectedValueException("Unsupported issuer type."); |
|
82 | - } |
|
63 | + /** |
|
64 | + * Initialize from ASN.1. |
|
65 | + * |
|
66 | + * @param UnspecifiedType $el CHOICE |
|
67 | + * @throws \UnexpectedValueException |
|
68 | + * @return self |
|
69 | + */ |
|
70 | + public static function fromASN1(UnspecifiedType $el): self |
|
71 | + { |
|
72 | + if (!$el->isTagged()) { |
|
73 | + throw new \UnexpectedValueException("v1Form issuer not supported."); |
|
74 | + } |
|
75 | + $tagged = $el->asTagged(); |
|
76 | + switch ($tagged->tag()) { |
|
77 | + case 0: |
|
78 | + return V2Form::fromV2ASN1( |
|
79 | + $tagged->asImplicit(Element::TYPE_SEQUENCE)->asSequence()); |
|
80 | + } |
|
81 | + throw new \UnexpectedValueException("Unsupported issuer type."); |
|
82 | + } |
|
83 | 83 | } |
@@ -15,94 +15,94 @@ |
||
15 | 15 | */ |
16 | 16 | class AttCertValidityPeriod |
17 | 17 | { |
18 | - use DateTimeHelper; |
|
18 | + use DateTimeHelper; |
|
19 | 19 | |
20 | - /** |
|
21 | - * Not before time. |
|
22 | - * |
|
23 | - * @var \DateTimeImmutable |
|
24 | - */ |
|
25 | - protected $_notBeforeTime; |
|
20 | + /** |
|
21 | + * Not before time. |
|
22 | + * |
|
23 | + * @var \DateTimeImmutable |
|
24 | + */ |
|
25 | + protected $_notBeforeTime; |
|
26 | 26 | |
27 | - /** |
|
28 | - * Not after time. |
|
29 | - * |
|
30 | - * @var \DateTimeImmutable |
|
31 | - */ |
|
32 | - protected $_notAfterTime; |
|
27 | + /** |
|
28 | + * Not after time. |
|
29 | + * |
|
30 | + * @var \DateTimeImmutable |
|
31 | + */ |
|
32 | + protected $_notAfterTime; |
|
33 | 33 | |
34 | - /** |
|
35 | - * Constructor. |
|
36 | - * |
|
37 | - * @param \DateTimeImmutable $nb |
|
38 | - * @param \DateTimeImmutable $na |
|
39 | - */ |
|
40 | - public function __construct(\DateTimeImmutable $nb, \DateTimeImmutable $na) |
|
41 | - { |
|
42 | - $this->_notBeforeTime = $nb; |
|
43 | - $this->_notAfterTime = $na; |
|
44 | - } |
|
34 | + /** |
|
35 | + * Constructor. |
|
36 | + * |
|
37 | + * @param \DateTimeImmutable $nb |
|
38 | + * @param \DateTimeImmutable $na |
|
39 | + */ |
|
40 | + public function __construct(\DateTimeImmutable $nb, \DateTimeImmutable $na) |
|
41 | + { |
|
42 | + $this->_notBeforeTime = $nb; |
|
43 | + $this->_notAfterTime = $na; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Initialize from ASN.1. |
|
48 | - * |
|
49 | - * @param Sequence $seq |
|
50 | - * @return self |
|
51 | - */ |
|
52 | - public static function fromASN1(Sequence $seq): self |
|
53 | - { |
|
54 | - $nb = $seq->at(0) |
|
55 | - ->asGeneralizedTime() |
|
56 | - ->dateTime(); |
|
57 | - $na = $seq->at(1) |
|
58 | - ->asGeneralizedTime() |
|
59 | - ->dateTime(); |
|
60 | - return new self($nb, $na); |
|
61 | - } |
|
46 | + /** |
|
47 | + * Initialize from ASN.1. |
|
48 | + * |
|
49 | + * @param Sequence $seq |
|
50 | + * @return self |
|
51 | + */ |
|
52 | + public static function fromASN1(Sequence $seq): self |
|
53 | + { |
|
54 | + $nb = $seq->at(0) |
|
55 | + ->asGeneralizedTime() |
|
56 | + ->dateTime(); |
|
57 | + $na = $seq->at(1) |
|
58 | + ->asGeneralizedTime() |
|
59 | + ->dateTime(); |
|
60 | + return new self($nb, $na); |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * Initialize from date strings. |
|
65 | - * |
|
66 | - * @param string|null $nb_date Not before date |
|
67 | - * @param string|null $na_date Not after date |
|
68 | - * @param string|null $tz Timezone string |
|
69 | - * @return self |
|
70 | - */ |
|
71 | - public static function fromStrings($nb_date, $na_date, $tz = null): self |
|
72 | - { |
|
73 | - $nb = self::_createDateTime($nb_date, $tz); |
|
74 | - $na = self::_createDateTime($na_date, $tz); |
|
75 | - return new self($nb, $na); |
|
76 | - } |
|
63 | + /** |
|
64 | + * Initialize from date strings. |
|
65 | + * |
|
66 | + * @param string|null $nb_date Not before date |
|
67 | + * @param string|null $na_date Not after date |
|
68 | + * @param string|null $tz Timezone string |
|
69 | + * @return self |
|
70 | + */ |
|
71 | + public static function fromStrings($nb_date, $na_date, $tz = null): self |
|
72 | + { |
|
73 | + $nb = self::_createDateTime($nb_date, $tz); |
|
74 | + $na = self::_createDateTime($na_date, $tz); |
|
75 | + return new self($nb, $na); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * Get not before time. |
|
80 | - * |
|
81 | - * @return \DateTimeImmutable |
|
82 | - */ |
|
83 | - public function notBeforeTime(): \DateTimeImmutable |
|
84 | - { |
|
85 | - return $this->_notBeforeTime; |
|
86 | - } |
|
78 | + /** |
|
79 | + * Get not before time. |
|
80 | + * |
|
81 | + * @return \DateTimeImmutable |
|
82 | + */ |
|
83 | + public function notBeforeTime(): \DateTimeImmutable |
|
84 | + { |
|
85 | + return $this->_notBeforeTime; |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * Get not after time. |
|
90 | - * |
|
91 | - * @return \DateTimeImmutable |
|
92 | - */ |
|
93 | - public function notAfterTime(): \DateTimeImmutable |
|
94 | - { |
|
95 | - return $this->_notAfterTime; |
|
96 | - } |
|
88 | + /** |
|
89 | + * Get not after time. |
|
90 | + * |
|
91 | + * @return \DateTimeImmutable |
|
92 | + */ |
|
93 | + public function notAfterTime(): \DateTimeImmutable |
|
94 | + { |
|
95 | + return $this->_notAfterTime; |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * Generate ASN.1 structure. |
|
100 | - * |
|
101 | - * @return Sequence |
|
102 | - */ |
|
103 | - public function toASN1(): Sequence |
|
104 | - { |
|
105 | - return new Sequence(new GeneralizedTime($this->_notBeforeTime), |
|
106 | - new GeneralizedTime($this->_notAfterTime)); |
|
107 | - } |
|
98 | + /** |
|
99 | + * Generate ASN.1 structure. |
|
100 | + * |
|
101 | + * @return Sequence |
|
102 | + */ |
|
103 | + public function toASN1(): Sequence |
|
104 | + { |
|
105 | + return new Sequence(new GeneralizedTime($this->_notBeforeTime), |
|
106 | + new GeneralizedTime($this->_notAfterTime)); |
|
107 | + } |
|
108 | 108 | } |
@@ -15,87 +15,87 @@ |
||
15 | 15 | */ |
16 | 16 | class GeneralSubtrees implements \Countable, \IteratorAggregate |
17 | 17 | { |
18 | - /** |
|
19 | - * Subtrees. |
|
20 | - * |
|
21 | - * @var GeneralSubtree[] $_subtrees |
|
22 | - */ |
|
23 | - protected $_subtrees; |
|
18 | + /** |
|
19 | + * Subtrees. |
|
20 | + * |
|
21 | + * @var GeneralSubtree[] $_subtrees |
|
22 | + */ |
|
23 | + protected $_subtrees; |
|
24 | 24 | |
25 | - /** |
|
26 | - * Constructor. |
|
27 | - * |
|
28 | - * @param GeneralSubtree ...$subtrees |
|
29 | - */ |
|
30 | - public function __construct(GeneralSubtree ...$subtrees) |
|
31 | - { |
|
32 | - $this->_subtrees = $subtrees; |
|
33 | - } |
|
25 | + /** |
|
26 | + * Constructor. |
|
27 | + * |
|
28 | + * @param GeneralSubtree ...$subtrees |
|
29 | + */ |
|
30 | + public function __construct(GeneralSubtree ...$subtrees) |
|
31 | + { |
|
32 | + $this->_subtrees = $subtrees; |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * Initialize from ASN.1. |
|
37 | - * |
|
38 | - * @param Sequence $seq |
|
39 | - * @return self |
|
40 | - */ |
|
41 | - public static function fromASN1(Sequence $seq): self |
|
42 | - { |
|
43 | - $subtrees = array_map( |
|
44 | - function (UnspecifiedType $el) { |
|
45 | - return GeneralSubtree::fromASN1($el->asSequence()); |
|
46 | - }, $seq->elements()); |
|
47 | - if (!count($subtrees)) { |
|
48 | - throw new \UnexpectedValueException( |
|
49 | - "GeneralSubtrees must contain at least one GeneralSubtree."); |
|
50 | - } |
|
51 | - return new self(...$subtrees); |
|
52 | - } |
|
35 | + /** |
|
36 | + * Initialize from ASN.1. |
|
37 | + * |
|
38 | + * @param Sequence $seq |
|
39 | + * @return self |
|
40 | + */ |
|
41 | + public static function fromASN1(Sequence $seq): self |
|
42 | + { |
|
43 | + $subtrees = array_map( |
|
44 | + function (UnspecifiedType $el) { |
|
45 | + return GeneralSubtree::fromASN1($el->asSequence()); |
|
46 | + }, $seq->elements()); |
|
47 | + if (!count($subtrees)) { |
|
48 | + throw new \UnexpectedValueException( |
|
49 | + "GeneralSubtrees must contain at least one GeneralSubtree."); |
|
50 | + } |
|
51 | + return new self(...$subtrees); |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Get all subtrees. |
|
56 | - * |
|
57 | - * @return GeneralSubtree[] |
|
58 | - */ |
|
59 | - public function all(): array |
|
60 | - { |
|
61 | - return $this->_subtrees; |
|
62 | - } |
|
54 | + /** |
|
55 | + * Get all subtrees. |
|
56 | + * |
|
57 | + * @return GeneralSubtree[] |
|
58 | + */ |
|
59 | + public function all(): array |
|
60 | + { |
|
61 | + return $this->_subtrees; |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Generate ASN.1 structure. |
|
66 | - * |
|
67 | - * @return Sequence |
|
68 | - */ |
|
69 | - public function toASN1(): Sequence |
|
70 | - { |
|
71 | - if (!count($this->_subtrees)) { |
|
72 | - throw new \LogicException("No subtrees."); |
|
73 | - } |
|
74 | - $elements = array_map( |
|
75 | - function (GeneralSubtree $gs) { |
|
76 | - return $gs->toASN1(); |
|
77 | - }, $this->_subtrees); |
|
78 | - return new Sequence(...$elements); |
|
79 | - } |
|
64 | + /** |
|
65 | + * Generate ASN.1 structure. |
|
66 | + * |
|
67 | + * @return Sequence |
|
68 | + */ |
|
69 | + public function toASN1(): Sequence |
|
70 | + { |
|
71 | + if (!count($this->_subtrees)) { |
|
72 | + throw new \LogicException("No subtrees."); |
|
73 | + } |
|
74 | + $elements = array_map( |
|
75 | + function (GeneralSubtree $gs) { |
|
76 | + return $gs->toASN1(); |
|
77 | + }, $this->_subtrees); |
|
78 | + return new Sequence(...$elements); |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * |
|
83 | - * @see \Countable::count() |
|
84 | - * @return int |
|
85 | - */ |
|
86 | - public function count(): int |
|
87 | - { |
|
88 | - return count($this->_subtrees); |
|
89 | - } |
|
81 | + /** |
|
82 | + * |
|
83 | + * @see \Countable::count() |
|
84 | + * @return int |
|
85 | + */ |
|
86 | + public function count(): int |
|
87 | + { |
|
88 | + return count($this->_subtrees); |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * Get iterator for subtrees. |
|
93 | - * |
|
94 | - * @see \IteratorAggregate::getIterator() |
|
95 | - * @return \ArrayIterator |
|
96 | - */ |
|
97 | - public function getIterator(): \ArrayIterator |
|
98 | - { |
|
99 | - return new \ArrayIterator($this->_subtrees); |
|
100 | - } |
|
91 | + /** |
|
92 | + * Get iterator for subtrees. |
|
93 | + * |
|
94 | + * @see \IteratorAggregate::getIterator() |
|
95 | + * @return \ArrayIterator |
|
96 | + */ |
|
97 | + public function getIterator(): \ArrayIterator |
|
98 | + { |
|
99 | + return new \ArrayIterator($this->_subtrees); |
|
100 | + } |
|
101 | 101 | } |
@@ -16,207 +16,207 @@ |
||
16 | 16 | */ |
17 | 17 | class PolicyInformation implements \Countable, \IteratorAggregate |
18 | 18 | { |
19 | - /** |
|
20 | - * Wildcard policy. |
|
21 | - * |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - const OID_ANY_POLICY = "2.5.29.32.0"; |
|
25 | - |
|
26 | - /** |
|
27 | - * Policy identifier. |
|
28 | - * |
|
29 | - * @var string $_oid |
|
30 | - */ |
|
31 | - protected $_oid; |
|
32 | - |
|
33 | - /** |
|
34 | - * Policy qualifiers. |
|
35 | - * |
|
36 | - * @var PolicyQualifierInfo[] $_qualifiers |
|
37 | - */ |
|
38 | - protected $_qualifiers; |
|
39 | - |
|
40 | - /** |
|
41 | - * Constructor. |
|
42 | - * |
|
43 | - * @param string $oid |
|
44 | - * @param PolicyQualifierInfo ...$qualifiers |
|
45 | - */ |
|
46 | - public function __construct(string $oid, PolicyQualifierInfo ...$qualifiers) |
|
47 | - { |
|
48 | - $this->_oid = $oid; |
|
49 | - $this->_qualifiers = array(); |
|
50 | - foreach ($qualifiers as $qual) { |
|
51 | - $this->_qualifiers[$qual->oid()] = $qual; |
|
52 | - } |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * Initialize from ASN.1. |
|
57 | - * |
|
58 | - * @param Sequence $seq |
|
59 | - * @return self |
|
60 | - */ |
|
61 | - public static function fromASN1(Sequence $seq): self |
|
62 | - { |
|
63 | - $oid = $seq->at(0) |
|
64 | - ->asObjectIdentifier() |
|
65 | - ->oid(); |
|
66 | - $qualifiers = array(); |
|
67 | - if (count($seq) > 1) { |
|
68 | - $qualifiers = array_map( |
|
69 | - function (UnspecifiedType $el) { |
|
70 | - return PolicyQualifierInfo::fromASN1($el->asSequence()); |
|
71 | - }, |
|
72 | - $seq->at(1) |
|
73 | - ->asSequence() |
|
74 | - ->elements()); |
|
75 | - } |
|
76 | - return new self($oid, ...$qualifiers); |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * Get policy identifier. |
|
81 | - * |
|
82 | - * @return string |
|
83 | - */ |
|
84 | - public function oid(): string |
|
85 | - { |
|
86 | - return $this->_oid; |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * Check whether this policy is anyPolicy. |
|
91 | - * |
|
92 | - * @return bool |
|
93 | - */ |
|
94 | - public function isAnyPolicy(): bool |
|
95 | - { |
|
96 | - return self::OID_ANY_POLICY === $this->_oid; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * Get policy qualifiers. |
|
101 | - * |
|
102 | - * @return PolicyQualifierInfo[] |
|
103 | - */ |
|
104 | - public function qualifiers(): array |
|
105 | - { |
|
106 | - return array_values($this->_qualifiers); |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Check whether qualifier is present. |
|
111 | - * |
|
112 | - * @param string $oid |
|
113 | - * @return boolean |
|
114 | - */ |
|
115 | - public function has(string $oid): bool |
|
116 | - { |
|
117 | - return isset($this->_qualifiers[$oid]); |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * Get qualifier by OID. |
|
122 | - * |
|
123 | - * @param string $oid |
|
124 | - * @throws \OutOfBoundsException |
|
125 | - * @return PolicyQualifierInfo |
|
126 | - */ |
|
127 | - public function get(string $oid): PolicyQualifierInfo |
|
128 | - { |
|
129 | - if (!$this->has($oid)) { |
|
130 | - throw new \LogicException("No $oid qualifier."); |
|
131 | - } |
|
132 | - return $this->_qualifiers[$oid]; |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * Check whether CPS qualifier is present. |
|
137 | - * |
|
138 | - * @return bool |
|
139 | - */ |
|
140 | - public function hasCPSQualifier(): bool |
|
141 | - { |
|
142 | - return $this->has(PolicyQualifierInfo::OID_CPS); |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * Get CPS qualifier. |
|
147 | - * |
|
148 | - * @throws \LogicException |
|
149 | - * @return CPSQualifier |
|
150 | - */ |
|
151 | - public function CPSQualifier(): CPSQualifier |
|
152 | - { |
|
153 | - if (!$this->hasCPSQualifier()) { |
|
154 | - throw new \LogicException("CPS qualifier not set."); |
|
155 | - } |
|
156 | - return $this->get(PolicyQualifierInfo::OID_CPS); |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * Check whether user notice qualifier is present. |
|
161 | - * |
|
162 | - * @return bool |
|
163 | - */ |
|
164 | - public function hasUserNoticeQualifier(): bool |
|
165 | - { |
|
166 | - return $this->has(PolicyQualifierInfo::OID_UNOTICE); |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * Get user notice qualifier. |
|
171 | - * |
|
172 | - * @throws \LogicException |
|
173 | - * @return UserNoticeQualifier |
|
174 | - */ |
|
175 | - public function userNoticeQualifier(): UserNoticeQualifier |
|
176 | - { |
|
177 | - if (!$this->hasUserNoticeQualifier()) { |
|
178 | - throw new \LogicException("User notice qualifier not set."); |
|
179 | - } |
|
180 | - return $this->get(PolicyQualifierInfo::OID_UNOTICE); |
|
181 | - } |
|
182 | - |
|
183 | - /** |
|
184 | - * Get ASN.1 structure. |
|
185 | - * |
|
186 | - * @return Sequence |
|
187 | - */ |
|
188 | - public function toASN1(): Sequence |
|
189 | - { |
|
190 | - $elements = array(new ObjectIdentifier($this->_oid)); |
|
191 | - if (count($this->_qualifiers)) { |
|
192 | - $qualifiers = array_map( |
|
193 | - function (PolicyQualifierInfo $pqi) { |
|
194 | - return $pqi->toASN1(); |
|
195 | - }, array_values($this->_qualifiers)); |
|
196 | - $elements[] = new Sequence(...$qualifiers); |
|
197 | - } |
|
198 | - return new Sequence(...$elements); |
|
199 | - } |
|
200 | - |
|
201 | - /** |
|
202 | - * Get number of qualifiers. |
|
203 | - * |
|
204 | - * @see \Countable::count() |
|
205 | - * @return int |
|
206 | - */ |
|
207 | - public function count(): int |
|
208 | - { |
|
209 | - return count($this->_qualifiers); |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * Get iterator for qualifiers. |
|
214 | - * |
|
215 | - * @see \IteratorAggregate::getIterator() |
|
216 | - * @return \ArrayIterator |
|
217 | - */ |
|
218 | - public function getIterator(): \ArrayIterator |
|
219 | - { |
|
220 | - return new \ArrayIterator($this->_qualifiers); |
|
221 | - } |
|
19 | + /** |
|
20 | + * Wildcard policy. |
|
21 | + * |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + const OID_ANY_POLICY = "2.5.29.32.0"; |
|
25 | + |
|
26 | + /** |
|
27 | + * Policy identifier. |
|
28 | + * |
|
29 | + * @var string $_oid |
|
30 | + */ |
|
31 | + protected $_oid; |
|
32 | + |
|
33 | + /** |
|
34 | + * Policy qualifiers. |
|
35 | + * |
|
36 | + * @var PolicyQualifierInfo[] $_qualifiers |
|
37 | + */ |
|
38 | + protected $_qualifiers; |
|
39 | + |
|
40 | + /** |
|
41 | + * Constructor. |
|
42 | + * |
|
43 | + * @param string $oid |
|
44 | + * @param PolicyQualifierInfo ...$qualifiers |
|
45 | + */ |
|
46 | + public function __construct(string $oid, PolicyQualifierInfo ...$qualifiers) |
|
47 | + { |
|
48 | + $this->_oid = $oid; |
|
49 | + $this->_qualifiers = array(); |
|
50 | + foreach ($qualifiers as $qual) { |
|
51 | + $this->_qualifiers[$qual->oid()] = $qual; |
|
52 | + } |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * Initialize from ASN.1. |
|
57 | + * |
|
58 | + * @param Sequence $seq |
|
59 | + * @return self |
|
60 | + */ |
|
61 | + public static function fromASN1(Sequence $seq): self |
|
62 | + { |
|
63 | + $oid = $seq->at(0) |
|
64 | + ->asObjectIdentifier() |
|
65 | + ->oid(); |
|
66 | + $qualifiers = array(); |
|
67 | + if (count($seq) > 1) { |
|
68 | + $qualifiers = array_map( |
|
69 | + function (UnspecifiedType $el) { |
|
70 | + return PolicyQualifierInfo::fromASN1($el->asSequence()); |
|
71 | + }, |
|
72 | + $seq->at(1) |
|
73 | + ->asSequence() |
|
74 | + ->elements()); |
|
75 | + } |
|
76 | + return new self($oid, ...$qualifiers); |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * Get policy identifier. |
|
81 | + * |
|
82 | + * @return string |
|
83 | + */ |
|
84 | + public function oid(): string |
|
85 | + { |
|
86 | + return $this->_oid; |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * Check whether this policy is anyPolicy. |
|
91 | + * |
|
92 | + * @return bool |
|
93 | + */ |
|
94 | + public function isAnyPolicy(): bool |
|
95 | + { |
|
96 | + return self::OID_ANY_POLICY === $this->_oid; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * Get policy qualifiers. |
|
101 | + * |
|
102 | + * @return PolicyQualifierInfo[] |
|
103 | + */ |
|
104 | + public function qualifiers(): array |
|
105 | + { |
|
106 | + return array_values($this->_qualifiers); |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Check whether qualifier is present. |
|
111 | + * |
|
112 | + * @param string $oid |
|
113 | + * @return boolean |
|
114 | + */ |
|
115 | + public function has(string $oid): bool |
|
116 | + { |
|
117 | + return isset($this->_qualifiers[$oid]); |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * Get qualifier by OID. |
|
122 | + * |
|
123 | + * @param string $oid |
|
124 | + * @throws \OutOfBoundsException |
|
125 | + * @return PolicyQualifierInfo |
|
126 | + */ |
|
127 | + public function get(string $oid): PolicyQualifierInfo |
|
128 | + { |
|
129 | + if (!$this->has($oid)) { |
|
130 | + throw new \LogicException("No $oid qualifier."); |
|
131 | + } |
|
132 | + return $this->_qualifiers[$oid]; |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * Check whether CPS qualifier is present. |
|
137 | + * |
|
138 | + * @return bool |
|
139 | + */ |
|
140 | + public function hasCPSQualifier(): bool |
|
141 | + { |
|
142 | + return $this->has(PolicyQualifierInfo::OID_CPS); |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * Get CPS qualifier. |
|
147 | + * |
|
148 | + * @throws \LogicException |
|
149 | + * @return CPSQualifier |
|
150 | + */ |
|
151 | + public function CPSQualifier(): CPSQualifier |
|
152 | + { |
|
153 | + if (!$this->hasCPSQualifier()) { |
|
154 | + throw new \LogicException("CPS qualifier not set."); |
|
155 | + } |
|
156 | + return $this->get(PolicyQualifierInfo::OID_CPS); |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * Check whether user notice qualifier is present. |
|
161 | + * |
|
162 | + * @return bool |
|
163 | + */ |
|
164 | + public function hasUserNoticeQualifier(): bool |
|
165 | + { |
|
166 | + return $this->has(PolicyQualifierInfo::OID_UNOTICE); |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * Get user notice qualifier. |
|
171 | + * |
|
172 | + * @throws \LogicException |
|
173 | + * @return UserNoticeQualifier |
|
174 | + */ |
|
175 | + public function userNoticeQualifier(): UserNoticeQualifier |
|
176 | + { |
|
177 | + if (!$this->hasUserNoticeQualifier()) { |
|
178 | + throw new \LogicException("User notice qualifier not set."); |
|
179 | + } |
|
180 | + return $this->get(PolicyQualifierInfo::OID_UNOTICE); |
|
181 | + } |
|
182 | + |
|
183 | + /** |
|
184 | + * Get ASN.1 structure. |
|
185 | + * |
|
186 | + * @return Sequence |
|
187 | + */ |
|
188 | + public function toASN1(): Sequence |
|
189 | + { |
|
190 | + $elements = array(new ObjectIdentifier($this->_oid)); |
|
191 | + if (count($this->_qualifiers)) { |
|
192 | + $qualifiers = array_map( |
|
193 | + function (PolicyQualifierInfo $pqi) { |
|
194 | + return $pqi->toASN1(); |
|
195 | + }, array_values($this->_qualifiers)); |
|
196 | + $elements[] = new Sequence(...$qualifiers); |
|
197 | + } |
|
198 | + return new Sequence(...$elements); |
|
199 | + } |
|
200 | + |
|
201 | + /** |
|
202 | + * Get number of qualifiers. |
|
203 | + * |
|
204 | + * @see \Countable::count() |
|
205 | + * @return int |
|
206 | + */ |
|
207 | + public function count(): int |
|
208 | + { |
|
209 | + return count($this->_qualifiers); |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * Get iterator for qualifiers. |
|
214 | + * |
|
215 | + * @see \IteratorAggregate::getIterator() |
|
216 | + * @return \ArrayIterator |
|
217 | + */ |
|
218 | + public function getIterator(): \ArrayIterator |
|
219 | + { |
|
220 | + return new \ArrayIterator($this->_qualifiers); |
|
221 | + } |
|
222 | 222 | } |
@@ -16,83 +16,83 @@ |
||
16 | 16 | */ |
17 | 17 | class NoticeReference |
18 | 18 | { |
19 | - /** |
|
20 | - * Organization. |
|
21 | - * |
|
22 | - * @var DisplayText $_organization |
|
23 | - */ |
|
24 | - protected $_organization; |
|
19 | + /** |
|
20 | + * Organization. |
|
21 | + * |
|
22 | + * @var DisplayText $_organization |
|
23 | + */ |
|
24 | + protected $_organization; |
|
25 | 25 | |
26 | - /** |
|
27 | - * Notification reference numbers. |
|
28 | - * |
|
29 | - * @var int[] $_numbers |
|
30 | - */ |
|
31 | - protected $_numbers; |
|
26 | + /** |
|
27 | + * Notification reference numbers. |
|
28 | + * |
|
29 | + * @var int[] $_numbers |
|
30 | + */ |
|
31 | + protected $_numbers; |
|
32 | 32 | |
33 | - /** |
|
34 | - * Constructor. |
|
35 | - * |
|
36 | - * @param DisplayText $organization |
|
37 | - * @param int ...$numbers |
|
38 | - */ |
|
39 | - public function __construct(DisplayText $organization, int ...$numbers) |
|
40 | - { |
|
41 | - $this->_organization = $organization; |
|
42 | - $this->_numbers = $numbers; |
|
43 | - } |
|
33 | + /** |
|
34 | + * Constructor. |
|
35 | + * |
|
36 | + * @param DisplayText $organization |
|
37 | + * @param int ...$numbers |
|
38 | + */ |
|
39 | + public function __construct(DisplayText $organization, int ...$numbers) |
|
40 | + { |
|
41 | + $this->_organization = $organization; |
|
42 | + $this->_numbers = $numbers; |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Initialize from ASN.1. |
|
47 | - * |
|
48 | - * @param Sequence $seq |
|
49 | - * @return self |
|
50 | - */ |
|
51 | - public static function fromASN1(Sequence $seq): self |
|
52 | - { |
|
53 | - $org = DisplayText::fromASN1($seq->at(0)->asString()); |
|
54 | - $numbers = array_map( |
|
55 | - function (UnspecifiedType $el) { |
|
56 | - return $el->asInteger()->intNumber(); |
|
57 | - }, |
|
58 | - $seq->at(1) |
|
59 | - ->asSequence() |
|
60 | - ->elements()); |
|
61 | - return new self($org, ...$numbers); |
|
62 | - } |
|
45 | + /** |
|
46 | + * Initialize from ASN.1. |
|
47 | + * |
|
48 | + * @param Sequence $seq |
|
49 | + * @return self |
|
50 | + */ |
|
51 | + public static function fromASN1(Sequence $seq): self |
|
52 | + { |
|
53 | + $org = DisplayText::fromASN1($seq->at(0)->asString()); |
|
54 | + $numbers = array_map( |
|
55 | + function (UnspecifiedType $el) { |
|
56 | + return $el->asInteger()->intNumber(); |
|
57 | + }, |
|
58 | + $seq->at(1) |
|
59 | + ->asSequence() |
|
60 | + ->elements()); |
|
61 | + return new self($org, ...$numbers); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Get reference organization. |
|
66 | - * |
|
67 | - * @return DisplayText |
|
68 | - */ |
|
69 | - public function organization(): DisplayText |
|
70 | - { |
|
71 | - return $this->_organization; |
|
72 | - } |
|
64 | + /** |
|
65 | + * Get reference organization. |
|
66 | + * |
|
67 | + * @return DisplayText |
|
68 | + */ |
|
69 | + public function organization(): DisplayText |
|
70 | + { |
|
71 | + return $this->_organization; |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * Get reference numbers. |
|
76 | - * |
|
77 | - * @return int[] |
|
78 | - */ |
|
79 | - public function numbers(): array |
|
80 | - { |
|
81 | - return $this->_numbers; |
|
82 | - } |
|
74 | + /** |
|
75 | + * Get reference numbers. |
|
76 | + * |
|
77 | + * @return int[] |
|
78 | + */ |
|
79 | + public function numbers(): array |
|
80 | + { |
|
81 | + return $this->_numbers; |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * Generate ASN.1 structure. |
|
86 | - * |
|
87 | - * @return Sequence |
|
88 | - */ |
|
89 | - public function toASN1(): Sequence |
|
90 | - { |
|
91 | - $org = $this->_organization->toASN1(); |
|
92 | - $nums = array_map( |
|
93 | - function ($number) { |
|
94 | - return new Integer($number); |
|
95 | - }, $this->_numbers); |
|
96 | - return new Sequence($org, new Sequence(...$nums)); |
|
97 | - } |
|
84 | + /** |
|
85 | + * Generate ASN.1 structure. |
|
86 | + * |
|
87 | + * @return Sequence |
|
88 | + */ |
|
89 | + public function toASN1(): Sequence |
|
90 | + { |
|
91 | + $org = $this->_organization->toASN1(); |
|
92 | + $nums = array_map( |
|
93 | + function ($number) { |
|
94 | + return new Integer($number); |
|
95 | + }, $this->_numbers); |
|
96 | + return new Sequence($org, new Sequence(...$nums)); |
|
97 | + } |
|
98 | 98 | } |
@@ -13,72 +13,72 @@ |
||
13 | 13 | */ |
14 | 14 | class UniqueIdentifier |
15 | 15 | { |
16 | - /** |
|
17 | - * Identifier. |
|
18 | - * |
|
19 | - * @var BitString $_uid |
|
20 | - */ |
|
21 | - protected $_uid; |
|
16 | + /** |
|
17 | + * Identifier. |
|
18 | + * |
|
19 | + * @var BitString $_uid |
|
20 | + */ |
|
21 | + protected $_uid; |
|
22 | 22 | |
23 | - /** |
|
24 | - * Constructor. |
|
25 | - * |
|
26 | - * @param BitString $bs |
|
27 | - */ |
|
28 | - public function __construct(BitString $bs) |
|
29 | - { |
|
30 | - $this->_uid = $bs; |
|
31 | - } |
|
23 | + /** |
|
24 | + * Constructor. |
|
25 | + * |
|
26 | + * @param BitString $bs |
|
27 | + */ |
|
28 | + public function __construct(BitString $bs) |
|
29 | + { |
|
30 | + $this->_uid = $bs; |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * Initialize from ASN.1. |
|
35 | - * |
|
36 | - * @param BitString $bs |
|
37 | - * @return self |
|
38 | - */ |
|
39 | - public static function fromASN1(BitString $bs): UniqueIdentifier |
|
40 | - { |
|
41 | - return new self($bs); |
|
42 | - } |
|
33 | + /** |
|
34 | + * Initialize from ASN.1. |
|
35 | + * |
|
36 | + * @param BitString $bs |
|
37 | + * @return self |
|
38 | + */ |
|
39 | + public static function fromASN1(BitString $bs): UniqueIdentifier |
|
40 | + { |
|
41 | + return new self($bs); |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * Initialize from string. |
|
46 | - * |
|
47 | - * @param string $str |
|
48 | - * @return self |
|
49 | - */ |
|
50 | - public static function fromString(string $str): UniqueIdentifier |
|
51 | - { |
|
52 | - return new self(new BitString($str)); |
|
53 | - } |
|
44 | + /** |
|
45 | + * Initialize from string. |
|
46 | + * |
|
47 | + * @param string $str |
|
48 | + * @return self |
|
49 | + */ |
|
50 | + public static function fromString(string $str): UniqueIdentifier |
|
51 | + { |
|
52 | + return new self(new BitString($str)); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * Get unique identifier as a string. |
|
57 | - * |
|
58 | - * @return string |
|
59 | - */ |
|
60 | - public function string(): string |
|
61 | - { |
|
62 | - return $this->_uid->string(); |
|
63 | - } |
|
55 | + /** |
|
56 | + * Get unique identifier as a string. |
|
57 | + * |
|
58 | + * @return string |
|
59 | + */ |
|
60 | + public function string(): string |
|
61 | + { |
|
62 | + return $this->_uid->string(); |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * Get unique identifier as a bit string. |
|
67 | - * |
|
68 | - * @return BitString |
|
69 | - */ |
|
70 | - public function bitString(): BitString |
|
71 | - { |
|
72 | - return $this->_uid; |
|
73 | - } |
|
65 | + /** |
|
66 | + * Get unique identifier as a bit string. |
|
67 | + * |
|
68 | + * @return BitString |
|
69 | + */ |
|
70 | + public function bitString(): BitString |
|
71 | + { |
|
72 | + return $this->_uid; |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Get ASN.1 element. |
|
77 | - * |
|
78 | - * @return BitString |
|
79 | - */ |
|
80 | - public function toASN1(): BitString |
|
81 | - { |
|
82 | - return $this->_uid; |
|
83 | - } |
|
75 | + /** |
|
76 | + * Get ASN.1 element. |
|
77 | + * |
|
78 | + * @return BitString |
|
79 | + */ |
|
80 | + public function toASN1(): BitString |
|
81 | + { |
|
82 | + return $this->_uid; |
|
83 | + } |
|
84 | 84 | } |
@@ -12,208 +12,208 @@ |
||
12 | 12 | */ |
13 | 13 | class CertificateBundle implements \Countable, \IteratorAggregate |
14 | 14 | { |
15 | - /** |
|
16 | - * Certificates. |
|
17 | - * |
|
18 | - * @var Certificate[] $_certs |
|
19 | - */ |
|
20 | - protected $_certs; |
|
15 | + /** |
|
16 | + * Certificates. |
|
17 | + * |
|
18 | + * @var Certificate[] $_certs |
|
19 | + */ |
|
20 | + protected $_certs; |
|
21 | 21 | |
22 | - /** |
|
23 | - * Mapping from public key id to array of certificates. |
|
24 | - * |
|
25 | - * @var null|(Certificate[])[] |
|
26 | - */ |
|
27 | - private $_keyIdMap; |
|
22 | + /** |
|
23 | + * Mapping from public key id to array of certificates. |
|
24 | + * |
|
25 | + * @var null|(Certificate[])[] |
|
26 | + */ |
|
27 | + private $_keyIdMap; |
|
28 | 28 | |
29 | - /** |
|
30 | - * Constructor. |
|
31 | - * |
|
32 | - * @param Certificate ...$certs Certificate objects |
|
33 | - */ |
|
34 | - public function __construct(Certificate ...$certs) |
|
35 | - { |
|
36 | - $this->_certs = $certs; |
|
37 | - } |
|
29 | + /** |
|
30 | + * Constructor. |
|
31 | + * |
|
32 | + * @param Certificate ...$certs Certificate objects |
|
33 | + */ |
|
34 | + public function __construct(Certificate ...$certs) |
|
35 | + { |
|
36 | + $this->_certs = $certs; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * Reset internal cached variables on clone. |
|
41 | - */ |
|
42 | - public function __clone() |
|
43 | - { |
|
44 | - $this->_keyIdMap = null; |
|
45 | - } |
|
39 | + /** |
|
40 | + * Reset internal cached variables on clone. |
|
41 | + */ |
|
42 | + public function __clone() |
|
43 | + { |
|
44 | + $this->_keyIdMap = null; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Initialize from PEMs. |
|
49 | - * |
|
50 | - * @param PEM ...$pems PEM objects |
|
51 | - * @return self |
|
52 | - */ |
|
53 | - public static function fromPEMs(PEM ...$pems): self |
|
54 | - { |
|
55 | - $certs = array_map( |
|
56 | - function ($pem) { |
|
57 | - return Certificate::fromPEM($pem); |
|
58 | - }, $pems); |
|
59 | - return new self(...$certs); |
|
60 | - } |
|
47 | + /** |
|
48 | + * Initialize from PEMs. |
|
49 | + * |
|
50 | + * @param PEM ...$pems PEM objects |
|
51 | + * @return self |
|
52 | + */ |
|
53 | + public static function fromPEMs(PEM ...$pems): self |
|
54 | + { |
|
55 | + $certs = array_map( |
|
56 | + function ($pem) { |
|
57 | + return Certificate::fromPEM($pem); |
|
58 | + }, $pems); |
|
59 | + return new self(...$certs); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Initialize from PEM bundle. |
|
64 | - * |
|
65 | - * @param PEMBundle $pem_bundle |
|
66 | - * @return self |
|
67 | - */ |
|
68 | - public static function fromPEMBundle(PEMBundle $pem_bundle): self |
|
69 | - { |
|
70 | - return self::fromPEMs(...$pem_bundle->all()); |
|
71 | - } |
|
62 | + /** |
|
63 | + * Initialize from PEM bundle. |
|
64 | + * |
|
65 | + * @param PEMBundle $pem_bundle |
|
66 | + * @return self |
|
67 | + */ |
|
68 | + public static function fromPEMBundle(PEMBundle $pem_bundle): self |
|
69 | + { |
|
70 | + return self::fromPEMs(...$pem_bundle->all()); |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * Get self with certificates added. |
|
75 | - * |
|
76 | - * @param Certificate ...$cert |
|
77 | - * @return self |
|
78 | - */ |
|
79 | - public function withCertificates(Certificate ...$cert): self |
|
80 | - { |
|
81 | - $obj = clone $this; |
|
82 | - $obj->_certs = array_merge($obj->_certs, $cert); |
|
83 | - return $obj; |
|
84 | - } |
|
73 | + /** |
|
74 | + * Get self with certificates added. |
|
75 | + * |
|
76 | + * @param Certificate ...$cert |
|
77 | + * @return self |
|
78 | + */ |
|
79 | + public function withCertificates(Certificate ...$cert): self |
|
80 | + { |
|
81 | + $obj = clone $this; |
|
82 | + $obj->_certs = array_merge($obj->_certs, $cert); |
|
83 | + return $obj; |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Get self with certificates from PEMBundle added. |
|
88 | - * |
|
89 | - * @param PEMBundle $pem_bundle |
|
90 | - * @return self |
|
91 | - */ |
|
92 | - public function withPEMBundle(PEMBundle $pem_bundle): self |
|
93 | - { |
|
94 | - $certs = $this->_certs; |
|
95 | - foreach ($pem_bundle as $pem) { |
|
96 | - $certs[] = Certificate::fromPEM($pem); |
|
97 | - } |
|
98 | - return new self(...$certs); |
|
99 | - } |
|
86 | + /** |
|
87 | + * Get self with certificates from PEMBundle added. |
|
88 | + * |
|
89 | + * @param PEMBundle $pem_bundle |
|
90 | + * @return self |
|
91 | + */ |
|
92 | + public function withPEMBundle(PEMBundle $pem_bundle): self |
|
93 | + { |
|
94 | + $certs = $this->_certs; |
|
95 | + foreach ($pem_bundle as $pem) { |
|
96 | + $certs[] = Certificate::fromPEM($pem); |
|
97 | + } |
|
98 | + return new self(...$certs); |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Get self with single certificate from PEM added. |
|
103 | - * |
|
104 | - * @param PEM $pem |
|
105 | - * @return self |
|
106 | - */ |
|
107 | - public function withPEM(PEM $pem): self |
|
108 | - { |
|
109 | - $certs = $this->_certs; |
|
110 | - $certs[] = Certificate::fromPEM($pem); |
|
111 | - return new self(...$certs); |
|
112 | - } |
|
101 | + /** |
|
102 | + * Get self with single certificate from PEM added. |
|
103 | + * |
|
104 | + * @param PEM $pem |
|
105 | + * @return self |
|
106 | + */ |
|
107 | + public function withPEM(PEM $pem): self |
|
108 | + { |
|
109 | + $certs = $this->_certs; |
|
110 | + $certs[] = Certificate::fromPEM($pem); |
|
111 | + return new self(...$certs); |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * Check whether bundle contains a given certificate. |
|
116 | - * |
|
117 | - * @param Certificate $cert |
|
118 | - * @return bool |
|
119 | - */ |
|
120 | - public function contains(Certificate $cert): bool |
|
121 | - { |
|
122 | - $id = self::_getCertKeyId($cert); |
|
123 | - $map = $this->_getKeyIdMap(); |
|
124 | - if (!isset($map[$id])) { |
|
125 | - return false; |
|
126 | - } |
|
127 | - foreach ($map[$id] as $c) { |
|
128 | - /** @var Certificate $c */ |
|
129 | - if ($cert->equals($c)) { |
|
130 | - return true; |
|
131 | - } |
|
132 | - } |
|
133 | - return false; |
|
134 | - } |
|
114 | + /** |
|
115 | + * Check whether bundle contains a given certificate. |
|
116 | + * |
|
117 | + * @param Certificate $cert |
|
118 | + * @return bool |
|
119 | + */ |
|
120 | + public function contains(Certificate $cert): bool |
|
121 | + { |
|
122 | + $id = self::_getCertKeyId($cert); |
|
123 | + $map = $this->_getKeyIdMap(); |
|
124 | + if (!isset($map[$id])) { |
|
125 | + return false; |
|
126 | + } |
|
127 | + foreach ($map[$id] as $c) { |
|
128 | + /** @var Certificate $c */ |
|
129 | + if ($cert->equals($c)) { |
|
130 | + return true; |
|
131 | + } |
|
132 | + } |
|
133 | + return false; |
|
134 | + } |
|
135 | 135 | |
136 | - /** |
|
137 | - * Get all certificates that have given subject key identifier. |
|
138 | - * |
|
139 | - * @param string $id |
|
140 | - * @return Certificate[] |
|
141 | - */ |
|
142 | - public function allBySubjectKeyIdentifier(string $id): array |
|
143 | - { |
|
144 | - $map = $this->_getKeyIdMap(); |
|
145 | - if (!isset($map[$id])) { |
|
146 | - return array(); |
|
147 | - } |
|
148 | - return $map[$id]; |
|
149 | - } |
|
136 | + /** |
|
137 | + * Get all certificates that have given subject key identifier. |
|
138 | + * |
|
139 | + * @param string $id |
|
140 | + * @return Certificate[] |
|
141 | + */ |
|
142 | + public function allBySubjectKeyIdentifier(string $id): array |
|
143 | + { |
|
144 | + $map = $this->_getKeyIdMap(); |
|
145 | + if (!isset($map[$id])) { |
|
146 | + return array(); |
|
147 | + } |
|
148 | + return $map[$id]; |
|
149 | + } |
|
150 | 150 | |
151 | - /** |
|
152 | - * Get all certificates in a bundle. |
|
153 | - * |
|
154 | - * @return Certificate[] |
|
155 | - */ |
|
156 | - public function all(): array |
|
157 | - { |
|
158 | - return $this->_certs; |
|
159 | - } |
|
151 | + /** |
|
152 | + * Get all certificates in a bundle. |
|
153 | + * |
|
154 | + * @return Certificate[] |
|
155 | + */ |
|
156 | + public function all(): array |
|
157 | + { |
|
158 | + return $this->_certs; |
|
159 | + } |
|
160 | 160 | |
161 | - /** |
|
162 | - * Get certificate mapping by public key id. |
|
163 | - * |
|
164 | - * @return (Certificate[])[] |
|
165 | - */ |
|
166 | - private function _getKeyIdMap(): array |
|
167 | - { |
|
168 | - // lazily build mapping |
|
169 | - if (!isset($this->_keyIdMap)) { |
|
170 | - $this->_keyIdMap = array(); |
|
171 | - foreach ($this->_certs as $cert) { |
|
172 | - $id = self::_getCertKeyId($cert); |
|
173 | - if (!isset($this->_keyIdMap[$id])) { |
|
174 | - $this->_keyIdMap[$id] = array(); |
|
175 | - } |
|
176 | - array_push($this->_keyIdMap[$id], $cert); |
|
177 | - } |
|
178 | - } |
|
179 | - return $this->_keyIdMap; |
|
180 | - } |
|
161 | + /** |
|
162 | + * Get certificate mapping by public key id. |
|
163 | + * |
|
164 | + * @return (Certificate[])[] |
|
165 | + */ |
|
166 | + private function _getKeyIdMap(): array |
|
167 | + { |
|
168 | + // lazily build mapping |
|
169 | + if (!isset($this->_keyIdMap)) { |
|
170 | + $this->_keyIdMap = array(); |
|
171 | + foreach ($this->_certs as $cert) { |
|
172 | + $id = self::_getCertKeyId($cert); |
|
173 | + if (!isset($this->_keyIdMap[$id])) { |
|
174 | + $this->_keyIdMap[$id] = array(); |
|
175 | + } |
|
176 | + array_push($this->_keyIdMap[$id], $cert); |
|
177 | + } |
|
178 | + } |
|
179 | + return $this->_keyIdMap; |
|
180 | + } |
|
181 | 181 | |
182 | - /** |
|
183 | - * Get public key id for the certificate. |
|
184 | - * |
|
185 | - * @param Certificate $cert |
|
186 | - * @return string |
|
187 | - */ |
|
188 | - private static function _getCertKeyId(Certificate $cert): string |
|
189 | - { |
|
190 | - $exts = $cert->tbsCertificate()->extensions(); |
|
191 | - if ($exts->hasSubjectKeyIdentifier()) { |
|
192 | - return $exts->subjectKeyIdentifier()->keyIdentifier(); |
|
193 | - } |
|
194 | - return $cert->tbsCertificate() |
|
195 | - ->subjectPublicKeyInfo() |
|
196 | - ->keyIdentifier(); |
|
197 | - } |
|
182 | + /** |
|
183 | + * Get public key id for the certificate. |
|
184 | + * |
|
185 | + * @param Certificate $cert |
|
186 | + * @return string |
|
187 | + */ |
|
188 | + private static function _getCertKeyId(Certificate $cert): string |
|
189 | + { |
|
190 | + $exts = $cert->tbsCertificate()->extensions(); |
|
191 | + if ($exts->hasSubjectKeyIdentifier()) { |
|
192 | + return $exts->subjectKeyIdentifier()->keyIdentifier(); |
|
193 | + } |
|
194 | + return $cert->tbsCertificate() |
|
195 | + ->subjectPublicKeyInfo() |
|
196 | + ->keyIdentifier(); |
|
197 | + } |
|
198 | 198 | |
199 | - /** |
|
200 | - * |
|
201 | - * @see \Countable::count() |
|
202 | - * @return int |
|
203 | - */ |
|
204 | - public function count(): int |
|
205 | - { |
|
206 | - return count($this->_certs); |
|
207 | - } |
|
199 | + /** |
|
200 | + * |
|
201 | + * @see \Countable::count() |
|
202 | + * @return int |
|
203 | + */ |
|
204 | + public function count(): int |
|
205 | + { |
|
206 | + return count($this->_certs); |
|
207 | + } |
|
208 | 208 | |
209 | - /** |
|
210 | - * Get iterator for certificates. |
|
211 | - * |
|
212 | - * @see \IteratorAggregate::getIterator() |
|
213 | - * @return \ArrayIterator |
|
214 | - */ |
|
215 | - public function getIterator(): \ArrayIterator |
|
216 | - { |
|
217 | - return new \ArrayIterator($this->_certs); |
|
218 | - } |
|
209 | + /** |
|
210 | + * Get iterator for certificates. |
|
211 | + * |
|
212 | + * @see \IteratorAggregate::getIterator() |
|
213 | + * @return \ArrayIterator |
|
214 | + */ |
|
215 | + public function getIterator(): \ArrayIterator |
|
216 | + { |
|
217 | + return new \ArrayIterator($this->_certs); |
|
218 | + } |
|
219 | 219 | } |