@@ -50,6 +50,7 @@ |
||
| 50 | 50 | * @param PathValidationConfig $config Validation config |
| 51 | 51 | * @param Certificate ...$certificates Certificates from the trust anchor to |
| 52 | 52 | * the end-entity certificate |
| 53 | + * @param Certificate[] $certificates |
|
| 53 | 54 | */ |
| 54 | 55 | public function __construct(Crypto $crypto, PathValidationConfig $config, |
| 55 | 56 | Certificate ...$certificates) |
@@ -17,584 +17,584 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class PathValidator |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * Crypto engine. |
|
| 22 | - * |
|
| 23 | - * @var Crypto $_crypto |
|
| 24 | - */ |
|
| 25 | - protected $_crypto; |
|
| 20 | + /** |
|
| 21 | + * Crypto engine. |
|
| 22 | + * |
|
| 23 | + * @var Crypto $_crypto |
|
| 24 | + */ |
|
| 25 | + protected $_crypto; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Path validation configuration. |
|
| 29 | - * |
|
| 30 | - * @var PathValidationConfig $_config |
|
| 31 | - */ |
|
| 32 | - protected $_config; |
|
| 27 | + /** |
|
| 28 | + * Path validation configuration. |
|
| 29 | + * |
|
| 30 | + * @var PathValidationConfig $_config |
|
| 31 | + */ |
|
| 32 | + protected $_config; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Certification path. |
|
| 36 | - * |
|
| 37 | - * @var Certificate[] $_certificates |
|
| 38 | - */ |
|
| 39 | - protected $_certificates; |
|
| 34 | + /** |
|
| 35 | + * Certification path. |
|
| 36 | + * |
|
| 37 | + * @var Certificate[] $_certificates |
|
| 38 | + */ |
|
| 39 | + protected $_certificates; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Certification path trust anchor. |
|
| 43 | - * |
|
| 44 | - * @var Certificate $_trustAnchor |
|
| 45 | - */ |
|
| 46 | - protected $_trustAnchor; |
|
| 41 | + /** |
|
| 42 | + * Certification path trust anchor. |
|
| 43 | + * |
|
| 44 | + * @var Certificate $_trustAnchor |
|
| 45 | + */ |
|
| 46 | + protected $_trustAnchor; |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Constructor. |
|
| 50 | - * |
|
| 51 | - * @param Crypto $crypto Crypto engine |
|
| 52 | - * @param PathValidationConfig $config Validation config |
|
| 53 | - * @param Certificate ...$certificates Certificates from the trust anchor to |
|
| 54 | - * the end-entity certificate |
|
| 55 | - */ |
|
| 56 | - public function __construct(Crypto $crypto, PathValidationConfig $config, |
|
| 57 | - Certificate ...$certificates) |
|
| 58 | - { |
|
| 59 | - if (!count($certificates)) { |
|
| 60 | - throw new \LogicException("No certificates."); |
|
| 61 | - } |
|
| 62 | - $this->_crypto = $crypto; |
|
| 63 | - $this->_config = $config; |
|
| 64 | - $this->_certificates = $certificates; |
|
| 65 | - // if trust anchor is explicitly given in configuration |
|
| 66 | - if ($config->hasTrustAnchor()) { |
|
| 67 | - $this->_trustAnchor = $config->trustAnchor(); |
|
| 68 | - } else { |
|
| 69 | - $this->_trustAnchor = $certificates[0]; |
|
| 70 | - } |
|
| 71 | - } |
|
| 48 | + /** |
|
| 49 | + * Constructor. |
|
| 50 | + * |
|
| 51 | + * @param Crypto $crypto Crypto engine |
|
| 52 | + * @param PathValidationConfig $config Validation config |
|
| 53 | + * @param Certificate ...$certificates Certificates from the trust anchor to |
|
| 54 | + * the end-entity certificate |
|
| 55 | + */ |
|
| 56 | + public function __construct(Crypto $crypto, PathValidationConfig $config, |
|
| 57 | + Certificate ...$certificates) |
|
| 58 | + { |
|
| 59 | + if (!count($certificates)) { |
|
| 60 | + throw new \LogicException("No certificates."); |
|
| 61 | + } |
|
| 62 | + $this->_crypto = $crypto; |
|
| 63 | + $this->_config = $config; |
|
| 64 | + $this->_certificates = $certificates; |
|
| 65 | + // if trust anchor is explicitly given in configuration |
|
| 66 | + if ($config->hasTrustAnchor()) { |
|
| 67 | + $this->_trustAnchor = $config->trustAnchor(); |
|
| 68 | + } else { |
|
| 69 | + $this->_trustAnchor = $certificates[0]; |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * Validate certification path. |
|
| 75 | - * |
|
| 76 | - * @throws PathValidationException |
|
| 77 | - * @return PathValidationResult |
|
| 78 | - */ |
|
| 79 | - public function validate() |
|
| 80 | - { |
|
| 81 | - $n = count($this->_certificates); |
|
| 82 | - $state = ValidatorState::initialize($this->_config, $this->_trustAnchor, |
|
| 83 | - $n); |
|
| 84 | - for ($i = 0; $i < $n; ++$i) { |
|
| 85 | - $state = $state->withIndex($i + 1); |
|
| 86 | - $cert = $this->_certificates[$i]; |
|
| 87 | - // process certificate (section 6.1.3.) |
|
| 88 | - $state = $this->_processCertificate($state, $cert); |
|
| 89 | - if (!$state->isFinal()) { |
|
| 90 | - // prepare next certificate (section 6.1.4.) |
|
| 91 | - $state = $this->_prepareNext($state, $cert); |
|
| 92 | - } |
|
| 93 | - } |
|
| 94 | - if (!isset($cert)) { |
|
| 95 | - throw new \LogicException("No certificates."); |
|
| 96 | - } |
|
| 97 | - // wrap-up (section 6.1.5.) |
|
| 98 | - $state = $this->_wrapUp($state, $cert); |
|
| 99 | - // return outputs |
|
| 100 | - return $state->getResult($this->_certificates); |
|
| 101 | - } |
|
| 73 | + /** |
|
| 74 | + * Validate certification path. |
|
| 75 | + * |
|
| 76 | + * @throws PathValidationException |
|
| 77 | + * @return PathValidationResult |
|
| 78 | + */ |
|
| 79 | + public function validate() |
|
| 80 | + { |
|
| 81 | + $n = count($this->_certificates); |
|
| 82 | + $state = ValidatorState::initialize($this->_config, $this->_trustAnchor, |
|
| 83 | + $n); |
|
| 84 | + for ($i = 0; $i < $n; ++$i) { |
|
| 85 | + $state = $state->withIndex($i + 1); |
|
| 86 | + $cert = $this->_certificates[$i]; |
|
| 87 | + // process certificate (section 6.1.3.) |
|
| 88 | + $state = $this->_processCertificate($state, $cert); |
|
| 89 | + if (!$state->isFinal()) { |
|
| 90 | + // prepare next certificate (section 6.1.4.) |
|
| 91 | + $state = $this->_prepareNext($state, $cert); |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | + if (!isset($cert)) { |
|
| 95 | + throw new \LogicException("No certificates."); |
|
| 96 | + } |
|
| 97 | + // wrap-up (section 6.1.5.) |
|
| 98 | + $state = $this->_wrapUp($state, $cert); |
|
| 99 | + // return outputs |
|
| 100 | + return $state->getResult($this->_certificates); |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * Apply basic certificate processing according to RFC 5280 section 6.1.3. |
|
| 105 | - * |
|
| 106 | - * @link https://tools.ietf.org/html/rfc5280#section-6.1.3 |
|
| 107 | - * @param ValidatorState $state |
|
| 108 | - * @param Certificate $cert |
|
| 109 | - * @throws PathValidationException |
|
| 110 | - * @return ValidatorState |
|
| 111 | - */ |
|
| 112 | - private function _processCertificate(ValidatorState $state, Certificate $cert) |
|
| 113 | - { |
|
| 114 | - // (a.1) verify signature |
|
| 115 | - $this->_verifySignature($state, $cert); |
|
| 116 | - // (a.2) check validity period |
|
| 117 | - $this->_checkValidity($cert); |
|
| 118 | - // (a.3) check that certificate is not revoked |
|
| 119 | - $this->_checkRevocation($cert); |
|
| 120 | - // (a.4) check issuer |
|
| 121 | - $this->_checkIssuer($state, $cert); |
|
| 122 | - // (b)(c) if certificate is self-issued and it is not |
|
| 123 | - // the final certificate in the path, skip this step |
|
| 124 | - if (!($cert->isSelfIssued() && !$state->isFinal())) { |
|
| 125 | - // (b) check permitted subtrees |
|
| 126 | - $this->_checkPermittedSubtrees($state, $cert); |
|
| 127 | - // (c) check excluded subtrees |
|
| 128 | - $this->_checkExcludedSubtrees($state, $cert); |
|
| 129 | - } |
|
| 130 | - $extensions = $cert->tbsCertificate()->extensions(); |
|
| 131 | - if ($extensions->hasCertificatePolicies()) { |
|
| 132 | - // (d) process policy information |
|
| 133 | - if ($state->hasValidPolicyTree()) { |
|
| 134 | - $state = $state->validPolicyTree()->processPolicies($state, |
|
| 135 | - $cert); |
|
| 136 | - } |
|
| 137 | - } else { |
|
| 138 | - // (e) certificate policies extension not present, |
|
| 139 | - // set the valid_policy_tree to NULL |
|
| 140 | - $state = $state->withoutValidPolicyTree(); |
|
| 141 | - } |
|
| 142 | - // (f) check that explicit_policy > 0 or valid_policy_tree is set |
|
| 143 | - if (!($state->explicitPolicy() > 0 || $state->hasValidPolicyTree())) { |
|
| 144 | - throw new PathValidationException("No valid policies."); |
|
| 145 | - } |
|
| 146 | - return $state; |
|
| 147 | - } |
|
| 103 | + /** |
|
| 104 | + * Apply basic certificate processing according to RFC 5280 section 6.1.3. |
|
| 105 | + * |
|
| 106 | + * @link https://tools.ietf.org/html/rfc5280#section-6.1.3 |
|
| 107 | + * @param ValidatorState $state |
|
| 108 | + * @param Certificate $cert |
|
| 109 | + * @throws PathValidationException |
|
| 110 | + * @return ValidatorState |
|
| 111 | + */ |
|
| 112 | + private function _processCertificate(ValidatorState $state, Certificate $cert) |
|
| 113 | + { |
|
| 114 | + // (a.1) verify signature |
|
| 115 | + $this->_verifySignature($state, $cert); |
|
| 116 | + // (a.2) check validity period |
|
| 117 | + $this->_checkValidity($cert); |
|
| 118 | + // (a.3) check that certificate is not revoked |
|
| 119 | + $this->_checkRevocation($cert); |
|
| 120 | + // (a.4) check issuer |
|
| 121 | + $this->_checkIssuer($state, $cert); |
|
| 122 | + // (b)(c) if certificate is self-issued and it is not |
|
| 123 | + // the final certificate in the path, skip this step |
|
| 124 | + if (!($cert->isSelfIssued() && !$state->isFinal())) { |
|
| 125 | + // (b) check permitted subtrees |
|
| 126 | + $this->_checkPermittedSubtrees($state, $cert); |
|
| 127 | + // (c) check excluded subtrees |
|
| 128 | + $this->_checkExcludedSubtrees($state, $cert); |
|
| 129 | + } |
|
| 130 | + $extensions = $cert->tbsCertificate()->extensions(); |
|
| 131 | + if ($extensions->hasCertificatePolicies()) { |
|
| 132 | + // (d) process policy information |
|
| 133 | + if ($state->hasValidPolicyTree()) { |
|
| 134 | + $state = $state->validPolicyTree()->processPolicies($state, |
|
| 135 | + $cert); |
|
| 136 | + } |
|
| 137 | + } else { |
|
| 138 | + // (e) certificate policies extension not present, |
|
| 139 | + // set the valid_policy_tree to NULL |
|
| 140 | + $state = $state->withoutValidPolicyTree(); |
|
| 141 | + } |
|
| 142 | + // (f) check that explicit_policy > 0 or valid_policy_tree is set |
|
| 143 | + if (!($state->explicitPolicy() > 0 || $state->hasValidPolicyTree())) { |
|
| 144 | + throw new PathValidationException("No valid policies."); |
|
| 145 | + } |
|
| 146 | + return $state; |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - /** |
|
| 150 | - * Apply preparation for the certificate i+1 according to rfc5280 section |
|
| 151 | - * 6.1.4. |
|
| 152 | - * |
|
| 153 | - * @link https://tools.ietf.org/html/rfc5280#section-6.1.4 |
|
| 154 | - * @param ValidatorState $state |
|
| 155 | - * @param Certificate $cert |
|
| 156 | - * @return ValidatorState |
|
| 157 | - */ |
|
| 158 | - private function _prepareNext(ValidatorState $state, Certificate $cert) |
|
| 159 | - { |
|
| 160 | - // (a)(b) if policy mappings extension is present |
|
| 161 | - $state = $this->_preparePolicyMappings($state, $cert); |
|
| 162 | - // (c) assign working_issuer_name |
|
| 163 | - $state = $state->withWorkingIssuerName( |
|
| 164 | - $cert->tbsCertificate() |
|
| 165 | - ->subject()); |
|
| 166 | - // (d)(e)(f) |
|
| 167 | - $state = $this->_setPublicKeyState($state, $cert); |
|
| 168 | - // (g) if name constraints extension is present |
|
| 169 | - $state = $this->_prepareNameConstraints($state, $cert); |
|
| 170 | - // (h) if certificate is not self-issued |
|
| 171 | - if (!$cert->isSelfIssued()) { |
|
| 172 | - $state = $this->_prepareNonSelfIssued($state); |
|
| 173 | - } |
|
| 174 | - // (i) if policy constraints extension is present |
|
| 175 | - $state = $this->_preparePolicyConstraints($state, $cert); |
|
| 176 | - // (j) if inhibit any policy extension is present |
|
| 177 | - $state = $this->_prepareInhibitAnyPolicy($state, $cert); |
|
| 178 | - // (k) check basic constraints |
|
| 179 | - $this->_processBasicContraints($cert); |
|
| 180 | - // (l) verify max_path_length |
|
| 181 | - $state = $this->_verifyMaxPathLength($state, $cert); |
|
| 182 | - // (m) check pathLenContraint |
|
| 183 | - $state = $this->_processPathLengthContraint($state, $cert); |
|
| 184 | - // (n) check key usage |
|
| 185 | - $this->_checkKeyUsage($cert); |
|
| 186 | - // (o) process relevant extensions |
|
| 187 | - $state = $this->_processExtensions($state, $cert); |
|
| 188 | - return $state; |
|
| 189 | - } |
|
| 149 | + /** |
|
| 150 | + * Apply preparation for the certificate i+1 according to rfc5280 section |
|
| 151 | + * 6.1.4. |
|
| 152 | + * |
|
| 153 | + * @link https://tools.ietf.org/html/rfc5280#section-6.1.4 |
|
| 154 | + * @param ValidatorState $state |
|
| 155 | + * @param Certificate $cert |
|
| 156 | + * @return ValidatorState |
|
| 157 | + */ |
|
| 158 | + private function _prepareNext(ValidatorState $state, Certificate $cert) |
|
| 159 | + { |
|
| 160 | + // (a)(b) if policy mappings extension is present |
|
| 161 | + $state = $this->_preparePolicyMappings($state, $cert); |
|
| 162 | + // (c) assign working_issuer_name |
|
| 163 | + $state = $state->withWorkingIssuerName( |
|
| 164 | + $cert->tbsCertificate() |
|
| 165 | + ->subject()); |
|
| 166 | + // (d)(e)(f) |
|
| 167 | + $state = $this->_setPublicKeyState($state, $cert); |
|
| 168 | + // (g) if name constraints extension is present |
|
| 169 | + $state = $this->_prepareNameConstraints($state, $cert); |
|
| 170 | + // (h) if certificate is not self-issued |
|
| 171 | + if (!$cert->isSelfIssued()) { |
|
| 172 | + $state = $this->_prepareNonSelfIssued($state); |
|
| 173 | + } |
|
| 174 | + // (i) if policy constraints extension is present |
|
| 175 | + $state = $this->_preparePolicyConstraints($state, $cert); |
|
| 176 | + // (j) if inhibit any policy extension is present |
|
| 177 | + $state = $this->_prepareInhibitAnyPolicy($state, $cert); |
|
| 178 | + // (k) check basic constraints |
|
| 179 | + $this->_processBasicContraints($cert); |
|
| 180 | + // (l) verify max_path_length |
|
| 181 | + $state = $this->_verifyMaxPathLength($state, $cert); |
|
| 182 | + // (m) check pathLenContraint |
|
| 183 | + $state = $this->_processPathLengthContraint($state, $cert); |
|
| 184 | + // (n) check key usage |
|
| 185 | + $this->_checkKeyUsage($cert); |
|
| 186 | + // (o) process relevant extensions |
|
| 187 | + $state = $this->_processExtensions($state, $cert); |
|
| 188 | + return $state; |
|
| 189 | + } |
|
| 190 | 190 | |
| 191 | - /** |
|
| 192 | - * Apply wrap-up procedure according to RFC 5280 section 6.1.5. |
|
| 193 | - * |
|
| 194 | - * @link https://tools.ietf.org/html/rfc5280#section-6.1.5 |
|
| 195 | - * @param ValidatorState $state |
|
| 196 | - * @param Certificate $cert |
|
| 197 | - * @throws PathValidationException |
|
| 198 | - */ |
|
| 199 | - private function _wrapUp(ValidatorState $state, Certificate $cert) |
|
| 200 | - { |
|
| 201 | - $tbs_cert = $cert->tbsCertificate(); |
|
| 202 | - $extensions = $tbs_cert->extensions(); |
|
| 203 | - // (a) |
|
| 204 | - if ($state->explicitPolicy() > 0) { |
|
| 205 | - $state = $state->withExplicitPolicy($state->explicitPolicy() - 1); |
|
| 206 | - } |
|
| 207 | - // (b) |
|
| 208 | - if ($extensions->hasPolicyConstraints()) { |
|
| 209 | - $ext = $extensions->policyConstraints(); |
|
| 210 | - if ($ext->hasRequireExplicitPolicy() && |
|
| 211 | - $ext->requireExplicitPolicy() == 0) { |
|
| 212 | - $state = $state->withExplicitPolicy(0); |
|
| 213 | - } |
|
| 214 | - } |
|
| 215 | - // (c)(d)(e) |
|
| 216 | - $state = $this->_setPublicKeyState($state, $cert); |
|
| 217 | - // (f) process relevant extensions |
|
| 218 | - $state = $this->_processExtensions($state, $cert); |
|
| 219 | - // (g) intersection of valid_policy_tree and the initial-policy-set |
|
| 220 | - $state = $this->_calculatePolicyIntersection($state); |
|
| 221 | - // check that explicit_policy > 0 or valid_policy_tree is set |
|
| 222 | - if (!($state->explicitPolicy() > 0 || $state->hasValidPolicyTree())) { |
|
| 223 | - throw new PathValidationException("No valid policies."); |
|
| 224 | - } |
|
| 225 | - // path validation succeeded |
|
| 226 | - return $state; |
|
| 227 | - } |
|
| 191 | + /** |
|
| 192 | + * Apply wrap-up procedure according to RFC 5280 section 6.1.5. |
|
| 193 | + * |
|
| 194 | + * @link https://tools.ietf.org/html/rfc5280#section-6.1.5 |
|
| 195 | + * @param ValidatorState $state |
|
| 196 | + * @param Certificate $cert |
|
| 197 | + * @throws PathValidationException |
|
| 198 | + */ |
|
| 199 | + private function _wrapUp(ValidatorState $state, Certificate $cert) |
|
| 200 | + { |
|
| 201 | + $tbs_cert = $cert->tbsCertificate(); |
|
| 202 | + $extensions = $tbs_cert->extensions(); |
|
| 203 | + // (a) |
|
| 204 | + if ($state->explicitPolicy() > 0) { |
|
| 205 | + $state = $state->withExplicitPolicy($state->explicitPolicy() - 1); |
|
| 206 | + } |
|
| 207 | + // (b) |
|
| 208 | + if ($extensions->hasPolicyConstraints()) { |
|
| 209 | + $ext = $extensions->policyConstraints(); |
|
| 210 | + if ($ext->hasRequireExplicitPolicy() && |
|
| 211 | + $ext->requireExplicitPolicy() == 0) { |
|
| 212 | + $state = $state->withExplicitPolicy(0); |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | + // (c)(d)(e) |
|
| 216 | + $state = $this->_setPublicKeyState($state, $cert); |
|
| 217 | + // (f) process relevant extensions |
|
| 218 | + $state = $this->_processExtensions($state, $cert); |
|
| 219 | + // (g) intersection of valid_policy_tree and the initial-policy-set |
|
| 220 | + $state = $this->_calculatePolicyIntersection($state); |
|
| 221 | + // check that explicit_policy > 0 or valid_policy_tree is set |
|
| 222 | + if (!($state->explicitPolicy() > 0 || $state->hasValidPolicyTree())) { |
|
| 223 | + throw new PathValidationException("No valid policies."); |
|
| 224 | + } |
|
| 225 | + // path validation succeeded |
|
| 226 | + return $state; |
|
| 227 | + } |
|
| 228 | 228 | |
| 229 | - /** |
|
| 230 | - * Update working_public_key, working_public_key_parameters and |
|
| 231 | - * working_public_key_algorithm state variables from certificate. |
|
| 232 | - * |
|
| 233 | - * @param ValidatorState $state |
|
| 234 | - * @param Certificate $cert |
|
| 235 | - * @return ValidatorState |
|
| 236 | - */ |
|
| 237 | - private function _setPublicKeyState(ValidatorState $state, Certificate $cert) |
|
| 238 | - { |
|
| 239 | - $pk_info = $cert->tbsCertificate()->subjectPublicKeyInfo(); |
|
| 240 | - // assign working_public_key |
|
| 241 | - $state = $state->withWorkingPublicKey($pk_info); |
|
| 242 | - // assign working_public_key_parameters |
|
| 243 | - $params = ValidatorState::getAlgorithmParameters( |
|
| 244 | - $pk_info->algorithmIdentifier()); |
|
| 245 | - if (null !== $params) { |
|
| 246 | - $state = $state->withWorkingPublicKeyParameters($params); |
|
| 247 | - } else { |
|
| 248 | - // if algorithms differ, set parameters to null |
|
| 249 | - if ($pk_info->algorithmIdentifier()->oid() !== |
|
| 250 | - $state->workingPublicKeyAlgorithm()->oid()) { |
|
| 251 | - $state = $state->withWorkingPublicKeyParameters(null); |
|
| 252 | - } |
|
| 253 | - } |
|
| 254 | - // assign working_public_key_algorithm |
|
| 255 | - $state = $state->withWorkingPublicKeyAlgorithm( |
|
| 256 | - $pk_info->algorithmIdentifier()); |
|
| 257 | - return $state; |
|
| 258 | - } |
|
| 229 | + /** |
|
| 230 | + * Update working_public_key, working_public_key_parameters and |
|
| 231 | + * working_public_key_algorithm state variables from certificate. |
|
| 232 | + * |
|
| 233 | + * @param ValidatorState $state |
|
| 234 | + * @param Certificate $cert |
|
| 235 | + * @return ValidatorState |
|
| 236 | + */ |
|
| 237 | + private function _setPublicKeyState(ValidatorState $state, Certificate $cert) |
|
| 238 | + { |
|
| 239 | + $pk_info = $cert->tbsCertificate()->subjectPublicKeyInfo(); |
|
| 240 | + // assign working_public_key |
|
| 241 | + $state = $state->withWorkingPublicKey($pk_info); |
|
| 242 | + // assign working_public_key_parameters |
|
| 243 | + $params = ValidatorState::getAlgorithmParameters( |
|
| 244 | + $pk_info->algorithmIdentifier()); |
|
| 245 | + if (null !== $params) { |
|
| 246 | + $state = $state->withWorkingPublicKeyParameters($params); |
|
| 247 | + } else { |
|
| 248 | + // if algorithms differ, set parameters to null |
|
| 249 | + if ($pk_info->algorithmIdentifier()->oid() !== |
|
| 250 | + $state->workingPublicKeyAlgorithm()->oid()) { |
|
| 251 | + $state = $state->withWorkingPublicKeyParameters(null); |
|
| 252 | + } |
|
| 253 | + } |
|
| 254 | + // assign working_public_key_algorithm |
|
| 255 | + $state = $state->withWorkingPublicKeyAlgorithm( |
|
| 256 | + $pk_info->algorithmIdentifier()); |
|
| 257 | + return $state; |
|
| 258 | + } |
|
| 259 | 259 | |
| 260 | - /** |
|
| 261 | - * Verify certificate signature. |
|
| 262 | - * |
|
| 263 | - * @param ValidatorState $state |
|
| 264 | - * @param Certificate $cert |
|
| 265 | - * @throws PathValidationException |
|
| 266 | - */ |
|
| 267 | - private function _verifySignature(ValidatorState $state, Certificate $cert) |
|
| 268 | - { |
|
| 269 | - try { |
|
| 270 | - $valid = $cert->verify($state->workingPublicKey(), $this->_crypto); |
|
| 271 | - } catch (\RuntimeException $e) { |
|
| 272 | - throw new PathValidationException( |
|
| 273 | - "Failed to verify signature: " . $e->getMessage(), 0, $e); |
|
| 274 | - } |
|
| 275 | - if (!$valid) { |
|
| 276 | - throw new PathValidationException( |
|
| 277 | - "Certificate signature doesn't match."); |
|
| 278 | - } |
|
| 279 | - } |
|
| 260 | + /** |
|
| 261 | + * Verify certificate signature. |
|
| 262 | + * |
|
| 263 | + * @param ValidatorState $state |
|
| 264 | + * @param Certificate $cert |
|
| 265 | + * @throws PathValidationException |
|
| 266 | + */ |
|
| 267 | + private function _verifySignature(ValidatorState $state, Certificate $cert) |
|
| 268 | + { |
|
| 269 | + try { |
|
| 270 | + $valid = $cert->verify($state->workingPublicKey(), $this->_crypto); |
|
| 271 | + } catch (\RuntimeException $e) { |
|
| 272 | + throw new PathValidationException( |
|
| 273 | + "Failed to verify signature: " . $e->getMessage(), 0, $e); |
|
| 274 | + } |
|
| 275 | + if (!$valid) { |
|
| 276 | + throw new PathValidationException( |
|
| 277 | + "Certificate signature doesn't match."); |
|
| 278 | + } |
|
| 279 | + } |
|
| 280 | 280 | |
| 281 | - /** |
|
| 282 | - * Check certificate validity. |
|
| 283 | - * |
|
| 284 | - * @param Certificate $cert |
|
| 285 | - * @throws PathValidationException |
|
| 286 | - */ |
|
| 287 | - private function _checkValidity(Certificate $cert) |
|
| 288 | - { |
|
| 289 | - $refdt = $this->_config->dateTime(); |
|
| 290 | - $validity = $cert->tbsCertificate()->validity(); |
|
| 291 | - if ($validity->notBefore() |
|
| 292 | - ->dateTime() |
|
| 293 | - ->diff($refdt)->invert) { |
|
| 294 | - throw new PathValidationException( |
|
| 295 | - "Certificate validity period has not started."); |
|
| 296 | - } |
|
| 297 | - if ($refdt->diff($validity->notAfter() |
|
| 298 | - ->dateTime())->invert) { |
|
| 299 | - throw new PathValidationException("Certificate has expired."); |
|
| 300 | - } |
|
| 301 | - } |
|
| 281 | + /** |
|
| 282 | + * Check certificate validity. |
|
| 283 | + * |
|
| 284 | + * @param Certificate $cert |
|
| 285 | + * @throws PathValidationException |
|
| 286 | + */ |
|
| 287 | + private function _checkValidity(Certificate $cert) |
|
| 288 | + { |
|
| 289 | + $refdt = $this->_config->dateTime(); |
|
| 290 | + $validity = $cert->tbsCertificate()->validity(); |
|
| 291 | + if ($validity->notBefore() |
|
| 292 | + ->dateTime() |
|
| 293 | + ->diff($refdt)->invert) { |
|
| 294 | + throw new PathValidationException( |
|
| 295 | + "Certificate validity period has not started."); |
|
| 296 | + } |
|
| 297 | + if ($refdt->diff($validity->notAfter() |
|
| 298 | + ->dateTime())->invert) { |
|
| 299 | + throw new PathValidationException("Certificate has expired."); |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | 302 | |
| 303 | - /** |
|
| 304 | - * Check certificate revocation. |
|
| 305 | - * |
|
| 306 | - * @param Certificate $cert |
|
| 307 | - */ |
|
| 308 | - private function _checkRevocation(Certificate $cert) |
|
| 309 | - { |
|
| 310 | - // @todo Implement CRL handling |
|
| 311 | - } |
|
| 303 | + /** |
|
| 304 | + * Check certificate revocation. |
|
| 305 | + * |
|
| 306 | + * @param Certificate $cert |
|
| 307 | + */ |
|
| 308 | + private function _checkRevocation(Certificate $cert) |
|
| 309 | + { |
|
| 310 | + // @todo Implement CRL handling |
|
| 311 | + } |
|
| 312 | 312 | |
| 313 | - /** |
|
| 314 | - * Check certificate issuer. |
|
| 315 | - * |
|
| 316 | - * @param ValidatorState $state |
|
| 317 | - * @param Certificate $cert |
|
| 318 | - * @throws PathValidationException |
|
| 319 | - */ |
|
| 320 | - private function _checkIssuer(ValidatorState $state, Certificate $cert) |
|
| 321 | - { |
|
| 322 | - if (!$cert->tbsCertificate() |
|
| 323 | - ->issuer() |
|
| 324 | - ->equals($state->workingIssuerName())) { |
|
| 325 | - throw new PathValidationException("Certification issuer mismatch."); |
|
| 326 | - } |
|
| 327 | - } |
|
| 313 | + /** |
|
| 314 | + * Check certificate issuer. |
|
| 315 | + * |
|
| 316 | + * @param ValidatorState $state |
|
| 317 | + * @param Certificate $cert |
|
| 318 | + * @throws PathValidationException |
|
| 319 | + */ |
|
| 320 | + private function _checkIssuer(ValidatorState $state, Certificate $cert) |
|
| 321 | + { |
|
| 322 | + if (!$cert->tbsCertificate() |
|
| 323 | + ->issuer() |
|
| 324 | + ->equals($state->workingIssuerName())) { |
|
| 325 | + throw new PathValidationException("Certification issuer mismatch."); |
|
| 326 | + } |
|
| 327 | + } |
|
| 328 | 328 | |
| 329 | - /** |
|
| 330 | - * |
|
| 331 | - * @param ValidatorState $state |
|
| 332 | - * @param Certificate $cert |
|
| 333 | - */ |
|
| 334 | - private function _checkPermittedSubtrees(ValidatorState $state, |
|
| 335 | - Certificate $cert) |
|
| 336 | - { |
|
| 337 | - // @todo Implement |
|
| 338 | - $state->permittedSubtrees(); |
|
| 339 | - } |
|
| 329 | + /** |
|
| 330 | + * |
|
| 331 | + * @param ValidatorState $state |
|
| 332 | + * @param Certificate $cert |
|
| 333 | + */ |
|
| 334 | + private function _checkPermittedSubtrees(ValidatorState $state, |
|
| 335 | + Certificate $cert) |
|
| 336 | + { |
|
| 337 | + // @todo Implement |
|
| 338 | + $state->permittedSubtrees(); |
|
| 339 | + } |
|
| 340 | 340 | |
| 341 | - /** |
|
| 342 | - * |
|
| 343 | - * @param ValidatorState $state |
|
| 344 | - * @param Certificate $cert |
|
| 345 | - */ |
|
| 346 | - private function _checkExcludedSubtrees(ValidatorState $state, |
|
| 347 | - Certificate $cert) |
|
| 348 | - { |
|
| 349 | - // @todo Implement |
|
| 350 | - $state->excludedSubtrees(); |
|
| 351 | - } |
|
| 341 | + /** |
|
| 342 | + * |
|
| 343 | + * @param ValidatorState $state |
|
| 344 | + * @param Certificate $cert |
|
| 345 | + */ |
|
| 346 | + private function _checkExcludedSubtrees(ValidatorState $state, |
|
| 347 | + Certificate $cert) |
|
| 348 | + { |
|
| 349 | + // @todo Implement |
|
| 350 | + $state->excludedSubtrees(); |
|
| 351 | + } |
|
| 352 | 352 | |
| 353 | - /** |
|
| 354 | - * Apply policy mappings handling for the preparation step. |
|
| 355 | - * |
|
| 356 | - * @param ValidatorState $state |
|
| 357 | - * @param Certificate $cert |
|
| 358 | - * @throws PathValidationException |
|
| 359 | - * @return ValidatorState |
|
| 360 | - */ |
|
| 361 | - private function _preparePolicyMappings(ValidatorState $state, |
|
| 362 | - Certificate $cert) |
|
| 363 | - { |
|
| 364 | - $extensions = $cert->tbsCertificate()->extensions(); |
|
| 365 | - if ($extensions->hasPolicyMappings()) { |
|
| 366 | - // (a) verify that anyPolicy mapping is not used |
|
| 367 | - if ($extensions->policyMappings()->hasAnyPolicyMapping()) { |
|
| 368 | - throw new PathValidationException("anyPolicy mapping found."); |
|
| 369 | - } |
|
| 370 | - // (b) process policy mappings |
|
| 371 | - if ($state->hasValidPolicyTree()) { |
|
| 372 | - $state = $state->validPolicyTree()->processMappings($state, |
|
| 373 | - $cert); |
|
| 374 | - } |
|
| 375 | - } |
|
| 376 | - return $state; |
|
| 377 | - } |
|
| 353 | + /** |
|
| 354 | + * Apply policy mappings handling for the preparation step. |
|
| 355 | + * |
|
| 356 | + * @param ValidatorState $state |
|
| 357 | + * @param Certificate $cert |
|
| 358 | + * @throws PathValidationException |
|
| 359 | + * @return ValidatorState |
|
| 360 | + */ |
|
| 361 | + private function _preparePolicyMappings(ValidatorState $state, |
|
| 362 | + Certificate $cert) |
|
| 363 | + { |
|
| 364 | + $extensions = $cert->tbsCertificate()->extensions(); |
|
| 365 | + if ($extensions->hasPolicyMappings()) { |
|
| 366 | + // (a) verify that anyPolicy mapping is not used |
|
| 367 | + if ($extensions->policyMappings()->hasAnyPolicyMapping()) { |
|
| 368 | + throw new PathValidationException("anyPolicy mapping found."); |
|
| 369 | + } |
|
| 370 | + // (b) process policy mappings |
|
| 371 | + if ($state->hasValidPolicyTree()) { |
|
| 372 | + $state = $state->validPolicyTree()->processMappings($state, |
|
| 373 | + $cert); |
|
| 374 | + } |
|
| 375 | + } |
|
| 376 | + return $state; |
|
| 377 | + } |
|
| 378 | 378 | |
| 379 | - /** |
|
| 380 | - * Apply name constraints handling for the preparation step. |
|
| 381 | - * |
|
| 382 | - * @param ValidatorState $state |
|
| 383 | - * @param Certificate $cert |
|
| 384 | - * @return ValidatorState |
|
| 385 | - */ |
|
| 386 | - private function _prepareNameConstraints(ValidatorState $state, |
|
| 387 | - Certificate $cert) |
|
| 388 | - { |
|
| 389 | - $extensions = $cert->tbsCertificate()->extensions(); |
|
| 390 | - if ($extensions->hasNameConstraints()) { |
|
| 391 | - $state = $this->_processNameConstraints($state, $cert); |
|
| 392 | - } |
|
| 393 | - return $state; |
|
| 394 | - } |
|
| 379 | + /** |
|
| 380 | + * Apply name constraints handling for the preparation step. |
|
| 381 | + * |
|
| 382 | + * @param ValidatorState $state |
|
| 383 | + * @param Certificate $cert |
|
| 384 | + * @return ValidatorState |
|
| 385 | + */ |
|
| 386 | + private function _prepareNameConstraints(ValidatorState $state, |
|
| 387 | + Certificate $cert) |
|
| 388 | + { |
|
| 389 | + $extensions = $cert->tbsCertificate()->extensions(); |
|
| 390 | + if ($extensions->hasNameConstraints()) { |
|
| 391 | + $state = $this->_processNameConstraints($state, $cert); |
|
| 392 | + } |
|
| 393 | + return $state; |
|
| 394 | + } |
|
| 395 | 395 | |
| 396 | - /** |
|
| 397 | - * Apply preparation for a non-self-signed certificate. |
|
| 398 | - * |
|
| 399 | - * @param ValidatorState $state |
|
| 400 | - * @return ValidatorState |
|
| 401 | - */ |
|
| 402 | - private function _prepareNonSelfIssued(ValidatorState $state) |
|
| 403 | - { |
|
| 404 | - // (h.1) |
|
| 405 | - if ($state->explicitPolicy() > 0) { |
|
| 406 | - $state = $state->withExplicitPolicy($state->explicitPolicy() - 1); |
|
| 407 | - } |
|
| 408 | - // (h.2) |
|
| 409 | - if ($state->policyMapping() > 0) { |
|
| 410 | - $state = $state->withPolicyMapping($state->policyMapping() - 1); |
|
| 411 | - } |
|
| 412 | - // (h.3) |
|
| 413 | - if ($state->inhibitAnyPolicy() > 0) { |
|
| 414 | - $state = $state->withInhibitAnyPolicy( |
|
| 415 | - $state->inhibitAnyPolicy() - 1); |
|
| 416 | - } |
|
| 417 | - return $state; |
|
| 418 | - } |
|
| 396 | + /** |
|
| 397 | + * Apply preparation for a non-self-signed certificate. |
|
| 398 | + * |
|
| 399 | + * @param ValidatorState $state |
|
| 400 | + * @return ValidatorState |
|
| 401 | + */ |
|
| 402 | + private function _prepareNonSelfIssued(ValidatorState $state) |
|
| 403 | + { |
|
| 404 | + // (h.1) |
|
| 405 | + if ($state->explicitPolicy() > 0) { |
|
| 406 | + $state = $state->withExplicitPolicy($state->explicitPolicy() - 1); |
|
| 407 | + } |
|
| 408 | + // (h.2) |
|
| 409 | + if ($state->policyMapping() > 0) { |
|
| 410 | + $state = $state->withPolicyMapping($state->policyMapping() - 1); |
|
| 411 | + } |
|
| 412 | + // (h.3) |
|
| 413 | + if ($state->inhibitAnyPolicy() > 0) { |
|
| 414 | + $state = $state->withInhibitAnyPolicy( |
|
| 415 | + $state->inhibitAnyPolicy() - 1); |
|
| 416 | + } |
|
| 417 | + return $state; |
|
| 418 | + } |
|
| 419 | 419 | |
| 420 | - /** |
|
| 421 | - * Apply policy constraints handling for the preparation step. |
|
| 422 | - * |
|
| 423 | - * @param ValidatorState $state |
|
| 424 | - * @param Certificate $cert |
|
| 425 | - * @return ValidatorState |
|
| 426 | - */ |
|
| 427 | - private function _preparePolicyConstraints(ValidatorState $state, |
|
| 428 | - Certificate $cert) |
|
| 429 | - { |
|
| 430 | - $extensions = $cert->tbsCertificate()->extensions(); |
|
| 431 | - if (!$extensions->hasPolicyConstraints()) { |
|
| 432 | - return $state; |
|
| 433 | - } |
|
| 434 | - $ext = $extensions->policyConstraints(); |
|
| 435 | - // (i.1) |
|
| 436 | - if ($ext->hasRequireExplicitPolicy() && |
|
| 437 | - $ext->requireExplicitPolicy() < $state->explicitPolicy()) { |
|
| 438 | - $state = $state->withExplicitPolicy($ext->requireExplicitPolicy()); |
|
| 439 | - } |
|
| 440 | - // (i.2) |
|
| 441 | - if ($ext->hasInhibitPolicyMapping() && |
|
| 442 | - $ext->inhibitPolicyMapping() < $state->policyMapping()) { |
|
| 443 | - $state = $state->withPolicyMapping($ext->inhibitPolicyMapping()); |
|
| 444 | - } |
|
| 445 | - return $state; |
|
| 446 | - } |
|
| 420 | + /** |
|
| 421 | + * Apply policy constraints handling for the preparation step. |
|
| 422 | + * |
|
| 423 | + * @param ValidatorState $state |
|
| 424 | + * @param Certificate $cert |
|
| 425 | + * @return ValidatorState |
|
| 426 | + */ |
|
| 427 | + private function _preparePolicyConstraints(ValidatorState $state, |
|
| 428 | + Certificate $cert) |
|
| 429 | + { |
|
| 430 | + $extensions = $cert->tbsCertificate()->extensions(); |
|
| 431 | + if (!$extensions->hasPolicyConstraints()) { |
|
| 432 | + return $state; |
|
| 433 | + } |
|
| 434 | + $ext = $extensions->policyConstraints(); |
|
| 435 | + // (i.1) |
|
| 436 | + if ($ext->hasRequireExplicitPolicy() && |
|
| 437 | + $ext->requireExplicitPolicy() < $state->explicitPolicy()) { |
|
| 438 | + $state = $state->withExplicitPolicy($ext->requireExplicitPolicy()); |
|
| 439 | + } |
|
| 440 | + // (i.2) |
|
| 441 | + if ($ext->hasInhibitPolicyMapping() && |
|
| 442 | + $ext->inhibitPolicyMapping() < $state->policyMapping()) { |
|
| 443 | + $state = $state->withPolicyMapping($ext->inhibitPolicyMapping()); |
|
| 444 | + } |
|
| 445 | + return $state; |
|
| 446 | + } |
|
| 447 | 447 | |
| 448 | - /** |
|
| 449 | - * Apply inhibit any-policy handling for the preparation step. |
|
| 450 | - * |
|
| 451 | - * @param ValidatorState $state |
|
| 452 | - * @param Certificate $cert |
|
| 453 | - * @return ValidatorState |
|
| 454 | - */ |
|
| 455 | - private function _prepareInhibitAnyPolicy(ValidatorState $state, |
|
| 456 | - Certificate $cert) |
|
| 457 | - { |
|
| 458 | - $extensions = $cert->tbsCertificate()->extensions(); |
|
| 459 | - if ($extensions->hasInhibitAnyPolicy()) { |
|
| 460 | - $ext = $extensions->inhibitAnyPolicy(); |
|
| 461 | - if ($ext->skipCerts() < $state->inhibitAnyPolicy()) { |
|
| 462 | - $state = $state->withInhibitAnyPolicy($ext->skipCerts()); |
|
| 463 | - } |
|
| 464 | - } |
|
| 465 | - return $state; |
|
| 466 | - } |
|
| 448 | + /** |
|
| 449 | + * Apply inhibit any-policy handling for the preparation step. |
|
| 450 | + * |
|
| 451 | + * @param ValidatorState $state |
|
| 452 | + * @param Certificate $cert |
|
| 453 | + * @return ValidatorState |
|
| 454 | + */ |
|
| 455 | + private function _prepareInhibitAnyPolicy(ValidatorState $state, |
|
| 456 | + Certificate $cert) |
|
| 457 | + { |
|
| 458 | + $extensions = $cert->tbsCertificate()->extensions(); |
|
| 459 | + if ($extensions->hasInhibitAnyPolicy()) { |
|
| 460 | + $ext = $extensions->inhibitAnyPolicy(); |
|
| 461 | + if ($ext->skipCerts() < $state->inhibitAnyPolicy()) { |
|
| 462 | + $state = $state->withInhibitAnyPolicy($ext->skipCerts()); |
|
| 463 | + } |
|
| 464 | + } |
|
| 465 | + return $state; |
|
| 466 | + } |
|
| 467 | 467 | |
| 468 | - /** |
|
| 469 | - * Verify maximum certification path length for the preparation step. |
|
| 470 | - * |
|
| 471 | - * @param ValidatorState $state |
|
| 472 | - * @param Certificate $cert |
|
| 473 | - * @throws PathValidationException |
|
| 474 | - * @return ValidatorState |
|
| 475 | - */ |
|
| 476 | - private function _verifyMaxPathLength(ValidatorState $state, |
|
| 477 | - Certificate $cert): ValidatorState |
|
| 478 | - { |
|
| 479 | - if (!$cert->isSelfIssued()) { |
|
| 480 | - if ($state->maxPathLength() <= 0) { |
|
| 481 | - throw new PathValidationException( |
|
| 482 | - "Certification path length exceeded."); |
|
| 483 | - } |
|
| 484 | - $state = $state->withMaxPathLength($state->maxPathLength() - 1); |
|
| 485 | - } |
|
| 486 | - return $state; |
|
| 487 | - } |
|
| 468 | + /** |
|
| 469 | + * Verify maximum certification path length for the preparation step. |
|
| 470 | + * |
|
| 471 | + * @param ValidatorState $state |
|
| 472 | + * @param Certificate $cert |
|
| 473 | + * @throws PathValidationException |
|
| 474 | + * @return ValidatorState |
|
| 475 | + */ |
|
| 476 | + private function _verifyMaxPathLength(ValidatorState $state, |
|
| 477 | + Certificate $cert): ValidatorState |
|
| 478 | + { |
|
| 479 | + if (!$cert->isSelfIssued()) { |
|
| 480 | + if ($state->maxPathLength() <= 0) { |
|
| 481 | + throw new PathValidationException( |
|
| 482 | + "Certification path length exceeded."); |
|
| 483 | + } |
|
| 484 | + $state = $state->withMaxPathLength($state->maxPathLength() - 1); |
|
| 485 | + } |
|
| 486 | + return $state; |
|
| 487 | + } |
|
| 488 | 488 | |
| 489 | - /** |
|
| 490 | - * Check key usage extension for the preparation step. |
|
| 491 | - * |
|
| 492 | - * @param Certificate $cert |
|
| 493 | - * @throws PathValidationException |
|
| 494 | - */ |
|
| 495 | - private function _checkKeyUsage(Certificate $cert) |
|
| 496 | - { |
|
| 497 | - $extensions = $cert->tbsCertificate()->extensions(); |
|
| 498 | - if ($extensions->hasKeyUsage()) { |
|
| 499 | - $ext = $extensions->keyUsage(); |
|
| 500 | - if (!$ext->isKeyCertSign()) { |
|
| 501 | - throw new PathValidationException("keyCertSign usage not set."); |
|
| 502 | - } |
|
| 503 | - } |
|
| 504 | - } |
|
| 489 | + /** |
|
| 490 | + * Check key usage extension for the preparation step. |
|
| 491 | + * |
|
| 492 | + * @param Certificate $cert |
|
| 493 | + * @throws PathValidationException |
|
| 494 | + */ |
|
| 495 | + private function _checkKeyUsage(Certificate $cert) |
|
| 496 | + { |
|
| 497 | + $extensions = $cert->tbsCertificate()->extensions(); |
|
| 498 | + if ($extensions->hasKeyUsage()) { |
|
| 499 | + $ext = $extensions->keyUsage(); |
|
| 500 | + if (!$ext->isKeyCertSign()) { |
|
| 501 | + throw new PathValidationException("keyCertSign usage not set."); |
|
| 502 | + } |
|
| 503 | + } |
|
| 504 | + } |
|
| 505 | 505 | |
| 506 | - /** |
|
| 507 | - * |
|
| 508 | - * @param ValidatorState $state |
|
| 509 | - * @param Certificate $cert |
|
| 510 | - * @return ValidatorState |
|
| 511 | - */ |
|
| 512 | - private function _processNameConstraints(ValidatorState $state, |
|
| 513 | - Certificate $cert): ValidatorState |
|
| 514 | - { |
|
| 515 | - // @todo Implement |
|
| 516 | - return $state; |
|
| 517 | - } |
|
| 506 | + /** |
|
| 507 | + * |
|
| 508 | + * @param ValidatorState $state |
|
| 509 | + * @param Certificate $cert |
|
| 510 | + * @return ValidatorState |
|
| 511 | + */ |
|
| 512 | + private function _processNameConstraints(ValidatorState $state, |
|
| 513 | + Certificate $cert): ValidatorState |
|
| 514 | + { |
|
| 515 | + // @todo Implement |
|
| 516 | + return $state; |
|
| 517 | + } |
|
| 518 | 518 | |
| 519 | - /** |
|
| 520 | - * Process basic constraints extension. |
|
| 521 | - * |
|
| 522 | - * @param Certificate $cert |
|
| 523 | - * @throws PathValidationException |
|
| 524 | - */ |
|
| 525 | - private function _processBasicContraints(Certificate $cert) |
|
| 526 | - { |
|
| 527 | - if ($cert->tbsCertificate()->version() == TBSCertificate::VERSION_3) { |
|
| 528 | - $extensions = $cert->tbsCertificate()->extensions(); |
|
| 529 | - if (!$extensions->hasBasicConstraints()) { |
|
| 530 | - throw new PathValidationException( |
|
| 531 | - "v3 certificate must have basicConstraints extension."); |
|
| 532 | - } |
|
| 533 | - // verify that cA is set to TRUE |
|
| 534 | - if (!$extensions->basicConstraints()->isCA()) { |
|
| 535 | - throw new PathValidationException( |
|
| 536 | - "Certificate is not a CA certificate."); |
|
| 537 | - } |
|
| 538 | - } |
|
| 539 | - } |
|
| 519 | + /** |
|
| 520 | + * Process basic constraints extension. |
|
| 521 | + * |
|
| 522 | + * @param Certificate $cert |
|
| 523 | + * @throws PathValidationException |
|
| 524 | + */ |
|
| 525 | + private function _processBasicContraints(Certificate $cert) |
|
| 526 | + { |
|
| 527 | + if ($cert->tbsCertificate()->version() == TBSCertificate::VERSION_3) { |
|
| 528 | + $extensions = $cert->tbsCertificate()->extensions(); |
|
| 529 | + if (!$extensions->hasBasicConstraints()) { |
|
| 530 | + throw new PathValidationException( |
|
| 531 | + "v3 certificate must have basicConstraints extension."); |
|
| 532 | + } |
|
| 533 | + // verify that cA is set to TRUE |
|
| 534 | + if (!$extensions->basicConstraints()->isCA()) { |
|
| 535 | + throw new PathValidationException( |
|
| 536 | + "Certificate is not a CA certificate."); |
|
| 537 | + } |
|
| 538 | + } |
|
| 539 | + } |
|
| 540 | 540 | |
| 541 | - /** |
|
| 542 | - * Process pathLenConstraint. |
|
| 543 | - * |
|
| 544 | - * @param ValidatorState $state |
|
| 545 | - * @param Certificate $cert |
|
| 546 | - * @return ValidatorState |
|
| 547 | - */ |
|
| 548 | - private function _processPathLengthContraint(ValidatorState $state, |
|
| 549 | - Certificate $cert): ValidatorState |
|
| 550 | - { |
|
| 551 | - $extensions = $cert->tbsCertificate()->extensions(); |
|
| 552 | - if ($extensions->hasBasicConstraints()) { |
|
| 553 | - $ext = $extensions->basicConstraints(); |
|
| 554 | - if ($ext->hasPathLen()) { |
|
| 555 | - if ($ext->pathLen() < $state->maxPathLength()) { |
|
| 556 | - $state = $state->withMaxPathLength($ext->pathLen()); |
|
| 557 | - } |
|
| 558 | - } |
|
| 559 | - } |
|
| 560 | - return $state; |
|
| 561 | - } |
|
| 541 | + /** |
|
| 542 | + * Process pathLenConstraint. |
|
| 543 | + * |
|
| 544 | + * @param ValidatorState $state |
|
| 545 | + * @param Certificate $cert |
|
| 546 | + * @return ValidatorState |
|
| 547 | + */ |
|
| 548 | + private function _processPathLengthContraint(ValidatorState $state, |
|
| 549 | + Certificate $cert): ValidatorState |
|
| 550 | + { |
|
| 551 | + $extensions = $cert->tbsCertificate()->extensions(); |
|
| 552 | + if ($extensions->hasBasicConstraints()) { |
|
| 553 | + $ext = $extensions->basicConstraints(); |
|
| 554 | + if ($ext->hasPathLen()) { |
|
| 555 | + if ($ext->pathLen() < $state->maxPathLength()) { |
|
| 556 | + $state = $state->withMaxPathLength($ext->pathLen()); |
|
| 557 | + } |
|
| 558 | + } |
|
| 559 | + } |
|
| 560 | + return $state; |
|
| 561 | + } |
|
| 562 | 562 | |
| 563 | - /** |
|
| 564 | - * |
|
| 565 | - * @param ValidatorState $state |
|
| 566 | - * @param Certificate $cert |
|
| 567 | - * @return ValidatorState |
|
| 568 | - */ |
|
| 569 | - private function _processExtensions(ValidatorState $state, Certificate $cert): ValidatorState |
|
| 570 | - { |
|
| 571 | - // @todo Implement |
|
| 572 | - return $state; |
|
| 573 | - } |
|
| 563 | + /** |
|
| 564 | + * |
|
| 565 | + * @param ValidatorState $state |
|
| 566 | + * @param Certificate $cert |
|
| 567 | + * @return ValidatorState |
|
| 568 | + */ |
|
| 569 | + private function _processExtensions(ValidatorState $state, Certificate $cert): ValidatorState |
|
| 570 | + { |
|
| 571 | + // @todo Implement |
|
| 572 | + return $state; |
|
| 573 | + } |
|
| 574 | 574 | |
| 575 | - /** |
|
| 576 | - * |
|
| 577 | - * @param ValidatorState $state |
|
| 578 | - * @return ValidatorState |
|
| 579 | - */ |
|
| 580 | - private function _calculatePolicyIntersection(ValidatorState $state): ValidatorState |
|
| 581 | - { |
|
| 582 | - // (i) If the valid_policy_tree is NULL, the intersection is NULL |
|
| 583 | - if (!$state->hasValidPolicyTree()) { |
|
| 584 | - return $state; |
|
| 585 | - } |
|
| 586 | - // (ii) If the valid_policy_tree is not NULL and |
|
| 587 | - // the user-initial-policy-set is any-policy, the intersection |
|
| 588 | - // is the entire valid_policy_tree |
|
| 589 | - $initial_policies = $this->_config->policySet(); |
|
| 590 | - if (in_array(PolicyInformation::OID_ANY_POLICY, $initial_policies)) { |
|
| 591 | - return $state; |
|
| 592 | - } |
|
| 593 | - // (iii) If the valid_policy_tree is not NULL and the |
|
| 594 | - // user-initial-policy-set is not any-policy, calculate |
|
| 595 | - // the intersection of the valid_policy_tree and the |
|
| 596 | - // user-initial-policy-set as follows |
|
| 597 | - return $state->validPolicyTree()->calculateIntersection($state, |
|
| 598 | - $initial_policies); |
|
| 599 | - } |
|
| 575 | + /** |
|
| 576 | + * |
|
| 577 | + * @param ValidatorState $state |
|
| 578 | + * @return ValidatorState |
|
| 579 | + */ |
|
| 580 | + private function _calculatePolicyIntersection(ValidatorState $state): ValidatorState |
|
| 581 | + { |
|
| 582 | + // (i) If the valid_policy_tree is NULL, the intersection is NULL |
|
| 583 | + if (!$state->hasValidPolicyTree()) { |
|
| 584 | + return $state; |
|
| 585 | + } |
|
| 586 | + // (ii) If the valid_policy_tree is not NULL and |
|
| 587 | + // the user-initial-policy-set is any-policy, the intersection |
|
| 588 | + // is the entire valid_policy_tree |
|
| 589 | + $initial_policies = $this->_config->policySet(); |
|
| 590 | + if (in_array(PolicyInformation::OID_ANY_POLICY, $initial_policies)) { |
|
| 591 | + return $state; |
|
| 592 | + } |
|
| 593 | + // (iii) If the valid_policy_tree is not NULL and the |
|
| 594 | + // user-initial-policy-set is not any-policy, calculate |
|
| 595 | + // the intersection of the valid_policy_tree and the |
|
| 596 | + // user-initial-policy-set as follows |
|
| 597 | + return $state->validPolicyTree()->calculateIntersection($state, |
|
| 598 | + $initial_policies); |
|
| 599 | + } |
|
| 600 | 600 | } |
@@ -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\CertificationPath\PathValidation; |
| 6 | 6 | |
@@ -16,15 +16,15 @@ |
||
| 16 | 16 | $mask = null; |
| 17 | 17 | $bytes = unpack("C*", $octets); |
| 18 | 18 | switch (count($bytes)) { |
| 19 | - case 4: |
|
| 20 | - $ip = implode(".", $bytes); |
|
| 21 | - break; |
|
| 22 | - case 8: |
|
| 23 | - $ip = implode(".", array_slice($bytes, 0, 4)); |
|
| 24 | - $mask = implode(".", array_slice($bytes, 4, 4)); |
|
| 25 | - break; |
|
| 26 | - default: |
|
| 27 | - throw new \UnexpectedValueException("Invalid IPv4 octet length."); |
|
| 19 | + case 4: |
|
| 20 | + $ip = implode(".", $bytes); |
|
| 21 | + break; |
|
| 22 | + case 8: |
|
| 23 | + $ip = implode(".", array_slice($bytes, 0, 4)); |
|
| 24 | + $mask = implode(".", array_slice($bytes, 4, 4)); |
|
| 25 | + break; |
|
| 26 | + default: |
|
| 27 | + throw new \UnexpectedValueException("Invalid IPv4 octet length."); |
|
| 28 | 28 | } |
| 29 | 29 | return new self($ip, $mask); |
| 30 | 30 | } |
@@ -6,42 +6,42 @@ |
||
| 6 | 6 | |
| 7 | 7 | class IPv4Address 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 | - $bytes = unpack("C*", $octets); |
|
| 20 | - switch (count($bytes)) { |
|
| 21 | - case 4: |
|
| 22 | - $ip = implode(".", $bytes); |
|
| 23 | - break; |
|
| 24 | - case 8: |
|
| 25 | - $ip = implode(".", array_slice($bytes, 0, 4)); |
|
| 26 | - $mask = implode(".", array_slice($bytes, 4, 4)); |
|
| 27 | - break; |
|
| 28 | - default: |
|
| 29 | - throw new \UnexpectedValueException("Invalid IPv4 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 | + $bytes = unpack("C*", $octets); |
|
| 20 | + switch (count($bytes)) { |
|
| 21 | + case 4: |
|
| 22 | + $ip = implode(".", $bytes); |
|
| 23 | + break; |
|
| 24 | + case 8: |
|
| 25 | + $ip = implode(".", array_slice($bytes, 0, 4)); |
|
| 26 | + $mask = implode(".", array_slice($bytes, 4, 4)); |
|
| 27 | + break; |
|
| 28 | + default: |
|
| 29 | + throw new \UnexpectedValueException("Invalid IPv4 octet length."); |
|
| 30 | + } |
|
| 31 | + return new self($ip, $mask); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * |
|
| 36 | - * {@inheritdoc} |
|
| 37 | - */ |
|
| 38 | - protected function _octets(): string |
|
| 39 | - { |
|
| 40 | - $bytes = array_map("intval", explode(".", $this->_ip)); |
|
| 41 | - if (isset($this->_mask)) { |
|
| 42 | - $bytes = array_merge($bytes, |
|
| 43 | - array_map("intval", explode(".", $this->_mask))); |
|
| 44 | - } |
|
| 45 | - return pack("C*", ...$bytes); |
|
| 46 | - } |
|
| 34 | + /** |
|
| 35 | + * |
|
| 36 | + * {@inheritdoc} |
|
| 37 | + */ |
|
| 38 | + protected function _octets(): string |
|
| 39 | + { |
|
| 40 | + $bytes = array_map("intval", explode(".", $this->_ip)); |
|
| 41 | + if (isset($this->_mask)) { |
|
| 42 | + $bytes = array_merge($bytes, |
|
| 43 | + array_map("intval", explode(".", $this->_mask))); |
|
| 44 | + } |
|
| 45 | + return pack("C*", ...$bytes); |
|
| 46 | + } |
|
| 47 | 47 | } |
@@ -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 | |
@@ -59,15 +59,15 @@ |
||
| 59 | 59 | { |
| 60 | 60 | $octets = $el->asOctetString()->string(); |
| 61 | 61 | switch (strlen($octets)) { |
| 62 | - case 4: |
|
| 63 | - case 8: |
|
| 64 | - return IPv4Address::fromOctets($octets); |
|
| 65 | - case 16: |
|
| 66 | - case 32: |
|
| 67 | - return IPv6Address::fromOctets($octets); |
|
| 68 | - default: |
|
| 69 | - throw new \UnexpectedValueException( |
|
| 70 | - "Invalid octet length for IP address."); |
|
| 62 | + case 4: |
|
| 63 | + case 8: |
|
| 64 | + return IPv4Address::fromOctets($octets); |
|
| 65 | + case 16: |
|
| 66 | + case 32: |
|
| 67 | + return IPv6Address::fromOctets($octets); |
|
| 68 | + default: |
|
| 69 | + throw new \UnexpectedValueException( |
|
| 70 | + "Invalid octet length for IP address."); |
|
| 71 | 71 | } |
| 72 | 72 | } |
| 73 | 73 | |
@@ -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 | |
@@ -16,15 +16,15 @@ |
||
| 16 | 16 | $mask = null; |
| 17 | 17 | $words = unpack("n*", $octets); |
| 18 | 18 | switch (count($words)) { |
| 19 | - case 8: |
|
| 20 | - $ip = self::_wordsToIPv6String($words); |
|
| 21 | - break; |
|
| 22 | - case 16: |
|
| 23 | - $ip = self::_wordsToIPv6String(array_slice($words, 0, 8)); |
|
| 24 | - $mask = self::_wordsToIPv6String(array_slice($words, 8, 8)); |
|
| 25 | - break; |
|
| 26 | - default: |
|
| 27 | - throw new \UnexpectedValueException("Invalid IPv6 octet length."); |
|
| 19 | + case 8: |
|
| 20 | + $ip = self::_wordsToIPv6String($words); |
|
| 21 | + break; |
|
| 22 | + case 16: |
|
| 23 | + $ip = self::_wordsToIPv6String(array_slice($words, 0, 8)); |
|
| 24 | + $mask = self::_wordsToIPv6String(array_slice($words, 8, 8)); |
|
| 25 | + break; |
|
| 26 | + default: |
|
| 27 | + throw new \UnexpectedValueException("Invalid IPv6 octet length."); |
|
| 28 | 28 | } |
| 29 | 29 | return new self($ip, $mask); |
| 30 | 30 | } |
@@ -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); |
@@ -13,147 +13,147 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | abstract class GeneralName |
| 15 | 15 | { |
| 16 | - // GeneralName CHOICE tags |
|
| 17 | - const TAG_OTHER_NAME = 0; |
|
| 18 | - const TAG_RFC822_NAME = 1; |
|
| 19 | - const TAG_DNS_NAME = 2; |
|
| 20 | - const TAG_X400_ADDRESS = 3; |
|
| 21 | - const TAG_DIRECTORY_NAME = 4; |
|
| 22 | - const TAG_EDI_PARTY_NAME = 5; |
|
| 23 | - const TAG_URI = 6; |
|
| 24 | - const TAG_IP_ADDRESS = 7; |
|
| 25 | - const TAG_REGISTERED_ID = 8; |
|
| 16 | + // GeneralName CHOICE tags |
|
| 17 | + const TAG_OTHER_NAME = 0; |
|
| 18 | + const TAG_RFC822_NAME = 1; |
|
| 19 | + const TAG_DNS_NAME = 2; |
|
| 20 | + const TAG_X400_ADDRESS = 3; |
|
| 21 | + const TAG_DIRECTORY_NAME = 4; |
|
| 22 | + const TAG_EDI_PARTY_NAME = 5; |
|
| 23 | + const TAG_URI = 6; |
|
| 24 | + const TAG_IP_ADDRESS = 7; |
|
| 25 | + const TAG_REGISTERED_ID = 8; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Chosen tag. |
|
| 29 | - * |
|
| 30 | - * @var int $_tag |
|
| 31 | - */ |
|
| 32 | - protected $_tag; |
|
| 27 | + /** |
|
| 28 | + * Chosen tag. |
|
| 29 | + * |
|
| 30 | + * @var int $_tag |
|
| 31 | + */ |
|
| 32 | + protected $_tag; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Get string value of the type. |
|
| 36 | - * |
|
| 37 | - * @return string |
|
| 38 | - */ |
|
| 39 | - abstract public function string(); |
|
| 34 | + /** |
|
| 35 | + * Get string value of the type. |
|
| 36 | + * |
|
| 37 | + * @return string |
|
| 38 | + */ |
|
| 39 | + abstract public function string(); |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Get ASN.1 value in GeneralName CHOICE context. |
|
| 43 | - * |
|
| 44 | - * @return TaggedType |
|
| 45 | - */ |
|
| 46 | - abstract protected function _choiceASN1(); |
|
| 41 | + /** |
|
| 42 | + * Get ASN.1 value in GeneralName CHOICE context. |
|
| 43 | + * |
|
| 44 | + * @return TaggedType |
|
| 45 | + */ |
|
| 46 | + abstract protected function _choiceASN1(); |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Initialize concrete object from the chosen ASN.1 element. |
|
| 50 | - * |
|
| 51 | - * @param UnspecifiedType $el |
|
| 52 | - * @return self |
|
| 53 | - */ |
|
| 54 | - public static function fromChosenASN1(UnspecifiedType $el) |
|
| 55 | - { |
|
| 56 | - throw new \BadMethodCallException( |
|
| 57 | - __FUNCTION__ . " must be implemented in the derived class."); |
|
| 58 | - } |
|
| 48 | + /** |
|
| 49 | + * Initialize concrete object from the chosen ASN.1 element. |
|
| 50 | + * |
|
| 51 | + * @param UnspecifiedType $el |
|
| 52 | + * @return self |
|
| 53 | + */ |
|
| 54 | + public static function fromChosenASN1(UnspecifiedType $el) |
|
| 55 | + { |
|
| 56 | + throw new \BadMethodCallException( |
|
| 57 | + __FUNCTION__ . " must be implemented in the derived class."); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * Initialize from ASN.1. |
|
| 62 | - * |
|
| 63 | - * @param TaggedType $el |
|
| 64 | - * @throws \UnexpectedValueException |
|
| 65 | - * @return self |
|
| 66 | - */ |
|
| 67 | - public static function fromASN1(TaggedType $el) |
|
| 68 | - { |
|
| 69 | - switch ($el->tag()) { |
|
| 70 | - // otherName |
|
| 71 | - case self::TAG_OTHER_NAME: |
|
| 72 | - return OtherName::fromChosenASN1( |
|
| 73 | - $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
| 74 | - // rfc822Name |
|
| 75 | - case self::TAG_RFC822_NAME: |
|
| 76 | - return RFC822Name::fromChosenASN1( |
|
| 77 | - $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
| 78 | - // dNSName |
|
| 79 | - case self::TAG_DNS_NAME: |
|
| 80 | - return DNSName::fromChosenASN1( |
|
| 81 | - $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
| 82 | - // x400Address |
|
| 83 | - case self::TAG_X400_ADDRESS: |
|
| 84 | - return X400Address::fromChosenASN1( |
|
| 85 | - $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
| 86 | - // directoryName |
|
| 87 | - case self::TAG_DIRECTORY_NAME: |
|
| 88 | - // because Name is a CHOICE, albeit having only one option, |
|
| 89 | - // explicit tagging must be used |
|
| 90 | - // (see X.680 07/2002 30.6.c) |
|
| 91 | - return DirectoryName::fromChosenASN1($el->asExplicit()); |
|
| 92 | - // ediPartyName |
|
| 93 | - case self::TAG_EDI_PARTY_NAME: |
|
| 94 | - return EDIPartyName::fromChosenASN1( |
|
| 95 | - $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
| 96 | - // uniformResourceIdentifier |
|
| 97 | - case self::TAG_URI: |
|
| 98 | - return UniformResourceIdentifier::fromChosenASN1( |
|
| 99 | - $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
| 100 | - // iPAddress |
|
| 101 | - case self::TAG_IP_ADDRESS: |
|
| 102 | - return IPAddress::fromChosenASN1( |
|
| 103 | - $el->asImplicit(Element::TYPE_OCTET_STRING)); |
|
| 104 | - // registeredID |
|
| 105 | - case self::TAG_REGISTERED_ID: |
|
| 106 | - return RegisteredID::fromChosenASN1( |
|
| 107 | - $el->asImplicit(Element::TYPE_OBJECT_IDENTIFIER)); |
|
| 108 | - } |
|
| 109 | - throw new \UnexpectedValueException( |
|
| 110 | - "GeneralName type " . $el->tag() . " not supported."); |
|
| 111 | - } |
|
| 60 | + /** |
|
| 61 | + * Initialize from ASN.1. |
|
| 62 | + * |
|
| 63 | + * @param TaggedType $el |
|
| 64 | + * @throws \UnexpectedValueException |
|
| 65 | + * @return self |
|
| 66 | + */ |
|
| 67 | + public static function fromASN1(TaggedType $el) |
|
| 68 | + { |
|
| 69 | + switch ($el->tag()) { |
|
| 70 | + // otherName |
|
| 71 | + case self::TAG_OTHER_NAME: |
|
| 72 | + return OtherName::fromChosenASN1( |
|
| 73 | + $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
| 74 | + // rfc822Name |
|
| 75 | + case self::TAG_RFC822_NAME: |
|
| 76 | + return RFC822Name::fromChosenASN1( |
|
| 77 | + $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
| 78 | + // dNSName |
|
| 79 | + case self::TAG_DNS_NAME: |
|
| 80 | + return DNSName::fromChosenASN1( |
|
| 81 | + $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
| 82 | + // x400Address |
|
| 83 | + case self::TAG_X400_ADDRESS: |
|
| 84 | + return X400Address::fromChosenASN1( |
|
| 85 | + $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
| 86 | + // directoryName |
|
| 87 | + case self::TAG_DIRECTORY_NAME: |
|
| 88 | + // because Name is a CHOICE, albeit having only one option, |
|
| 89 | + // explicit tagging must be used |
|
| 90 | + // (see X.680 07/2002 30.6.c) |
|
| 91 | + return DirectoryName::fromChosenASN1($el->asExplicit()); |
|
| 92 | + // ediPartyName |
|
| 93 | + case self::TAG_EDI_PARTY_NAME: |
|
| 94 | + return EDIPartyName::fromChosenASN1( |
|
| 95 | + $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
| 96 | + // uniformResourceIdentifier |
|
| 97 | + case self::TAG_URI: |
|
| 98 | + return UniformResourceIdentifier::fromChosenASN1( |
|
| 99 | + $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
| 100 | + // iPAddress |
|
| 101 | + case self::TAG_IP_ADDRESS: |
|
| 102 | + return IPAddress::fromChosenASN1( |
|
| 103 | + $el->asImplicit(Element::TYPE_OCTET_STRING)); |
|
| 104 | + // registeredID |
|
| 105 | + case self::TAG_REGISTERED_ID: |
|
| 106 | + return RegisteredID::fromChosenASN1( |
|
| 107 | + $el->asImplicit(Element::TYPE_OBJECT_IDENTIFIER)); |
|
| 108 | + } |
|
| 109 | + throw new \UnexpectedValueException( |
|
| 110 | + "GeneralName type " . $el->tag() . " not supported."); |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - /** |
|
| 114 | - * Get type tag. |
|
| 115 | - * |
|
| 116 | - * @return int |
|
| 117 | - */ |
|
| 118 | - public function tag() |
|
| 119 | - { |
|
| 120 | - return $this->_tag; |
|
| 121 | - } |
|
| 113 | + /** |
|
| 114 | + * Get type tag. |
|
| 115 | + * |
|
| 116 | + * @return int |
|
| 117 | + */ |
|
| 118 | + public function tag() |
|
| 119 | + { |
|
| 120 | + return $this->_tag; |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | - /** |
|
| 124 | - * Generate ASN.1 element. |
|
| 125 | - * |
|
| 126 | - * @return Element |
|
| 127 | - */ |
|
| 128 | - public function toASN1() |
|
| 129 | - { |
|
| 130 | - return $this->_choiceASN1(); |
|
| 131 | - } |
|
| 123 | + /** |
|
| 124 | + * Generate ASN.1 element. |
|
| 125 | + * |
|
| 126 | + * @return Element |
|
| 127 | + */ |
|
| 128 | + public function toASN1() |
|
| 129 | + { |
|
| 130 | + return $this->_choiceASN1(); |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - /** |
|
| 134 | - * Check whether GeneralName is equal to other. |
|
| 135 | - * |
|
| 136 | - * @param GeneralName $other GeneralName to compare to |
|
| 137 | - * @return boolean True if names are equal |
|
| 138 | - */ |
|
| 139 | - public function equals(GeneralName $other) |
|
| 140 | - { |
|
| 141 | - if ($this->_tag != $other->_tag) { |
|
| 142 | - return false; |
|
| 143 | - } |
|
| 144 | - if ($this->_choiceASN1()->toDER() != $other->_choiceASN1()->toDER()) { |
|
| 145 | - return false; |
|
| 146 | - } |
|
| 147 | - return true; |
|
| 148 | - } |
|
| 133 | + /** |
|
| 134 | + * Check whether GeneralName is equal to other. |
|
| 135 | + * |
|
| 136 | + * @param GeneralName $other GeneralName to compare to |
|
| 137 | + * @return boolean True if names are equal |
|
| 138 | + */ |
|
| 139 | + public function equals(GeneralName $other) |
|
| 140 | + { |
|
| 141 | + if ($this->_tag != $other->_tag) { |
|
| 142 | + return false; |
|
| 143 | + } |
|
| 144 | + if ($this->_choiceASN1()->toDER() != $other->_choiceASN1()->toDER()) { |
|
| 145 | + return false; |
|
| 146 | + } |
|
| 147 | + return true; |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - /** |
|
| 151 | - * Get general name as a string. |
|
| 152 | - * |
|
| 153 | - * @return string |
|
| 154 | - */ |
|
| 155 | - public function __toString() |
|
| 156 | - { |
|
| 157 | - return $this->string(); |
|
| 158 | - } |
|
| 150 | + /** |
|
| 151 | + * Get general name as a string. |
|
| 152 | + * |
|
| 153 | + * @return string |
|
| 154 | + */ |
|
| 155 | + public function __toString() |
|
| 156 | + { |
|
| 157 | + return $this->string(); |
|
| 158 | + } |
|
| 159 | 159 | } |
@@ -68,43 +68,43 @@ |
||
| 68 | 68 | { |
| 69 | 69 | switch ($el->tag()) { |
| 70 | 70 | // otherName |
| 71 | - case self::TAG_OTHER_NAME: |
|
| 72 | - return OtherName::fromChosenASN1( |
|
| 73 | - $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
| 74 | - // rfc822Name |
|
| 75 | - case self::TAG_RFC822_NAME: |
|
| 76 | - return RFC822Name::fromChosenASN1( |
|
| 77 | - $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
| 78 | - // dNSName |
|
| 79 | - case self::TAG_DNS_NAME: |
|
| 80 | - return DNSName::fromChosenASN1( |
|
| 81 | - $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
| 82 | - // x400Address |
|
| 83 | - case self::TAG_X400_ADDRESS: |
|
| 84 | - return X400Address::fromChosenASN1( |
|
| 85 | - $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
| 86 | - // directoryName |
|
| 87 | - case self::TAG_DIRECTORY_NAME: |
|
| 88 | - // because Name is a CHOICE, albeit having only one option, |
|
| 89 | - // explicit tagging must be used |
|
| 90 | - // (see X.680 07/2002 30.6.c) |
|
| 91 | - return DirectoryName::fromChosenASN1($el->asExplicit()); |
|
| 92 | - // ediPartyName |
|
| 93 | - case self::TAG_EDI_PARTY_NAME: |
|
| 94 | - return EDIPartyName::fromChosenASN1( |
|
| 95 | - $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
| 96 | - // uniformResourceIdentifier |
|
| 97 | - case self::TAG_URI: |
|
| 98 | - return UniformResourceIdentifier::fromChosenASN1( |
|
| 99 | - $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
| 100 | - // iPAddress |
|
| 101 | - case self::TAG_IP_ADDRESS: |
|
| 102 | - return IPAddress::fromChosenASN1( |
|
| 103 | - $el->asImplicit(Element::TYPE_OCTET_STRING)); |
|
| 104 | - // registeredID |
|
| 105 | - case self::TAG_REGISTERED_ID: |
|
| 106 | - return RegisteredID::fromChosenASN1( |
|
| 107 | - $el->asImplicit(Element::TYPE_OBJECT_IDENTIFIER)); |
|
| 71 | + case self::TAG_OTHER_NAME: |
|
| 72 | + return OtherName::fromChosenASN1( |
|
| 73 | + $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
| 74 | + // rfc822Name |
|
| 75 | + case self::TAG_RFC822_NAME: |
|
| 76 | + return RFC822Name::fromChosenASN1( |
|
| 77 | + $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
| 78 | + // dNSName |
|
| 79 | + case self::TAG_DNS_NAME: |
|
| 80 | + return DNSName::fromChosenASN1( |
|
| 81 | + $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
| 82 | + // x400Address |
|
| 83 | + case self::TAG_X400_ADDRESS: |
|
| 84 | + return X400Address::fromChosenASN1( |
|
| 85 | + $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
| 86 | + // directoryName |
|
| 87 | + case self::TAG_DIRECTORY_NAME: |
|
| 88 | + // because Name is a CHOICE, albeit having only one option, |
|
| 89 | + // explicit tagging must be used |
|
| 90 | + // (see X.680 07/2002 30.6.c) |
|
| 91 | + return DirectoryName::fromChosenASN1($el->asExplicit()); |
|
| 92 | + // ediPartyName |
|
| 93 | + case self::TAG_EDI_PARTY_NAME: |
|
| 94 | + return EDIPartyName::fromChosenASN1( |
|
| 95 | + $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
| 96 | + // uniformResourceIdentifier |
|
| 97 | + case self::TAG_URI: |
|
| 98 | + return UniformResourceIdentifier::fromChosenASN1( |
|
| 99 | + $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
| 100 | + // iPAddress |
|
| 101 | + case self::TAG_IP_ADDRESS: |
|
| 102 | + return IPAddress::fromChosenASN1( |
|
| 103 | + $el->asImplicit(Element::TYPE_OCTET_STRING)); |
|
| 104 | + // registeredID |
|
| 105 | + case self::TAG_REGISTERED_ID: |
|
| 106 | + return RegisteredID::fromChosenASN1( |
|
| 107 | + $el->asImplicit(Element::TYPE_OBJECT_IDENTIFIER)); |
|
| 108 | 108 | } |
| 109 | 109 | throw new \UnexpectedValueException( |
| 110 | 110 | "GeneralName type " . $el->tag() . " not supported."); |
@@ -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 | |
@@ -16,91 +16,91 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class GeneralSubtree |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * Constraint. |
|
| 21 | - * |
|
| 22 | - * @var GeneralName |
|
| 23 | - */ |
|
| 24 | - protected $_base; |
|
| 19 | + /** |
|
| 20 | + * Constraint. |
|
| 21 | + * |
|
| 22 | + * @var GeneralName |
|
| 23 | + */ |
|
| 24 | + protected $_base; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Not used, must be zero. |
|
| 28 | - * |
|
| 29 | - * @var int $_min |
|
| 30 | - */ |
|
| 31 | - protected $_min; |
|
| 26 | + /** |
|
| 27 | + * Not used, must be zero. |
|
| 28 | + * |
|
| 29 | + * @var int $_min |
|
| 30 | + */ |
|
| 31 | + protected $_min; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Not used, must be null. |
|
| 35 | - * |
|
| 36 | - * @var int|null $_max |
|
| 37 | - */ |
|
| 38 | - protected $_max; |
|
| 33 | + /** |
|
| 34 | + * Not used, must be null. |
|
| 35 | + * |
|
| 36 | + * @var int|null $_max |
|
| 37 | + */ |
|
| 38 | + protected $_max; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Constructor. |
|
| 42 | - * |
|
| 43 | - * @param GeneralName $base |
|
| 44 | - * @param int $min |
|
| 45 | - * @param int|null $max |
|
| 46 | - */ |
|
| 47 | - public function __construct(GeneralName $base, $min = 0, $max = null) |
|
| 48 | - { |
|
| 49 | - $this->_base = $base; |
|
| 50 | - $this->_min = $min; |
|
| 51 | - $this->_max = $max; |
|
| 52 | - } |
|
| 40 | + /** |
|
| 41 | + * Constructor. |
|
| 42 | + * |
|
| 43 | + * @param GeneralName $base |
|
| 44 | + * @param int $min |
|
| 45 | + * @param int|null $max |
|
| 46 | + */ |
|
| 47 | + public function __construct(GeneralName $base, $min = 0, $max = null) |
|
| 48 | + { |
|
| 49 | + $this->_base = $base; |
|
| 50 | + $this->_min = $min; |
|
| 51 | + $this->_max = $max; |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Initialize from ASN.1. |
|
| 56 | - * |
|
| 57 | - * @param Sequence $seq |
|
| 58 | - * @return self |
|
| 59 | - */ |
|
| 60 | - public static function fromASN1(Sequence $seq) |
|
| 61 | - { |
|
| 62 | - $base = GeneralName::fromASN1($seq->at(0)->asTagged()); |
|
| 63 | - $min = 0; |
|
| 64 | - $max = null; |
|
| 65 | - if ($seq->hasTagged(0)) { |
|
| 66 | - $min = $seq->getTagged(0) |
|
| 67 | - ->asImplicit(Element::TYPE_INTEGER) |
|
| 68 | - ->asInteger() |
|
| 69 | - ->number(); |
|
| 70 | - } |
|
| 71 | - if ($seq->hasTagged(1)) { |
|
| 72 | - $max = $seq->getTagged(1) |
|
| 73 | - ->asImplicit(Element::TYPE_INTEGER) |
|
| 74 | - ->asInteger() |
|
| 75 | - ->number(); |
|
| 76 | - } |
|
| 77 | - return new self($base, $min, $max); |
|
| 78 | - } |
|
| 54 | + /** |
|
| 55 | + * Initialize from ASN.1. |
|
| 56 | + * |
|
| 57 | + * @param Sequence $seq |
|
| 58 | + * @return self |
|
| 59 | + */ |
|
| 60 | + public static function fromASN1(Sequence $seq) |
|
| 61 | + { |
|
| 62 | + $base = GeneralName::fromASN1($seq->at(0)->asTagged()); |
|
| 63 | + $min = 0; |
|
| 64 | + $max = null; |
|
| 65 | + if ($seq->hasTagged(0)) { |
|
| 66 | + $min = $seq->getTagged(0) |
|
| 67 | + ->asImplicit(Element::TYPE_INTEGER) |
|
| 68 | + ->asInteger() |
|
| 69 | + ->number(); |
|
| 70 | + } |
|
| 71 | + if ($seq->hasTagged(1)) { |
|
| 72 | + $max = $seq->getTagged(1) |
|
| 73 | + ->asImplicit(Element::TYPE_INTEGER) |
|
| 74 | + ->asInteger() |
|
| 75 | + ->number(); |
|
| 76 | + } |
|
| 77 | + return new self($base, $min, $max); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * Get constraint. |
|
| 82 | - * |
|
| 83 | - * @return GeneralName |
|
| 84 | - */ |
|
| 85 | - public function base() |
|
| 86 | - { |
|
| 87 | - return $this->_base; |
|
| 88 | - } |
|
| 80 | + /** |
|
| 81 | + * Get constraint. |
|
| 82 | + * |
|
| 83 | + * @return GeneralName |
|
| 84 | + */ |
|
| 85 | + public function base() |
|
| 86 | + { |
|
| 87 | + return $this->_base; |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * Generate ASN.1 structure. |
|
| 92 | - * |
|
| 93 | - * @return Sequence |
|
| 94 | - */ |
|
| 95 | - public function toASN1() |
|
| 96 | - { |
|
| 97 | - $elements = array($this->_base->toASN1()); |
|
| 98 | - if (isset($this->_min) && $this->_min != 0) { |
|
| 99 | - $elements[] = new ImplicitlyTaggedType(0, new Integer($this->_min)); |
|
| 100 | - } |
|
| 101 | - if (isset($this->_max)) { |
|
| 102 | - $elements[] = new ImplicitlyTaggedType(1, new Integer($this->_max)); |
|
| 103 | - } |
|
| 104 | - return new Sequence(...$elements); |
|
| 105 | - } |
|
| 90 | + /** |
|
| 91 | + * Generate ASN.1 structure. |
|
| 92 | + * |
|
| 93 | + * @return Sequence |
|
| 94 | + */ |
|
| 95 | + public function toASN1() |
|
| 96 | + { |
|
| 97 | + $elements = array($this->_base->toASN1()); |
|
| 98 | + if (isset($this->_min) && $this->_min != 0) { |
|
| 99 | + $elements[] = new ImplicitlyTaggedType(0, new Integer($this->_min)); |
|
| 100 | + } |
|
| 101 | + if (isset($this->_max)) { |
|
| 102 | + $elements[] = new ImplicitlyTaggedType(1, new Integer($this->_max)); |
|
| 103 | + } |
|
| 104 | + return new Sequence(...$elements); |
|
| 105 | + } |
|
| 106 | 106 | } |
@@ -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\Certificate\Extension\NameConstraints; |
| 6 | 6 | |
@@ -43,16 +43,16 @@ |
||
| 43 | 43 | public static function fromTaggedType(TaggedType $el) |
| 44 | 44 | { |
| 45 | 45 | switch ($el->tag()) { |
| 46 | - case self::TAG_FULL_NAME: |
|
| 47 | - return new FullName( |
|
| 48 | - GeneralNames::fromASN1( |
|
| 49 | - $el->asImplicit(Element::TYPE_SEQUENCE)->asSequence())); |
|
| 50 | - case self::TAG_RDN: |
|
| 51 | - return new RelativeName( |
|
| 52 | - RDN::fromASN1($el->asImplicit(Element::TYPE_SET)->asSet())); |
|
| 53 | - default: |
|
| 54 | - throw new \UnexpectedValueException( |
|
| 55 | - "DistributionPointName tag " . $el->tag() . " not supported."); |
|
| 46 | + case self::TAG_FULL_NAME: |
|
| 47 | + return new FullName( |
|
| 48 | + GeneralNames::fromASN1( |
|
| 49 | + $el->asImplicit(Element::TYPE_SEQUENCE)->asSequence())); |
|
| 50 | + case self::TAG_RDN: |
|
| 51 | + return new RelativeName( |
|
| 52 | + RDN::fromASN1($el->asImplicit(Element::TYPE_SET)->asSet())); |
|
| 53 | + default: |
|
| 54 | + throw new \UnexpectedValueException( |
|
| 55 | + "DistributionPointName tag " . $el->tag() . " not supported."); |
|
| 56 | 56 | } |
| 57 | 57 | } |
| 58 | 58 | |
@@ -18,64 +18,64 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | abstract class DistributionPointName |
| 20 | 20 | { |
| 21 | - const TAG_FULL_NAME = 0; |
|
| 22 | - const TAG_RDN = 1; |
|
| 21 | + const TAG_FULL_NAME = 0; |
|
| 22 | + const TAG_RDN = 1; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Type. |
|
| 26 | - * |
|
| 27 | - * @var int $_tag |
|
| 28 | - */ |
|
| 29 | - protected $_tag; |
|
| 24 | + /** |
|
| 25 | + * Type. |
|
| 26 | + * |
|
| 27 | + * @var int $_tag |
|
| 28 | + */ |
|
| 29 | + protected $_tag; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Generate ASN.1 element. |
|
| 33 | - * |
|
| 34 | - * @return Element |
|
| 35 | - */ |
|
| 36 | - abstract protected function _valueASN1(); |
|
| 31 | + /** |
|
| 32 | + * Generate ASN.1 element. |
|
| 33 | + * |
|
| 34 | + * @return Element |
|
| 35 | + */ |
|
| 36 | + abstract protected function _valueASN1(); |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Initialize from TaggedType. |
|
| 40 | - * |
|
| 41 | - * @param TaggedType $el |
|
| 42 | - * @throws \UnexpectedValueException |
|
| 43 | - * @return self |
|
| 44 | - */ |
|
| 45 | - public static function fromTaggedType(TaggedType $el) |
|
| 46 | - { |
|
| 47 | - switch ($el->tag()) { |
|
| 48 | - case self::TAG_FULL_NAME: |
|
| 49 | - return new FullName( |
|
| 50 | - GeneralNames::fromASN1( |
|
| 51 | - $el->asImplicit(Element::TYPE_SEQUENCE)->asSequence())); |
|
| 52 | - case self::TAG_RDN: |
|
| 53 | - return new RelativeName( |
|
| 54 | - RDN::fromASN1($el->asImplicit(Element::TYPE_SET)->asSet())); |
|
| 55 | - default: |
|
| 56 | - throw new \UnexpectedValueException( |
|
| 57 | - "DistributionPointName tag " . $el->tag() . " not supported."); |
|
| 58 | - } |
|
| 59 | - } |
|
| 38 | + /** |
|
| 39 | + * Initialize from TaggedType. |
|
| 40 | + * |
|
| 41 | + * @param TaggedType $el |
|
| 42 | + * @throws \UnexpectedValueException |
|
| 43 | + * @return self |
|
| 44 | + */ |
|
| 45 | + public static function fromTaggedType(TaggedType $el) |
|
| 46 | + { |
|
| 47 | + switch ($el->tag()) { |
|
| 48 | + case self::TAG_FULL_NAME: |
|
| 49 | + return new FullName( |
|
| 50 | + GeneralNames::fromASN1( |
|
| 51 | + $el->asImplicit(Element::TYPE_SEQUENCE)->asSequence())); |
|
| 52 | + case self::TAG_RDN: |
|
| 53 | + return new RelativeName( |
|
| 54 | + RDN::fromASN1($el->asImplicit(Element::TYPE_SET)->asSet())); |
|
| 55 | + default: |
|
| 56 | + throw new \UnexpectedValueException( |
|
| 57 | + "DistributionPointName tag " . $el->tag() . " not supported."); |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Get type tag. |
|
| 63 | - * |
|
| 64 | - * @return int |
|
| 65 | - */ |
|
| 66 | - public function tag() |
|
| 67 | - { |
|
| 68 | - return $this->_tag; |
|
| 69 | - } |
|
| 61 | + /** |
|
| 62 | + * Get type tag. |
|
| 63 | + * |
|
| 64 | + * @return int |
|
| 65 | + */ |
|
| 66 | + public function tag() |
|
| 67 | + { |
|
| 68 | + return $this->_tag; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Generate ASN.1 structure. |
|
| 73 | - * |
|
| 74 | - * @return ImplicitlyTaggedType |
|
| 75 | - */ |
|
| 76 | - public function toASN1(): ImplicitlyTaggedType |
|
| 77 | - { |
|
| 78 | - $element = $this->_valueASN1(); |
|
| 79 | - return new ImplicitlyTaggedType($this->_tag, $element); |
|
| 80 | - } |
|
| 71 | + /** |
|
| 72 | + * Generate ASN.1 structure. |
|
| 73 | + * |
|
| 74 | + * @return ImplicitlyTaggedType |
|
| 75 | + */ |
|
| 76 | + public function toASN1(): ImplicitlyTaggedType |
|
| 77 | + { |
|
| 78 | + $element = $this->_valueASN1(); |
|
| 79 | + return new ImplicitlyTaggedType($this->_tag, $element); |
|
| 80 | + } |
|
| 81 | 81 | } |
@@ -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\Certificate\Extension\DistributionPoint; |
| 6 | 6 | |
@@ -14,114 +14,114 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class UserNoticeQualifier extends PolicyQualifierInfo |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * Explicit notice text. |
|
| 19 | - * |
|
| 20 | - * @var DisplayText $_text |
|
| 21 | - */ |
|
| 22 | - protected $_text; |
|
| 17 | + /** |
|
| 18 | + * Explicit notice text. |
|
| 19 | + * |
|
| 20 | + * @var DisplayText $_text |
|
| 21 | + */ |
|
| 22 | + protected $_text; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Notice reference. |
|
| 26 | - * |
|
| 27 | - * @var NoticeReference $_ref |
|
| 28 | - */ |
|
| 29 | - protected $_ref; |
|
| 24 | + /** |
|
| 25 | + * Notice reference. |
|
| 26 | + * |
|
| 27 | + * @var NoticeReference $_ref |
|
| 28 | + */ |
|
| 29 | + protected $_ref; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Constructor. |
|
| 33 | - * |
|
| 34 | - * @param DisplayText|null $text |
|
| 35 | - * @param NoticeReference|null $ref |
|
| 36 | - */ |
|
| 37 | - public function __construct(DisplayText $text = null, NoticeReference $ref = null) |
|
| 38 | - { |
|
| 39 | - $this->_oid = self::OID_UNOTICE; |
|
| 40 | - $this->_text = $text; |
|
| 41 | - $this->_ref = $ref; |
|
| 42 | - } |
|
| 31 | + /** |
|
| 32 | + * Constructor. |
|
| 33 | + * |
|
| 34 | + * @param DisplayText|null $text |
|
| 35 | + * @param NoticeReference|null $ref |
|
| 36 | + */ |
|
| 37 | + public function __construct(DisplayText $text = null, NoticeReference $ref = null) |
|
| 38 | + { |
|
| 39 | + $this->_oid = self::OID_UNOTICE; |
|
| 40 | + $this->_text = $text; |
|
| 41 | + $this->_ref = $ref; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * |
|
| 46 | - * @param UnspecifiedType $el |
|
| 47 | - * @return self |
|
| 48 | - */ |
|
| 49 | - public static function fromQualifierASN1(UnspecifiedType $el) |
|
| 50 | - { |
|
| 51 | - $seq = $el->asSequence(); |
|
| 52 | - $ref = null; |
|
| 53 | - $text = null; |
|
| 54 | - $idx = 0; |
|
| 55 | - if ($seq->has($idx, Element::TYPE_SEQUENCE)) { |
|
| 56 | - $ref = NoticeReference::fromASN1($seq->at($idx++)->asSequence()); |
|
| 57 | - } |
|
| 58 | - if ($seq->has($idx, Element::TYPE_STRING)) { |
|
| 59 | - $text = DisplayText::fromASN1($seq->at($idx)->asString()); |
|
| 60 | - } |
|
| 61 | - return new self($text, $ref); |
|
| 62 | - } |
|
| 44 | + /** |
|
| 45 | + * |
|
| 46 | + * @param UnspecifiedType $el |
|
| 47 | + * @return self |
|
| 48 | + */ |
|
| 49 | + public static function fromQualifierASN1(UnspecifiedType $el) |
|
| 50 | + { |
|
| 51 | + $seq = $el->asSequence(); |
|
| 52 | + $ref = null; |
|
| 53 | + $text = null; |
|
| 54 | + $idx = 0; |
|
| 55 | + if ($seq->has($idx, Element::TYPE_SEQUENCE)) { |
|
| 56 | + $ref = NoticeReference::fromASN1($seq->at($idx++)->asSequence()); |
|
| 57 | + } |
|
| 58 | + if ($seq->has($idx, Element::TYPE_STRING)) { |
|
| 59 | + $text = DisplayText::fromASN1($seq->at($idx)->asString()); |
|
| 60 | + } |
|
| 61 | + return new self($text, $ref); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * Whether explicit text is present. |
|
| 66 | - * |
|
| 67 | - * @return bool |
|
| 68 | - */ |
|
| 69 | - public function hasExplicitText() |
|
| 70 | - { |
|
| 71 | - return isset($this->_text); |
|
| 72 | - } |
|
| 64 | + /** |
|
| 65 | + * Whether explicit text is present. |
|
| 66 | + * |
|
| 67 | + * @return bool |
|
| 68 | + */ |
|
| 69 | + public function hasExplicitText() |
|
| 70 | + { |
|
| 71 | + return isset($this->_text); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * Get explicit text. |
|
| 76 | - * |
|
| 77 | - * @return DisplayText |
|
| 78 | - */ |
|
| 79 | - public function explicitText() |
|
| 80 | - { |
|
| 81 | - if (!$this->hasExplicitText()) { |
|
| 82 | - throw new \LogicException("explicitText not set."); |
|
| 83 | - } |
|
| 84 | - return $this->_text; |
|
| 85 | - } |
|
| 74 | + /** |
|
| 75 | + * Get explicit text. |
|
| 76 | + * |
|
| 77 | + * @return DisplayText |
|
| 78 | + */ |
|
| 79 | + public function explicitText() |
|
| 80 | + { |
|
| 81 | + if (!$this->hasExplicitText()) { |
|
| 82 | + throw new \LogicException("explicitText not set."); |
|
| 83 | + } |
|
| 84 | + return $this->_text; |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * Whether notice reference is present. |
|
| 89 | - * |
|
| 90 | - * @return bool |
|
| 91 | - */ |
|
| 92 | - public function hasNoticeRef() |
|
| 93 | - { |
|
| 94 | - return isset($this->_ref); |
|
| 95 | - } |
|
| 87 | + /** |
|
| 88 | + * Whether notice reference is present. |
|
| 89 | + * |
|
| 90 | + * @return bool |
|
| 91 | + */ |
|
| 92 | + public function hasNoticeRef() |
|
| 93 | + { |
|
| 94 | + return isset($this->_ref); |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * Get notice reference. |
|
| 99 | - * |
|
| 100 | - * @throws \RuntimeException |
|
| 101 | - * @return NoticeReference |
|
| 102 | - */ |
|
| 103 | - public function noticeRef() |
|
| 104 | - { |
|
| 105 | - if (!$this->hasNoticeRef()) { |
|
| 106 | - throw new \LogicException("noticeRef not set."); |
|
| 107 | - } |
|
| 108 | - return $this->_ref; |
|
| 109 | - } |
|
| 97 | + /** |
|
| 98 | + * Get notice reference. |
|
| 99 | + * |
|
| 100 | + * @throws \RuntimeException |
|
| 101 | + * @return NoticeReference |
|
| 102 | + */ |
|
| 103 | + public function noticeRef() |
|
| 104 | + { |
|
| 105 | + if (!$this->hasNoticeRef()) { |
|
| 106 | + throw new \LogicException("noticeRef not set."); |
|
| 107 | + } |
|
| 108 | + return $this->_ref; |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * |
|
| 113 | - * {@inheritdoc} |
|
| 114 | - * @return Sequence |
|
| 115 | - */ |
|
| 116 | - protected function _qualifierASN1() |
|
| 117 | - { |
|
| 118 | - $elements = array(); |
|
| 119 | - if (isset($this->_ref)) { |
|
| 120 | - $elements[] = $this->_ref->toASN1(); |
|
| 121 | - } |
|
| 122 | - if (isset($this->_text)) { |
|
| 123 | - $elements[] = $this->_text->toASN1(); |
|
| 124 | - } |
|
| 125 | - return new Sequence(...$elements); |
|
| 126 | - } |
|
| 111 | + /** |
|
| 112 | + * |
|
| 113 | + * {@inheritdoc} |
|
| 114 | + * @return Sequence |
|
| 115 | + */ |
|
| 116 | + protected function _qualifierASN1() |
|
| 117 | + { |
|
| 118 | + $elements = array(); |
|
| 119 | + if (isset($this->_ref)) { |
|
| 120 | + $elements[] = $this->_ref->toASN1(); |
|
| 121 | + } |
|
| 122 | + if (isset($this->_text)) { |
|
| 123 | + $elements[] = $this->_text->toASN1(); |
|
| 124 | + } |
|
| 125 | + return new Sequence(...$elements); |
|
| 126 | + } |
|
| 127 | 127 | } |
@@ -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\Certificate\Extension\CertificatePolicy; |
| 6 | 6 | |
@@ -17,93 +17,93 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class DisplayText |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * Text. |
|
| 22 | - * |
|
| 23 | - * @var string $_text |
|
| 24 | - */ |
|
| 25 | - protected $_text; |
|
| 20 | + /** |
|
| 21 | + * Text. |
|
| 22 | + * |
|
| 23 | + * @var string $_text |
|
| 24 | + */ |
|
| 25 | + protected $_text; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Element tag. |
|
| 29 | - * |
|
| 30 | - * @var int $_tag |
|
| 31 | - */ |
|
| 32 | - protected $_tag; |
|
| 27 | + /** |
|
| 28 | + * Element tag. |
|
| 29 | + * |
|
| 30 | + * @var int $_tag |
|
| 31 | + */ |
|
| 32 | + protected $_tag; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Constructor. |
|
| 36 | - * |
|
| 37 | - * @param string $text |
|
| 38 | - * @param int $tag |
|
| 39 | - */ |
|
| 40 | - public function __construct($text, $tag) |
|
| 41 | - { |
|
| 42 | - $this->_text = $text; |
|
| 43 | - $this->_tag = $tag; |
|
| 44 | - } |
|
| 34 | + /** |
|
| 35 | + * Constructor. |
|
| 36 | + * |
|
| 37 | + * @param string $text |
|
| 38 | + * @param int $tag |
|
| 39 | + */ |
|
| 40 | + public function __construct($text, $tag) |
|
| 41 | + { |
|
| 42 | + $this->_text = $text; |
|
| 43 | + $this->_tag = $tag; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Initialize from ASN.1. |
|
| 48 | - * |
|
| 49 | - * @param StringType $el |
|
| 50 | - * @return self |
|
| 51 | - */ |
|
| 52 | - public static function fromASN1(StringType $el) |
|
| 53 | - { |
|
| 54 | - return new self($el->string(), $el->tag()); |
|
| 55 | - } |
|
| 46 | + /** |
|
| 47 | + * Initialize from ASN.1. |
|
| 48 | + * |
|
| 49 | + * @param StringType $el |
|
| 50 | + * @return self |
|
| 51 | + */ |
|
| 52 | + public static function fromASN1(StringType $el) |
|
| 53 | + { |
|
| 54 | + return new self($el->string(), $el->tag()); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Initialize from a UTF-8 string. |
|
| 59 | - * |
|
| 60 | - * @param string $str |
|
| 61 | - * @return self |
|
| 62 | - */ |
|
| 63 | - public static function fromString($str) |
|
| 64 | - { |
|
| 65 | - return new self($str, Element::TYPE_UTF8_STRING); |
|
| 66 | - } |
|
| 57 | + /** |
|
| 58 | + * Initialize from a UTF-8 string. |
|
| 59 | + * |
|
| 60 | + * @param string $str |
|
| 61 | + * @return self |
|
| 62 | + */ |
|
| 63 | + public static function fromString($str) |
|
| 64 | + { |
|
| 65 | + return new self($str, Element::TYPE_UTF8_STRING); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * Get the text. |
|
| 70 | - * |
|
| 71 | - * @return string |
|
| 72 | - */ |
|
| 73 | - public function string() |
|
| 74 | - { |
|
| 75 | - return $this->_text; |
|
| 76 | - } |
|
| 68 | + /** |
|
| 69 | + * Get the text. |
|
| 70 | + * |
|
| 71 | + * @return string |
|
| 72 | + */ |
|
| 73 | + public function string() |
|
| 74 | + { |
|
| 75 | + return $this->_text; |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Generate ASN.1 element. |
|
| 80 | - * |
|
| 81 | - * @throws \UnexpectedValueException |
|
| 82 | - * @return StringType |
|
| 83 | - */ |
|
| 84 | - public function toASN1() |
|
| 85 | - { |
|
| 86 | - switch ($this->_tag) { |
|
| 87 | - case Element::TYPE_IA5_STRING: |
|
| 88 | - return new IA5String($this->_text); |
|
| 89 | - case Element::TYPE_VISIBLE_STRING: |
|
| 90 | - return new VisibleString($this->_text); |
|
| 91 | - case Element::TYPE_BMP_STRING: |
|
| 92 | - return new BMPString($this->_text); |
|
| 93 | - case Element::TYPE_UTF8_STRING: |
|
| 94 | - return new UTF8String($this->_text); |
|
| 95 | - default: |
|
| 96 | - throw new \UnexpectedValueException( |
|
| 97 | - "Type " . Element::tagToName($this->_tag) . " not supported."); |
|
| 98 | - } |
|
| 99 | - } |
|
| 78 | + /** |
|
| 79 | + * Generate ASN.1 element. |
|
| 80 | + * |
|
| 81 | + * @throws \UnexpectedValueException |
|
| 82 | + * @return StringType |
|
| 83 | + */ |
|
| 84 | + public function toASN1() |
|
| 85 | + { |
|
| 86 | + switch ($this->_tag) { |
|
| 87 | + case Element::TYPE_IA5_STRING: |
|
| 88 | + return new IA5String($this->_text); |
|
| 89 | + case Element::TYPE_VISIBLE_STRING: |
|
| 90 | + return new VisibleString($this->_text); |
|
| 91 | + case Element::TYPE_BMP_STRING: |
|
| 92 | + return new BMPString($this->_text); |
|
| 93 | + case Element::TYPE_UTF8_STRING: |
|
| 94 | + return new UTF8String($this->_text); |
|
| 95 | + default: |
|
| 96 | + throw new \UnexpectedValueException( |
|
| 97 | + "Type " . Element::tagToName($this->_tag) . " not supported."); |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * |
|
| 103 | - * @return string |
|
| 104 | - */ |
|
| 105 | - public function __toString() |
|
| 106 | - { |
|
| 107 | - return $this->string(); |
|
| 108 | - } |
|
| 101 | + /** |
|
| 102 | + * |
|
| 103 | + * @return string |
|
| 104 | + */ |
|
| 105 | + public function __toString() |
|
| 106 | + { |
|
| 107 | + return $this->string(); |
|
| 108 | + } |
|
| 109 | 109 | } |
@@ -84,17 +84,17 @@ |
||
| 84 | 84 | public function toASN1() |
| 85 | 85 | { |
| 86 | 86 | switch ($this->_tag) { |
| 87 | - case Element::TYPE_IA5_STRING: |
|
| 88 | - return new IA5String($this->_text); |
|
| 89 | - case Element::TYPE_VISIBLE_STRING: |
|
| 90 | - return new VisibleString($this->_text); |
|
| 91 | - case Element::TYPE_BMP_STRING: |
|
| 92 | - return new BMPString($this->_text); |
|
| 93 | - case Element::TYPE_UTF8_STRING: |
|
| 94 | - return new UTF8String($this->_text); |
|
| 95 | - default: |
|
| 96 | - throw new \UnexpectedValueException( |
|
| 97 | - "Type " . Element::tagToName($this->_tag) . " not supported."); |
|
| 87 | + case Element::TYPE_IA5_STRING: |
|
| 88 | + return new IA5String($this->_text); |
|
| 89 | + case Element::TYPE_VISIBLE_STRING: |
|
| 90 | + return new VisibleString($this->_text); |
|
| 91 | + case Element::TYPE_BMP_STRING: |
|
| 92 | + return new BMPString($this->_text); |
|
| 93 | + case Element::TYPE_UTF8_STRING: |
|
| 94 | + return new UTF8String($this->_text); |
|
| 95 | + default: |
|
| 96 | + throw new \UnexpectedValueException( |
|
| 97 | + "Type " . Element::tagToName($this->_tag) . " not supported."); |
|
| 98 | 98 | } |
| 99 | 99 | } |
| 100 | 100 | |