@@ -17,144 +17,144 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class V2Form extends AttCertIssuer |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * Issuer name. |
|
| 22 | - * |
|
| 23 | - * @var GeneralNames $_issuerName |
|
| 24 | - */ |
|
| 25 | - protected $_issuerName; |
|
| 20 | + /** |
|
| 21 | + * Issuer name. |
|
| 22 | + * |
|
| 23 | + * @var GeneralNames $_issuerName |
|
| 24 | + */ |
|
| 25 | + protected $_issuerName; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Issuer PKC's issuer and serial. |
|
| 29 | - * |
|
| 30 | - * @var IssuerSerial $_baseCertificateID |
|
| 31 | - */ |
|
| 32 | - protected $_baseCertificateID; |
|
| 27 | + /** |
|
| 28 | + * Issuer PKC's issuer and serial. |
|
| 29 | + * |
|
| 30 | + * @var IssuerSerial $_baseCertificateID |
|
| 31 | + */ |
|
| 32 | + protected $_baseCertificateID; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Linked object. |
|
| 36 | - * |
|
| 37 | - * @var ObjectDigestInfo $_objectDigestInfo |
|
| 38 | - */ |
|
| 39 | - protected $_objectDigestInfo; |
|
| 34 | + /** |
|
| 35 | + * Linked object. |
|
| 36 | + * |
|
| 37 | + * @var ObjectDigestInfo $_objectDigestInfo |
|
| 38 | + */ |
|
| 39 | + protected $_objectDigestInfo; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Constructor. |
|
| 43 | - * |
|
| 44 | - * @param GeneralNames|null $names |
|
| 45 | - */ |
|
| 46 | - public function __construct(GeneralNames $names = null) |
|
| 47 | - { |
|
| 48 | - $this->_issuerName = $names; |
|
| 49 | - $this->_baseCertificateID = null; |
|
| 50 | - $this->_objectDigestInfo = null; |
|
| 51 | - } |
|
| 41 | + /** |
|
| 42 | + * Constructor. |
|
| 43 | + * |
|
| 44 | + * @param GeneralNames|null $names |
|
| 45 | + */ |
|
| 46 | + public function __construct(GeneralNames $names = null) |
|
| 47 | + { |
|
| 48 | + $this->_issuerName = $names; |
|
| 49 | + $this->_baseCertificateID = null; |
|
| 50 | + $this->_objectDigestInfo = null; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Initialize from ASN.1. |
|
| 55 | - * |
|
| 56 | - * @param Sequence $seq |
|
| 57 | - * @return self |
|
| 58 | - */ |
|
| 59 | - public static function fromV2ASN1(Sequence $seq) |
|
| 60 | - { |
|
| 61 | - $issuer = null; |
|
| 62 | - $cert_id = null; |
|
| 63 | - $digest_info = null; |
|
| 64 | - if ($seq->has(0, Element::TYPE_SEQUENCE)) { |
|
| 65 | - $issuer = GeneralNames::fromASN1($seq->at(0)->asSequence()); |
|
| 66 | - } |
|
| 67 | - if ($seq->hasTagged(0)) { |
|
| 68 | - $cert_id = IssuerSerial::fromASN1( |
|
| 69 | - $seq->getTagged(0) |
|
| 70 | - ->asImplicit(Element::TYPE_SEQUENCE) |
|
| 71 | - ->asSequence()); |
|
| 72 | - } |
|
| 73 | - if ($seq->hasTagged(1)) { |
|
| 74 | - $digest_info = ObjectDigestInfo::fromASN1( |
|
| 75 | - $seq->getTagged(1) |
|
| 76 | - ->asImplicit(Element::TYPE_SEQUENCE) |
|
| 77 | - ->asSequence()); |
|
| 78 | - } |
|
| 79 | - $obj = new self($issuer); |
|
| 80 | - $obj->_baseCertificateID = $cert_id; |
|
| 81 | - $obj->_objectDigestInfo = $digest_info; |
|
| 82 | - return $obj; |
|
| 83 | - } |
|
| 53 | + /** |
|
| 54 | + * Initialize from ASN.1. |
|
| 55 | + * |
|
| 56 | + * @param Sequence $seq |
|
| 57 | + * @return self |
|
| 58 | + */ |
|
| 59 | + public static function fromV2ASN1(Sequence $seq) |
|
| 60 | + { |
|
| 61 | + $issuer = null; |
|
| 62 | + $cert_id = null; |
|
| 63 | + $digest_info = null; |
|
| 64 | + if ($seq->has(0, Element::TYPE_SEQUENCE)) { |
|
| 65 | + $issuer = GeneralNames::fromASN1($seq->at(0)->asSequence()); |
|
| 66 | + } |
|
| 67 | + if ($seq->hasTagged(0)) { |
|
| 68 | + $cert_id = IssuerSerial::fromASN1( |
|
| 69 | + $seq->getTagged(0) |
|
| 70 | + ->asImplicit(Element::TYPE_SEQUENCE) |
|
| 71 | + ->asSequence()); |
|
| 72 | + } |
|
| 73 | + if ($seq->hasTagged(1)) { |
|
| 74 | + $digest_info = ObjectDigestInfo::fromASN1( |
|
| 75 | + $seq->getTagged(1) |
|
| 76 | + ->asImplicit(Element::TYPE_SEQUENCE) |
|
| 77 | + ->asSequence()); |
|
| 78 | + } |
|
| 79 | + $obj = new self($issuer); |
|
| 80 | + $obj->_baseCertificateID = $cert_id; |
|
| 81 | + $obj->_objectDigestInfo = $digest_info; |
|
| 82 | + return $obj; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * Check whether issuer name is set. |
|
| 87 | - * |
|
| 88 | - * @return bool |
|
| 89 | - */ |
|
| 90 | - public function hasIssuerName(): bool |
|
| 91 | - { |
|
| 92 | - return isset($this->_issuerName); |
|
| 93 | - } |
|
| 85 | + /** |
|
| 86 | + * Check whether issuer name is set. |
|
| 87 | + * |
|
| 88 | + * @return bool |
|
| 89 | + */ |
|
| 90 | + public function hasIssuerName(): bool |
|
| 91 | + { |
|
| 92 | + return isset($this->_issuerName); |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * Get issuer name. |
|
| 97 | - * |
|
| 98 | - * @throws \LogicException |
|
| 99 | - * @return GeneralNames |
|
| 100 | - */ |
|
| 101 | - public function issuerName(): GeneralNames |
|
| 102 | - { |
|
| 103 | - if (!$this->hasIssuerName()) { |
|
| 104 | - throw new \LogicException("issuerName not set."); |
|
| 105 | - } |
|
| 106 | - return $this->_issuerName; |
|
| 107 | - } |
|
| 95 | + /** |
|
| 96 | + * Get issuer name. |
|
| 97 | + * |
|
| 98 | + * @throws \LogicException |
|
| 99 | + * @return GeneralNames |
|
| 100 | + */ |
|
| 101 | + public function issuerName(): GeneralNames |
|
| 102 | + { |
|
| 103 | + if (!$this->hasIssuerName()) { |
|
| 104 | + throw new \LogicException("issuerName not set."); |
|
| 105 | + } |
|
| 106 | + return $this->_issuerName; |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * Get DN of the issuer. |
|
| 111 | - * |
|
| 112 | - * This is a convenience method conforming to RFC 5755, which states |
|
| 113 | - * that Issuer must contain only one non-empty distinguished name. |
|
| 114 | - * |
|
| 115 | - * @return \X501\ASN1\Name |
|
| 116 | - */ |
|
| 117 | - public function name(): \X501\ASN1\Name |
|
| 118 | - { |
|
| 119 | - return $this->issuerName()->firstDN(); |
|
| 120 | - } |
|
| 109 | + /** |
|
| 110 | + * Get DN of the issuer. |
|
| 111 | + * |
|
| 112 | + * This is a convenience method conforming to RFC 5755, which states |
|
| 113 | + * that Issuer must contain only one non-empty distinguished name. |
|
| 114 | + * |
|
| 115 | + * @return \X501\ASN1\Name |
|
| 116 | + */ |
|
| 117 | + public function name(): \X501\ASN1\Name |
|
| 118 | + { |
|
| 119 | + return $this->issuerName()->firstDN(); |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * |
|
| 124 | - * @see \X509\AttributeCertificate\AttCertIssuer::ASN1() |
|
| 125 | - * @return ImplicitlyTaggedType Tagged Sequence |
|
| 126 | - */ |
|
| 127 | - public function toASN1() |
|
| 128 | - { |
|
| 129 | - $elements = array(); |
|
| 130 | - if (isset($this->_issuerName)) { |
|
| 131 | - $elements[] = $this->_issuerName->toASN1(); |
|
| 132 | - } |
|
| 133 | - if (isset($this->_baseCertificateID)) { |
|
| 134 | - $elements[] = new ImplicitlyTaggedType(0, |
|
| 135 | - $this->_baseCertificateID->toASN1()); |
|
| 136 | - } |
|
| 137 | - if (isset($this->_objectDigestInfo)) { |
|
| 138 | - $elements[] = new ImplicitlyTaggedType(1, |
|
| 139 | - $this->_objectDigestInfo->toASN1()); |
|
| 140 | - } |
|
| 141 | - return new ImplicitlyTaggedType(0, new Sequence(...$elements)); |
|
| 142 | - } |
|
| 122 | + /** |
|
| 123 | + * |
|
| 124 | + * @see \X509\AttributeCertificate\AttCertIssuer::ASN1() |
|
| 125 | + * @return ImplicitlyTaggedType Tagged Sequence |
|
| 126 | + */ |
|
| 127 | + public function toASN1() |
|
| 128 | + { |
|
| 129 | + $elements = array(); |
|
| 130 | + if (isset($this->_issuerName)) { |
|
| 131 | + $elements[] = $this->_issuerName->toASN1(); |
|
| 132 | + } |
|
| 133 | + if (isset($this->_baseCertificateID)) { |
|
| 134 | + $elements[] = new ImplicitlyTaggedType(0, |
|
| 135 | + $this->_baseCertificateID->toASN1()); |
|
| 136 | + } |
|
| 137 | + if (isset($this->_objectDigestInfo)) { |
|
| 138 | + $elements[] = new ImplicitlyTaggedType(1, |
|
| 139 | + $this->_objectDigestInfo->toASN1()); |
|
| 140 | + } |
|
| 141 | + return new ImplicitlyTaggedType(0, new Sequence(...$elements)); |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | - /** |
|
| 145 | - * |
|
| 146 | - * {@inheritdoc} |
|
| 147 | - * @see \X509\AttributeCertificate\AttCertIssuer::identifiesPKC() |
|
| 148 | - * @return bool |
|
| 149 | - */ |
|
| 150 | - public function identifiesPKC(Certificate $cert): bool |
|
| 151 | - { |
|
| 152 | - $name = $this->_issuerName->firstDN(); |
|
| 153 | - if (!$cert->tbsCertificate() |
|
| 154 | - ->subject() |
|
| 155 | - ->equals($name)) { |
|
| 156 | - return false; |
|
| 157 | - } |
|
| 158 | - return true; |
|
| 159 | - } |
|
| 144 | + /** |
|
| 145 | + * |
|
| 146 | + * {@inheritdoc} |
|
| 147 | + * @see \X509\AttributeCertificate\AttCertIssuer::identifiesPKC() |
|
| 148 | + * @return bool |
|
| 149 | + */ |
|
| 150 | + public function identifiesPKC(Certificate $cert): bool |
|
| 151 | + { |
|
| 152 | + $name = $this->_issuerName->firstDN(); |
|
| 153 | + if (!$cert->tbsCertificate() |
|
| 154 | + ->subject() |
|
| 155 | + ->equals($name)) { |
|
| 156 | + return false; |
|
| 157 | + } |
|
| 158 | + return true; |
|
| 159 | + } |
|
| 160 | 160 | } |
@@ -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\AttributeCertificate; |
| 6 | 6 | |
@@ -13,131 +13,131 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class CertificateChain implements \Countable, \IteratorAggregate |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * List of certificates in a chain. |
|
| 18 | - * |
|
| 19 | - * @var Certificate[] |
|
| 20 | - */ |
|
| 21 | - protected $_certs; |
|
| 16 | + /** |
|
| 17 | + * List of certificates in a chain. |
|
| 18 | + * |
|
| 19 | + * @var Certificate[] |
|
| 20 | + */ |
|
| 21 | + protected $_certs; |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Constructor. |
|
| 25 | - * |
|
| 26 | - * @param Certificate ...$certs List of certificates, end-entity first |
|
| 27 | - */ |
|
| 28 | - public function __construct(Certificate ...$certs) |
|
| 29 | - { |
|
| 30 | - $this->_certs = $certs; |
|
| 31 | - } |
|
| 23 | + /** |
|
| 24 | + * Constructor. |
|
| 25 | + * |
|
| 26 | + * @param Certificate ...$certs List of certificates, end-entity first |
|
| 27 | + */ |
|
| 28 | + public function __construct(Certificate ...$certs) |
|
| 29 | + { |
|
| 30 | + $this->_certs = $certs; |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Initialize from a list of PEMs. |
|
| 35 | - * |
|
| 36 | - * @param PEM ...$pems |
|
| 37 | - * @return self |
|
| 38 | - */ |
|
| 39 | - public static function fromPEMs(PEM ...$pems) |
|
| 40 | - { |
|
| 41 | - $certs = array_map( |
|
| 42 | - function (PEM $pem) { |
|
| 43 | - return Certificate::fromPEM($pem); |
|
| 44 | - }, $pems); |
|
| 45 | - return new self(...$certs); |
|
| 46 | - } |
|
| 33 | + /** |
|
| 34 | + * Initialize from a list of PEMs. |
|
| 35 | + * |
|
| 36 | + * @param PEM ...$pems |
|
| 37 | + * @return self |
|
| 38 | + */ |
|
| 39 | + public static function fromPEMs(PEM ...$pems) |
|
| 40 | + { |
|
| 41 | + $certs = array_map( |
|
| 42 | + function (PEM $pem) { |
|
| 43 | + return Certificate::fromPEM($pem); |
|
| 44 | + }, $pems); |
|
| 45 | + return new self(...$certs); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Initialize from a string containing multiple PEM blocks. |
|
| 50 | - * |
|
| 51 | - * @param string $str |
|
| 52 | - * @return self |
|
| 53 | - */ |
|
| 54 | - public static function fromPEMString(string $str) |
|
| 55 | - { |
|
| 56 | - $pems = PEMBundle::fromString($str)->all(); |
|
| 57 | - return self::fromPEMs(...$pems); |
|
| 58 | - } |
|
| 48 | + /** |
|
| 49 | + * Initialize from a string containing multiple PEM blocks. |
|
| 50 | + * |
|
| 51 | + * @param string $str |
|
| 52 | + * @return self |
|
| 53 | + */ |
|
| 54 | + public static function fromPEMString(string $str) |
|
| 55 | + { |
|
| 56 | + $pems = PEMBundle::fromString($str)->all(); |
|
| 57 | + return self::fromPEMs(...$pems); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * Get all certificates in a chain ordered from the end-entity certificate |
|
| 62 | - * to the trust anchor. |
|
| 63 | - * |
|
| 64 | - * @return Certificate[] |
|
| 65 | - */ |
|
| 66 | - public function certificates(): array |
|
| 67 | - { |
|
| 68 | - return $this->_certs; |
|
| 69 | - } |
|
| 60 | + /** |
|
| 61 | + * Get all certificates in a chain ordered from the end-entity certificate |
|
| 62 | + * to the trust anchor. |
|
| 63 | + * |
|
| 64 | + * @return Certificate[] |
|
| 65 | + */ |
|
| 66 | + public function certificates(): array |
|
| 67 | + { |
|
| 68 | + return $this->_certs; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Get the end-entity certificate. |
|
| 73 | - * |
|
| 74 | - * @throws \LogicException |
|
| 75 | - * @return Certificate |
|
| 76 | - */ |
|
| 77 | - public function endEntityCertificate(): Certificate |
|
| 78 | - { |
|
| 79 | - if (!count($this->_certs)) { |
|
| 80 | - throw new \LogicException("No certificates."); |
|
| 81 | - } |
|
| 82 | - return $this->_certs[0]; |
|
| 83 | - } |
|
| 71 | + /** |
|
| 72 | + * Get the end-entity certificate. |
|
| 73 | + * |
|
| 74 | + * @throws \LogicException |
|
| 75 | + * @return Certificate |
|
| 76 | + */ |
|
| 77 | + public function endEntityCertificate(): Certificate |
|
| 78 | + { |
|
| 79 | + if (!count($this->_certs)) { |
|
| 80 | + throw new \LogicException("No certificates."); |
|
| 81 | + } |
|
| 82 | + return $this->_certs[0]; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * Get the trust anchor certificate. |
|
| 87 | - * |
|
| 88 | - * @throws \LogicException |
|
| 89 | - * @return Certificate |
|
| 90 | - */ |
|
| 91 | - public function trustAnchorCertificate(): Certificate |
|
| 92 | - { |
|
| 93 | - if (!count($this->_certs)) { |
|
| 94 | - throw new \LogicException("No certificates."); |
|
| 95 | - } |
|
| 96 | - return $this->_certs[count($this->_certs) - 1]; |
|
| 97 | - } |
|
| 85 | + /** |
|
| 86 | + * Get the trust anchor certificate. |
|
| 87 | + * |
|
| 88 | + * @throws \LogicException |
|
| 89 | + * @return Certificate |
|
| 90 | + */ |
|
| 91 | + public function trustAnchorCertificate(): Certificate |
|
| 92 | + { |
|
| 93 | + if (!count($this->_certs)) { |
|
| 94 | + throw new \LogicException("No certificates."); |
|
| 95 | + } |
|
| 96 | + return $this->_certs[count($this->_certs) - 1]; |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * Convert certificate chain to certification path. |
|
| 101 | - * |
|
| 102 | - * @return CertificationPath |
|
| 103 | - */ |
|
| 104 | - public function certificationPath(): CertificationPath |
|
| 105 | - { |
|
| 106 | - return CertificationPath::fromCertificateChain($this); |
|
| 107 | - } |
|
| 99 | + /** |
|
| 100 | + * Convert certificate chain to certification path. |
|
| 101 | + * |
|
| 102 | + * @return CertificationPath |
|
| 103 | + */ |
|
| 104 | + public function certificationPath(): CertificationPath |
|
| 105 | + { |
|
| 106 | + return CertificationPath::fromCertificateChain($this); |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * Convert certificate chain to string of PEM blocks. |
|
| 111 | - * |
|
| 112 | - * @return string |
|
| 113 | - */ |
|
| 114 | - public function toPEMString(): string |
|
| 115 | - { |
|
| 116 | - return implode("\n", |
|
| 117 | - array_map( |
|
| 118 | - function (Certificate $cert) { |
|
| 119 | - return $cert->toPEM()->string(); |
|
| 120 | - }, $this->_certs)); |
|
| 121 | - } |
|
| 109 | + /** |
|
| 110 | + * Convert certificate chain to string of PEM blocks. |
|
| 111 | + * |
|
| 112 | + * @return string |
|
| 113 | + */ |
|
| 114 | + public function toPEMString(): string |
|
| 115 | + { |
|
| 116 | + return implode("\n", |
|
| 117 | + array_map( |
|
| 118 | + function (Certificate $cert) { |
|
| 119 | + return $cert->toPEM()->string(); |
|
| 120 | + }, $this->_certs)); |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | - /** |
|
| 124 | - * |
|
| 125 | - * @see \Countable::count() |
|
| 126 | - * @return int |
|
| 127 | - */ |
|
| 128 | - public function count(): int |
|
| 129 | - { |
|
| 130 | - return count($this->_certs); |
|
| 131 | - } |
|
| 123 | + /** |
|
| 124 | + * |
|
| 125 | + * @see \Countable::count() |
|
| 126 | + * @return int |
|
| 127 | + */ |
|
| 128 | + public function count(): int |
|
| 129 | + { |
|
| 130 | + return count($this->_certs); |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - /** |
|
| 134 | - * Get iterator for certificates. |
|
| 135 | - * |
|
| 136 | - * @see \IteratorAggregate::getIterator() |
|
| 137 | - * @return \ArrayIterator |
|
| 138 | - */ |
|
| 139 | - public function getIterator(): \ArrayIterator |
|
| 140 | - { |
|
| 141 | - return new \ArrayIterator($this->_certs); |
|
| 142 | - } |
|
| 133 | + /** |
|
| 134 | + * Get iterator for certificates. |
|
| 135 | + * |
|
| 136 | + * @see \IteratorAggregate::getIterator() |
|
| 137 | + * @return \ArrayIterator |
|
| 138 | + */ |
|
| 139 | + public function getIterator(): \ArrayIterator |
|
| 140 | + { |
|
| 141 | + return new \ArrayIterator($this->_certs); |
|
| 142 | + } |
|
| 143 | 143 | } |
@@ -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\Certificate; |
| 6 | 6 | |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | public static function fromPEMs(PEM ...$pems) |
| 40 | 40 | { |
| 41 | 41 | $certs = array_map( |
| 42 | - function (PEM $pem) { |
|
| 42 | + function(PEM $pem) { |
|
| 43 | 43 | return Certificate::fromPEM($pem); |
| 44 | 44 | }, $pems); |
| 45 | 45 | return new self(...$certs); |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | { |
| 116 | 116 | return implode("\n", |
| 117 | 117 | array_map( |
| 118 | - function (Certificate $cert) { |
|
| 118 | + function(Certificate $cert) { |
|
| 119 | 119 | return $cert->toPEM()->string(); |
| 120 | 120 | }, $this->_certs)); |
| 121 | 121 | } |
@@ -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 | |
@@ -15,87 +15,87 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class GeneralSubtrees implements \Countable, \IteratorAggregate |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * Subtrees. |
|
| 20 | - * |
|
| 21 | - * @var GeneralSubtree[] $_subtrees |
|
| 22 | - */ |
|
| 23 | - protected $_subtrees; |
|
| 18 | + /** |
|
| 19 | + * Subtrees. |
|
| 20 | + * |
|
| 21 | + * @var GeneralSubtree[] $_subtrees |
|
| 22 | + */ |
|
| 23 | + protected $_subtrees; |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Constructor. |
|
| 27 | - * |
|
| 28 | - * @param GeneralSubtree[] $subtrees |
|
| 29 | - */ |
|
| 30 | - public function __construct(GeneralSubtree ...$subtrees) |
|
| 31 | - { |
|
| 32 | - $this->_subtrees = $subtrees; |
|
| 33 | - } |
|
| 25 | + /** |
|
| 26 | + * Constructor. |
|
| 27 | + * |
|
| 28 | + * @param GeneralSubtree[] $subtrees |
|
| 29 | + */ |
|
| 30 | + public function __construct(GeneralSubtree ...$subtrees) |
|
| 31 | + { |
|
| 32 | + $this->_subtrees = $subtrees; |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Initialize from ASN.1. |
|
| 37 | - * |
|
| 38 | - * @param Sequence $seq |
|
| 39 | - * @return self |
|
| 40 | - */ |
|
| 41 | - public static function fromASN1(Sequence $seq) |
|
| 42 | - { |
|
| 43 | - $subtrees = array_map( |
|
| 44 | - function (UnspecifiedType $el) { |
|
| 45 | - return GeneralSubtree::fromASN1($el->asSequence()); |
|
| 46 | - }, $seq->elements()); |
|
| 47 | - if (!count($subtrees)) { |
|
| 48 | - throw new \UnexpectedValueException( |
|
| 49 | - "GeneralSubtrees must contain at least one GeneralSubtree."); |
|
| 50 | - } |
|
| 51 | - return new self(...$subtrees); |
|
| 52 | - } |
|
| 35 | + /** |
|
| 36 | + * Initialize from ASN.1. |
|
| 37 | + * |
|
| 38 | + * @param Sequence $seq |
|
| 39 | + * @return self |
|
| 40 | + */ |
|
| 41 | + public static function fromASN1(Sequence $seq) |
|
| 42 | + { |
|
| 43 | + $subtrees = array_map( |
|
| 44 | + function (UnspecifiedType $el) { |
|
| 45 | + return GeneralSubtree::fromASN1($el->asSequence()); |
|
| 46 | + }, $seq->elements()); |
|
| 47 | + if (!count($subtrees)) { |
|
| 48 | + throw new \UnexpectedValueException( |
|
| 49 | + "GeneralSubtrees must contain at least one GeneralSubtree."); |
|
| 50 | + } |
|
| 51 | + return new self(...$subtrees); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Get all subtrees. |
|
| 56 | - * |
|
| 57 | - * @return GeneralSubtree[] |
|
| 58 | - */ |
|
| 59 | - public function all(): array |
|
| 60 | - { |
|
| 61 | - return $this->_subtrees; |
|
| 62 | - } |
|
| 54 | + /** |
|
| 55 | + * Get all subtrees. |
|
| 56 | + * |
|
| 57 | + * @return GeneralSubtree[] |
|
| 58 | + */ |
|
| 59 | + public function all(): array |
|
| 60 | + { |
|
| 61 | + return $this->_subtrees; |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * Generate ASN.1 structure. |
|
| 66 | - * |
|
| 67 | - * @return Sequence |
|
| 68 | - */ |
|
| 69 | - public function toASN1(): Sequence |
|
| 70 | - { |
|
| 71 | - if (!count($this->_subtrees)) { |
|
| 72 | - throw new \LogicException("No subtrees."); |
|
| 73 | - } |
|
| 74 | - $elements = array_map( |
|
| 75 | - function (GeneralSubtree $gs) { |
|
| 76 | - return $gs->toASN1(); |
|
| 77 | - }, $this->_subtrees); |
|
| 78 | - return new Sequence(...$elements); |
|
| 79 | - } |
|
| 64 | + /** |
|
| 65 | + * Generate ASN.1 structure. |
|
| 66 | + * |
|
| 67 | + * @return Sequence |
|
| 68 | + */ |
|
| 69 | + public function toASN1(): Sequence |
|
| 70 | + { |
|
| 71 | + if (!count($this->_subtrees)) { |
|
| 72 | + throw new \LogicException("No subtrees."); |
|
| 73 | + } |
|
| 74 | + $elements = array_map( |
|
| 75 | + function (GeneralSubtree $gs) { |
|
| 76 | + return $gs->toASN1(); |
|
| 77 | + }, $this->_subtrees); |
|
| 78 | + return new Sequence(...$elements); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * |
|
| 83 | - * @see \Countable::count() |
|
| 84 | - * @return int |
|
| 85 | - */ |
|
| 86 | - public function count(): int |
|
| 87 | - { |
|
| 88 | - return count($this->_subtrees); |
|
| 89 | - } |
|
| 81 | + /** |
|
| 82 | + * |
|
| 83 | + * @see \Countable::count() |
|
| 84 | + * @return int |
|
| 85 | + */ |
|
| 86 | + public function count(): int |
|
| 87 | + { |
|
| 88 | + return count($this->_subtrees); |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * Get iterator for subtrees. |
|
| 93 | - * |
|
| 94 | - * @see \IteratorAggregate::getIterator() |
|
| 95 | - * @return \ArrayIterator |
|
| 96 | - */ |
|
| 97 | - public function getIterator(): \ArrayIterator |
|
| 98 | - { |
|
| 99 | - return new \ArrayIterator($this->_subtrees); |
|
| 100 | - } |
|
| 91 | + /** |
|
| 92 | + * Get iterator for subtrees. |
|
| 93 | + * |
|
| 94 | + * @see \IteratorAggregate::getIterator() |
|
| 95 | + * @return \ArrayIterator |
|
| 96 | + */ |
|
| 97 | + public function getIterator(): \ArrayIterator |
|
| 98 | + { |
|
| 99 | + return new \ArrayIterator($this->_subtrees); |
|
| 100 | + } |
|
| 101 | 101 | } |
@@ -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\Certificate\Extension\NameConstraints; |
| 6 | 6 | |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | public static function fromASN1(Sequence $seq) |
| 42 | 42 | { |
| 43 | 43 | $subtrees = array_map( |
| 44 | - function (UnspecifiedType $el) { |
|
| 44 | + function(UnspecifiedType $el) { |
|
| 45 | 45 | return GeneralSubtree::fromASN1($el->asSequence()); |
| 46 | 46 | }, $seq->elements()); |
| 47 | 47 | if (!count($subtrees)) { |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | throw new \LogicException("No subtrees."); |
| 73 | 73 | } |
| 74 | 74 | $elements = array_map( |
| 75 | - function (GeneralSubtree $gs) { |
|
| 75 | + function(GeneralSubtree $gs) { |
|
| 76 | 76 | return $gs->toASN1(); |
| 77 | 77 | }, $this->_subtrees); |
| 78 | 78 | return new Sequence(...$elements); |
@@ -16,106 +16,106 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class BasicConstraintsExtension extends Extension |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * Whether certificate is a CA. |
|
| 21 | - * |
|
| 22 | - * @var boolean $_ca |
|
| 23 | - */ |
|
| 24 | - protected $_ca; |
|
| 19 | + /** |
|
| 20 | + * Whether certificate is a CA. |
|
| 21 | + * |
|
| 22 | + * @var boolean $_ca |
|
| 23 | + */ |
|
| 24 | + protected $_ca; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Maximum certification path length. |
|
| 28 | - * |
|
| 29 | - * @var int|null $_pathLen |
|
| 30 | - */ |
|
| 31 | - protected $_pathLen; |
|
| 26 | + /** |
|
| 27 | + * Maximum certification path length. |
|
| 28 | + * |
|
| 29 | + * @var int|null $_pathLen |
|
| 30 | + */ |
|
| 31 | + protected $_pathLen; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Constructor. |
|
| 35 | - * |
|
| 36 | - * @param bool $critical |
|
| 37 | - * @param bool $ca |
|
| 38 | - * @param int|null $path_len |
|
| 39 | - */ |
|
| 40 | - public function __construct(bool $critical, $ca, $path_len = null) |
|
| 41 | - { |
|
| 42 | - parent::__construct(self::OID_BASIC_CONSTRAINTS, $critical); |
|
| 43 | - $this->_ca = (bool) $ca; |
|
| 44 | - $this->_pathLen = $path_len; |
|
| 45 | - } |
|
| 33 | + /** |
|
| 34 | + * Constructor. |
|
| 35 | + * |
|
| 36 | + * @param bool $critical |
|
| 37 | + * @param bool $ca |
|
| 38 | + * @param int|null $path_len |
|
| 39 | + */ |
|
| 40 | + public function __construct(bool $critical, $ca, $path_len = null) |
|
| 41 | + { |
|
| 42 | + parent::__construct(self::OID_BASIC_CONSTRAINTS, $critical); |
|
| 43 | + $this->_ca = (bool) $ca; |
|
| 44 | + $this->_pathLen = $path_len; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * |
|
| 49 | - * {@inheritdoc} |
|
| 50 | - * @return self |
|
| 51 | - */ |
|
| 52 | - protected static function _fromDER($data, $critical) |
|
| 53 | - { |
|
| 54 | - $seq = Sequence::fromDER($data); |
|
| 55 | - $ca = false; |
|
| 56 | - $path_len = null; |
|
| 57 | - $idx = 0; |
|
| 58 | - if ($seq->has($idx, Element::TYPE_BOOLEAN)) { |
|
| 59 | - $ca = $seq->at($idx++) |
|
| 60 | - ->asBoolean() |
|
| 61 | - ->value(); |
|
| 62 | - } |
|
| 63 | - if ($seq->has($idx, Element::TYPE_INTEGER)) { |
|
| 64 | - $path_len = $seq->at($idx) |
|
| 65 | - ->asInteger() |
|
| 66 | - ->number(); |
|
| 67 | - } |
|
| 68 | - return new self($critical, $ca, $path_len); |
|
| 69 | - } |
|
| 47 | + /** |
|
| 48 | + * |
|
| 49 | + * {@inheritdoc} |
|
| 50 | + * @return self |
|
| 51 | + */ |
|
| 52 | + protected static function _fromDER($data, $critical) |
|
| 53 | + { |
|
| 54 | + $seq = Sequence::fromDER($data); |
|
| 55 | + $ca = false; |
|
| 56 | + $path_len = null; |
|
| 57 | + $idx = 0; |
|
| 58 | + if ($seq->has($idx, Element::TYPE_BOOLEAN)) { |
|
| 59 | + $ca = $seq->at($idx++) |
|
| 60 | + ->asBoolean() |
|
| 61 | + ->value(); |
|
| 62 | + } |
|
| 63 | + if ($seq->has($idx, Element::TYPE_INTEGER)) { |
|
| 64 | + $path_len = $seq->at($idx) |
|
| 65 | + ->asInteger() |
|
| 66 | + ->number(); |
|
| 67 | + } |
|
| 68 | + return new self($critical, $ca, $path_len); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Whether certificate is a CA. |
|
| 73 | - * |
|
| 74 | - * @return bool |
|
| 75 | - */ |
|
| 76 | - public function isCA(): bool |
|
| 77 | - { |
|
| 78 | - return $this->_ca; |
|
| 79 | - } |
|
| 71 | + /** |
|
| 72 | + * Whether certificate is a CA. |
|
| 73 | + * |
|
| 74 | + * @return bool |
|
| 75 | + */ |
|
| 76 | + public function isCA(): bool |
|
| 77 | + { |
|
| 78 | + return $this->_ca; |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * Whether path length is present. |
|
| 83 | - * |
|
| 84 | - * @return bool |
|
| 85 | - */ |
|
| 86 | - public function hasPathLen(): bool |
|
| 87 | - { |
|
| 88 | - return isset($this->_pathLen); |
|
| 89 | - } |
|
| 81 | + /** |
|
| 82 | + * Whether path length is present. |
|
| 83 | + * |
|
| 84 | + * @return bool |
|
| 85 | + */ |
|
| 86 | + public function hasPathLen(): bool |
|
| 87 | + { |
|
| 88 | + return isset($this->_pathLen); |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * Get path length. |
|
| 93 | - * |
|
| 94 | - * @throws \LogicException |
|
| 95 | - * @return int |
|
| 96 | - */ |
|
| 97 | - public function pathLen() |
|
| 98 | - { |
|
| 99 | - if (!$this->hasPathLen()) { |
|
| 100 | - throw new \LogicException("pathLenConstraint not set."); |
|
| 101 | - } |
|
| 102 | - return $this->_pathLen; |
|
| 103 | - } |
|
| 91 | + /** |
|
| 92 | + * Get path length. |
|
| 93 | + * |
|
| 94 | + * @throws \LogicException |
|
| 95 | + * @return int |
|
| 96 | + */ |
|
| 97 | + public function pathLen() |
|
| 98 | + { |
|
| 99 | + if (!$this->hasPathLen()) { |
|
| 100 | + throw new \LogicException("pathLenConstraint not set."); |
|
| 101 | + } |
|
| 102 | + return $this->_pathLen; |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * |
|
| 107 | - * {@inheritdoc} |
|
| 108 | - * @return Sequence |
|
| 109 | - */ |
|
| 110 | - protected function _valueASN1(): Sequence |
|
| 111 | - { |
|
| 112 | - $elements = array(); |
|
| 113 | - if ($this->_ca) { |
|
| 114 | - $elements[] = new Boolean(true); |
|
| 115 | - } |
|
| 116 | - if (isset($this->_pathLen)) { |
|
| 117 | - $elements[] = new Integer($this->_pathLen); |
|
| 118 | - } |
|
| 119 | - return new Sequence(...$elements); |
|
| 120 | - } |
|
| 105 | + /** |
|
| 106 | + * |
|
| 107 | + * {@inheritdoc} |
|
| 108 | + * @return Sequence |
|
| 109 | + */ |
|
| 110 | + protected function _valueASN1(): Sequence |
|
| 111 | + { |
|
| 112 | + $elements = array(); |
|
| 113 | + if ($this->_ca) { |
|
| 114 | + $elements[] = new Boolean(true); |
|
| 115 | + } |
|
| 116 | + if (isset($this->_pathLen)) { |
|
| 117 | + $elements[] = new Integer($this->_pathLen); |
|
| 118 | + } |
|
| 119 | + return new Sequence(...$elements); |
|
| 120 | + } |
|
| 121 | 121 | } |
@@ -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; |
| 6 | 6 | |
@@ -14,155 +14,155 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class KeyUsageExtension extends Extension |
| 16 | 16 | { |
| 17 | - const DIGITAL_SIGNATURE = 0x100; |
|
| 18 | - const NON_REPUDIATION = 0x080; |
|
| 19 | - const KEY_ENCIPHERMENT = 0x040; |
|
| 20 | - const DATA_ENCIPHERMENT = 0x020; |
|
| 21 | - const KEY_AGREEMENT = 0x010; |
|
| 22 | - const KEY_CERT_SIGN = 0x008; |
|
| 23 | - const CRL_SIGN = 0x004; |
|
| 24 | - const ENCIPHER_ONLY = 0x002; |
|
| 25 | - const DECIPHER_ONLY = 0x001; |
|
| 17 | + const DIGITAL_SIGNATURE = 0x100; |
|
| 18 | + const NON_REPUDIATION = 0x080; |
|
| 19 | + const KEY_ENCIPHERMENT = 0x040; |
|
| 20 | + const DATA_ENCIPHERMENT = 0x020; |
|
| 21 | + const KEY_AGREEMENT = 0x010; |
|
| 22 | + const KEY_CERT_SIGN = 0x008; |
|
| 23 | + const CRL_SIGN = 0x004; |
|
| 24 | + const ENCIPHER_ONLY = 0x002; |
|
| 25 | + const DECIPHER_ONLY = 0x001; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Key usage flags. |
|
| 29 | - * |
|
| 30 | - * @var int $_keyUsage |
|
| 31 | - */ |
|
| 32 | - protected $_keyUsage; |
|
| 27 | + /** |
|
| 28 | + * Key usage flags. |
|
| 29 | + * |
|
| 30 | + * @var int $_keyUsage |
|
| 31 | + */ |
|
| 32 | + protected $_keyUsage; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Constructor. |
|
| 36 | - * |
|
| 37 | - * @param bool $critical |
|
| 38 | - * @param int $keyUsage |
|
| 39 | - */ |
|
| 40 | - public function __construct(bool $critical, $keyUsage) |
|
| 41 | - { |
|
| 42 | - parent::__construct(self::OID_KEY_USAGE, $critical); |
|
| 43 | - $this->_keyUsage = (int) $keyUsage; |
|
| 44 | - } |
|
| 34 | + /** |
|
| 35 | + * Constructor. |
|
| 36 | + * |
|
| 37 | + * @param bool $critical |
|
| 38 | + * @param int $keyUsage |
|
| 39 | + */ |
|
| 40 | + public function __construct(bool $critical, $keyUsage) |
|
| 41 | + { |
|
| 42 | + parent::__construct(self::OID_KEY_USAGE, $critical); |
|
| 43 | + $this->_keyUsage = (int) $keyUsage; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * |
|
| 48 | - * {@inheritdoc} |
|
| 49 | - * @return self |
|
| 50 | - */ |
|
| 51 | - protected static function _fromDER($data, $critical) |
|
| 52 | - { |
|
| 53 | - return new self($critical, |
|
| 54 | - Flags::fromBitString(BitString::fromDER($data), 9)->number()); |
|
| 55 | - } |
|
| 46 | + /** |
|
| 47 | + * |
|
| 48 | + * {@inheritdoc} |
|
| 49 | + * @return self |
|
| 50 | + */ |
|
| 51 | + protected static function _fromDER($data, $critical) |
|
| 52 | + { |
|
| 53 | + return new self($critical, |
|
| 54 | + Flags::fromBitString(BitString::fromDER($data), 9)->number()); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Check whether digitalSignature flag is set. |
|
| 59 | - * |
|
| 60 | - * @return bool |
|
| 61 | - */ |
|
| 62 | - public function isDigitalSignature(): bool |
|
| 63 | - { |
|
| 64 | - return $this->_flagSet(self::DIGITAL_SIGNATURE); |
|
| 65 | - } |
|
| 57 | + /** |
|
| 58 | + * Check whether digitalSignature flag is set. |
|
| 59 | + * |
|
| 60 | + * @return bool |
|
| 61 | + */ |
|
| 62 | + public function isDigitalSignature(): bool |
|
| 63 | + { |
|
| 64 | + return $this->_flagSet(self::DIGITAL_SIGNATURE); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * Check whether nonRepudiation/contentCommitment flag is set. |
|
| 69 | - * |
|
| 70 | - * @return bool |
|
| 71 | - */ |
|
| 72 | - public function isNonRepudiation(): bool |
|
| 73 | - { |
|
| 74 | - return $this->_flagSet(self::NON_REPUDIATION); |
|
| 75 | - } |
|
| 67 | + /** |
|
| 68 | + * Check whether nonRepudiation/contentCommitment flag is set. |
|
| 69 | + * |
|
| 70 | + * @return bool |
|
| 71 | + */ |
|
| 72 | + public function isNonRepudiation(): bool |
|
| 73 | + { |
|
| 74 | + return $this->_flagSet(self::NON_REPUDIATION); |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * Check whether keyEncipherment flag is set. |
|
| 79 | - * |
|
| 80 | - * @return bool |
|
| 81 | - */ |
|
| 82 | - public function isKeyEncipherment(): bool |
|
| 83 | - { |
|
| 84 | - return $this->_flagSet(self::KEY_ENCIPHERMENT); |
|
| 85 | - } |
|
| 77 | + /** |
|
| 78 | + * Check whether keyEncipherment flag is set. |
|
| 79 | + * |
|
| 80 | + * @return bool |
|
| 81 | + */ |
|
| 82 | + public function isKeyEncipherment(): bool |
|
| 83 | + { |
|
| 84 | + return $this->_flagSet(self::KEY_ENCIPHERMENT); |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * Check whether dataEncipherment flag is set. |
|
| 89 | - * |
|
| 90 | - * @return bool |
|
| 91 | - */ |
|
| 92 | - public function isDataEncipherment(): bool |
|
| 93 | - { |
|
| 94 | - return $this->_flagSet(self::DATA_ENCIPHERMENT); |
|
| 95 | - } |
|
| 87 | + /** |
|
| 88 | + * Check whether dataEncipherment flag is set. |
|
| 89 | + * |
|
| 90 | + * @return bool |
|
| 91 | + */ |
|
| 92 | + public function isDataEncipherment(): bool |
|
| 93 | + { |
|
| 94 | + return $this->_flagSet(self::DATA_ENCIPHERMENT); |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * Check whether keyAgreement flag is set. |
|
| 99 | - * |
|
| 100 | - * @return bool |
|
| 101 | - */ |
|
| 102 | - public function isKeyAgreement(): bool |
|
| 103 | - { |
|
| 104 | - return $this->_flagSet(self::KEY_AGREEMENT); |
|
| 105 | - } |
|
| 97 | + /** |
|
| 98 | + * Check whether keyAgreement flag is set. |
|
| 99 | + * |
|
| 100 | + * @return bool |
|
| 101 | + */ |
|
| 102 | + public function isKeyAgreement(): bool |
|
| 103 | + { |
|
| 104 | + return $this->_flagSet(self::KEY_AGREEMENT); |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * Check whether keyCertSign flag is set. |
|
| 109 | - * |
|
| 110 | - * @return bool |
|
| 111 | - */ |
|
| 112 | - public function isKeyCertSign(): bool |
|
| 113 | - { |
|
| 114 | - return $this->_flagSet(self::KEY_CERT_SIGN); |
|
| 115 | - } |
|
| 107 | + /** |
|
| 108 | + * Check whether keyCertSign flag is set. |
|
| 109 | + * |
|
| 110 | + * @return bool |
|
| 111 | + */ |
|
| 112 | + public function isKeyCertSign(): bool |
|
| 113 | + { |
|
| 114 | + return $this->_flagSet(self::KEY_CERT_SIGN); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * Check whether cRLSign flag is set. |
|
| 119 | - * |
|
| 120 | - * @return bool |
|
| 121 | - */ |
|
| 122 | - public function isCRLSign(): bool |
|
| 123 | - { |
|
| 124 | - return $this->_flagSet(self::CRL_SIGN); |
|
| 125 | - } |
|
| 117 | + /** |
|
| 118 | + * Check whether cRLSign flag is set. |
|
| 119 | + * |
|
| 120 | + * @return bool |
|
| 121 | + */ |
|
| 122 | + public function isCRLSign(): bool |
|
| 123 | + { |
|
| 124 | + return $this->_flagSet(self::CRL_SIGN); |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | - /** |
|
| 128 | - * Check whether encipherOnly flag is set. |
|
| 129 | - * |
|
| 130 | - * @return bool |
|
| 131 | - */ |
|
| 132 | - public function isEncipherOnly(): bool |
|
| 133 | - { |
|
| 134 | - return $this->_flagSet(self::ENCIPHER_ONLY); |
|
| 135 | - } |
|
| 127 | + /** |
|
| 128 | + * Check whether encipherOnly flag is set. |
|
| 129 | + * |
|
| 130 | + * @return bool |
|
| 131 | + */ |
|
| 132 | + public function isEncipherOnly(): bool |
|
| 133 | + { |
|
| 134 | + return $this->_flagSet(self::ENCIPHER_ONLY); |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | - /** |
|
| 138 | - * Check whether decipherOnly flag is set. |
|
| 139 | - * |
|
| 140 | - * @return bool |
|
| 141 | - */ |
|
| 142 | - public function isDecipherOnly(): bool |
|
| 143 | - { |
|
| 144 | - return $this->_flagSet(self::DECIPHER_ONLY); |
|
| 145 | - } |
|
| 137 | + /** |
|
| 138 | + * Check whether decipherOnly flag is set. |
|
| 139 | + * |
|
| 140 | + * @return bool |
|
| 141 | + */ |
|
| 142 | + public function isDecipherOnly(): bool |
|
| 143 | + { |
|
| 144 | + return $this->_flagSet(self::DECIPHER_ONLY); |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - /** |
|
| 148 | - * Check whether given flag is set. |
|
| 149 | - * |
|
| 150 | - * @param int $flag |
|
| 151 | - * @return boolean |
|
| 152 | - */ |
|
| 153 | - protected function _flagSet($flag): bool |
|
| 154 | - { |
|
| 155 | - return (bool) ($this->_keyUsage & $flag); |
|
| 156 | - } |
|
| 147 | + /** |
|
| 148 | + * Check whether given flag is set. |
|
| 149 | + * |
|
| 150 | + * @param int $flag |
|
| 151 | + * @return boolean |
|
| 152 | + */ |
|
| 153 | + protected function _flagSet($flag): bool |
|
| 154 | + { |
|
| 155 | + return (bool) ($this->_keyUsage & $flag); |
|
| 156 | + } |
|
| 157 | 157 | |
| 158 | - /** |
|
| 159 | - * |
|
| 160 | - * {@inheritdoc} |
|
| 161 | - * @return BitString |
|
| 162 | - */ |
|
| 163 | - protected function _valueASN1(): BitString |
|
| 164 | - { |
|
| 165 | - $flags = new Flags($this->_keyUsage, 9); |
|
| 166 | - return $flags->bitString()->withoutTrailingZeroes(); |
|
| 167 | - } |
|
| 158 | + /** |
|
| 159 | + * |
|
| 160 | + * {@inheritdoc} |
|
| 161 | + * @return BitString |
|
| 162 | + */ |
|
| 163 | + protected function _valueASN1(): BitString |
|
| 164 | + { |
|
| 165 | + $flags = new Flags($this->_keyUsage, 9); |
|
| 166 | + return $flags->bitString()->withoutTrailingZeroes(); |
|
| 167 | + } |
|
| 168 | 168 | } |
@@ -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; |
| 6 | 6 | |
@@ -14,136 +14,136 @@ |
||
| 14 | 14 | * @link https://tools.ietf.org/html/rfc5280#section-4.2.1.4 |
| 15 | 15 | */ |
| 16 | 16 | class CertificatePoliciesExtension extends Extension implements |
| 17 | - \Countable, |
|
| 18 | - \IteratorAggregate |
|
| 17 | + \Countable, |
|
| 18 | + \IteratorAggregate |
|
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * Policy information terms. |
|
| 22 | - * |
|
| 23 | - * @var PolicyInformation[] $_policies |
|
| 24 | - */ |
|
| 25 | - protected $_policies; |
|
| 20 | + /** |
|
| 21 | + * Policy information terms. |
|
| 22 | + * |
|
| 23 | + * @var PolicyInformation[] $_policies |
|
| 24 | + */ |
|
| 25 | + protected $_policies; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Constructor. |
|
| 29 | - * |
|
| 30 | - * @param bool $critical |
|
| 31 | - * @param PolicyInformation ...$policies |
|
| 32 | - */ |
|
| 33 | - public function __construct($critical, PolicyInformation ...$policies) |
|
| 34 | - { |
|
| 35 | - parent::__construct(Extension::OID_CERTIFICATE_POLICIES, $critical); |
|
| 36 | - $this->_policies = []; |
|
| 37 | - foreach ($policies as $policy) { |
|
| 38 | - $this->_policies[$policy->oid()] = $policy; |
|
| 39 | - } |
|
| 40 | - } |
|
| 27 | + /** |
|
| 28 | + * Constructor. |
|
| 29 | + * |
|
| 30 | + * @param bool $critical |
|
| 31 | + * @param PolicyInformation ...$policies |
|
| 32 | + */ |
|
| 33 | + public function __construct($critical, PolicyInformation ...$policies) |
|
| 34 | + { |
|
| 35 | + parent::__construct(Extension::OID_CERTIFICATE_POLICIES, $critical); |
|
| 36 | + $this->_policies = []; |
|
| 37 | + foreach ($policies as $policy) { |
|
| 38 | + $this->_policies[$policy->oid()] = $policy; |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * |
|
| 44 | - * {@inheritdoc} |
|
| 45 | - * @return self |
|
| 46 | - */ |
|
| 47 | - protected static function _fromDER($data, $critical) |
|
| 48 | - { |
|
| 49 | - $policies = array_map( |
|
| 50 | - function (UnspecifiedType $el) { |
|
| 51 | - return PolicyInformation::fromASN1($el->asSequence()); |
|
| 52 | - }, Sequence::fromDER($data)->elements()); |
|
| 53 | - if (!count($policies)) { |
|
| 54 | - throw new \UnexpectedValueException( |
|
| 55 | - "certificatePolicies must contain" . |
|
| 56 | - " at least one PolicyInformation."); |
|
| 57 | - } |
|
| 58 | - return new self($critical, ...$policies); |
|
| 59 | - } |
|
| 42 | + /** |
|
| 43 | + * |
|
| 44 | + * {@inheritdoc} |
|
| 45 | + * @return self |
|
| 46 | + */ |
|
| 47 | + protected static function _fromDER($data, $critical) |
|
| 48 | + { |
|
| 49 | + $policies = array_map( |
|
| 50 | + function (UnspecifiedType $el) { |
|
| 51 | + return PolicyInformation::fromASN1($el->asSequence()); |
|
| 52 | + }, Sequence::fromDER($data)->elements()); |
|
| 53 | + if (!count($policies)) { |
|
| 54 | + throw new \UnexpectedValueException( |
|
| 55 | + "certificatePolicies must contain" . |
|
| 56 | + " at least one PolicyInformation."); |
|
| 57 | + } |
|
| 58 | + return new self($critical, ...$policies); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Check whether policy information by OID is present. |
|
| 63 | - * |
|
| 64 | - * @param string $oid |
|
| 65 | - * @return bool |
|
| 66 | - */ |
|
| 67 | - public function has(string $oid): bool |
|
| 68 | - { |
|
| 69 | - return isset($this->_policies[$oid]); |
|
| 70 | - } |
|
| 61 | + /** |
|
| 62 | + * Check whether policy information by OID is present. |
|
| 63 | + * |
|
| 64 | + * @param string $oid |
|
| 65 | + * @return bool |
|
| 66 | + */ |
|
| 67 | + public function has(string $oid): bool |
|
| 68 | + { |
|
| 69 | + return isset($this->_policies[$oid]); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Get policy information by OID. |
|
| 74 | - * |
|
| 75 | - * @param string $oid |
|
| 76 | - * @throws \LogicException |
|
| 77 | - * @return PolicyInformation |
|
| 78 | - */ |
|
| 79 | - public function get(string $oid): PolicyInformation |
|
| 80 | - { |
|
| 81 | - if (!$this->has($oid)) { |
|
| 82 | - throw new \LogicException("Not certificate policy by OID $oid."); |
|
| 83 | - } |
|
| 84 | - return $this->_policies[$oid]; |
|
| 85 | - } |
|
| 72 | + /** |
|
| 73 | + * Get policy information by OID. |
|
| 74 | + * |
|
| 75 | + * @param string $oid |
|
| 76 | + * @throws \LogicException |
|
| 77 | + * @return PolicyInformation |
|
| 78 | + */ |
|
| 79 | + public function get(string $oid): PolicyInformation |
|
| 80 | + { |
|
| 81 | + if (!$this->has($oid)) { |
|
| 82 | + throw new \LogicException("Not certificate policy by OID $oid."); |
|
| 83 | + } |
|
| 84 | + return $this->_policies[$oid]; |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * Check whether anyPolicy is present. |
|
| 89 | - * |
|
| 90 | - * @return bool |
|
| 91 | - */ |
|
| 92 | - public function hasAnyPolicy(): bool |
|
| 93 | - { |
|
| 94 | - return $this->has(PolicyInformation::OID_ANY_POLICY); |
|
| 95 | - } |
|
| 87 | + /** |
|
| 88 | + * Check whether anyPolicy is present. |
|
| 89 | + * |
|
| 90 | + * @return bool |
|
| 91 | + */ |
|
| 92 | + public function hasAnyPolicy(): bool |
|
| 93 | + { |
|
| 94 | + return $this->has(PolicyInformation::OID_ANY_POLICY); |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * Get anyPolicy information. |
|
| 99 | - * |
|
| 100 | - * @throws \LogicException If anyPolicy is not present. |
|
| 101 | - * @return PolicyInformation |
|
| 102 | - */ |
|
| 103 | - public function anyPolicy(): PolicyInformation |
|
| 104 | - { |
|
| 105 | - if (!$this->hasAnyPolicy()) { |
|
| 106 | - throw new \LogicException("No anyPolicy."); |
|
| 107 | - } |
|
| 108 | - return $this->get(PolicyInformation::OID_ANY_POLICY); |
|
| 109 | - } |
|
| 97 | + /** |
|
| 98 | + * Get anyPolicy information. |
|
| 99 | + * |
|
| 100 | + * @throws \LogicException If anyPolicy is not present. |
|
| 101 | + * @return PolicyInformation |
|
| 102 | + */ |
|
| 103 | + public function anyPolicy(): PolicyInformation |
|
| 104 | + { |
|
| 105 | + if (!$this->hasAnyPolicy()) { |
|
| 106 | + throw new \LogicException("No anyPolicy."); |
|
| 107 | + } |
|
| 108 | + return $this->get(PolicyInformation::OID_ANY_POLICY); |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * |
|
| 113 | - * {@inheritdoc} |
|
| 114 | - * @return Sequence |
|
| 115 | - */ |
|
| 116 | - protected function _valueASN1(): Sequence |
|
| 117 | - { |
|
| 118 | - if (!count($this->_policies)) { |
|
| 119 | - throw new \LogicException("No policies."); |
|
| 120 | - } |
|
| 121 | - $elements = array_map( |
|
| 122 | - function (PolicyInformation $pi) { |
|
| 123 | - return $pi->toASN1(); |
|
| 124 | - }, array_values($this->_policies)); |
|
| 125 | - return new Sequence(...$elements); |
|
| 126 | - } |
|
| 111 | + /** |
|
| 112 | + * |
|
| 113 | + * {@inheritdoc} |
|
| 114 | + * @return Sequence |
|
| 115 | + */ |
|
| 116 | + protected function _valueASN1(): Sequence |
|
| 117 | + { |
|
| 118 | + if (!count($this->_policies)) { |
|
| 119 | + throw new \LogicException("No policies."); |
|
| 120 | + } |
|
| 121 | + $elements = array_map( |
|
| 122 | + function (PolicyInformation $pi) { |
|
| 123 | + return $pi->toASN1(); |
|
| 124 | + }, array_values($this->_policies)); |
|
| 125 | + return new Sequence(...$elements); |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | - /** |
|
| 129 | - * Get the number of policies. |
|
| 130 | - * |
|
| 131 | - * @see \Countable::count() |
|
| 132 | - * @return int |
|
| 133 | - */ |
|
| 134 | - public function count(): int |
|
| 135 | - { |
|
| 136 | - return count($this->_policies); |
|
| 137 | - } |
|
| 128 | + /** |
|
| 129 | + * Get the number of policies. |
|
| 130 | + * |
|
| 131 | + * @see \Countable::count() |
|
| 132 | + * @return int |
|
| 133 | + */ |
|
| 134 | + public function count(): int |
|
| 135 | + { |
|
| 136 | + return count($this->_policies); |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - /** |
|
| 140 | - * Get iterator for policy information terms. |
|
| 141 | - * |
|
| 142 | - * @see \IteratorAggregate::getIterator() |
|
| 143 | - * @return \ArrayIterator |
|
| 144 | - */ |
|
| 145 | - public function getIterator(): \ArrayIterator |
|
| 146 | - { |
|
| 147 | - return new \ArrayIterator($this->_policies); |
|
| 148 | - } |
|
| 139 | + /** |
|
| 140 | + * Get iterator for policy information terms. |
|
| 141 | + * |
|
| 142 | + * @see \IteratorAggregate::getIterator() |
|
| 143 | + * @return \ArrayIterator |
|
| 144 | + */ |
|
| 145 | + public function getIterator(): \ArrayIterator |
|
| 146 | + { |
|
| 147 | + return new \ArrayIterator($this->_policies); |
|
| 148 | + } |
|
| 149 | 149 | } |
@@ -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\Certificate\Extension; |
| 6 | 6 | |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | protected static function _fromDER($data, $critical) |
| 48 | 48 | { |
| 49 | 49 | $policies = array_map( |
| 50 | - function (UnspecifiedType $el) { |
|
| 50 | + function(UnspecifiedType $el) { |
|
| 51 | 51 | return PolicyInformation::fromASN1($el->asSequence()); |
| 52 | 52 | }, Sequence::fromDER($data)->elements()); |
| 53 | 53 | if (!count($policies)) { |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | throw new \LogicException("No policies."); |
| 120 | 120 | } |
| 121 | 121 | $elements = array_map( |
| 122 | - function (PolicyInformation $pi) { |
|
| 122 | + function(PolicyInformation $pi) { |
|
| 123 | 123 | return $pi->toASN1(); |
| 124 | 124 | }, array_values($this->_policies)); |
| 125 | 125 | return new Sequence(...$elements); |
@@ -16,122 +16,122 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class NameConstraintsExtension extends Extension |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * Permitted subtrees. |
|
| 21 | - * |
|
| 22 | - * @var GeneralSubtrees|null $_permitted |
|
| 23 | - */ |
|
| 24 | - protected $_permitted; |
|
| 19 | + /** |
|
| 20 | + * Permitted subtrees. |
|
| 21 | + * |
|
| 22 | + * @var GeneralSubtrees|null $_permitted |
|
| 23 | + */ |
|
| 24 | + protected $_permitted; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Excluded subtrees. |
|
| 28 | - * |
|
| 29 | - * @var GeneralSubtrees|null $_excluded |
|
| 30 | - */ |
|
| 31 | - protected $_excluded; |
|
| 26 | + /** |
|
| 27 | + * Excluded subtrees. |
|
| 28 | + * |
|
| 29 | + * @var GeneralSubtrees|null $_excluded |
|
| 30 | + */ |
|
| 31 | + protected $_excluded; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Constructor. |
|
| 35 | - * |
|
| 36 | - * @param bool $critical |
|
| 37 | - * @param GeneralSubtrees $permitted |
|
| 38 | - * @param GeneralSubtrees $excluded |
|
| 39 | - */ |
|
| 40 | - public function __construct(bool $critical, GeneralSubtrees $permitted = null, |
|
| 41 | - GeneralSubtrees $excluded = null) |
|
| 42 | - { |
|
| 43 | - parent::__construct(self::OID_NAME_CONSTRAINTS, $critical); |
|
| 44 | - $this->_permitted = $permitted; |
|
| 45 | - $this->_excluded = $excluded; |
|
| 46 | - } |
|
| 33 | + /** |
|
| 34 | + * Constructor. |
|
| 35 | + * |
|
| 36 | + * @param bool $critical |
|
| 37 | + * @param GeneralSubtrees $permitted |
|
| 38 | + * @param GeneralSubtrees $excluded |
|
| 39 | + */ |
|
| 40 | + public function __construct(bool $critical, GeneralSubtrees $permitted = null, |
|
| 41 | + GeneralSubtrees $excluded = null) |
|
| 42 | + { |
|
| 43 | + parent::__construct(self::OID_NAME_CONSTRAINTS, $critical); |
|
| 44 | + $this->_permitted = $permitted; |
|
| 45 | + $this->_excluded = $excluded; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * |
|
| 50 | - * {@inheritdoc} |
|
| 51 | - * @return self |
|
| 52 | - */ |
|
| 53 | - protected static function _fromDER($data, $critical) |
|
| 54 | - { |
|
| 55 | - $seq = Sequence::fromDER($data); |
|
| 56 | - $permitted = null; |
|
| 57 | - $excluded = null; |
|
| 58 | - if ($seq->hasTagged(0)) { |
|
| 59 | - $permitted = GeneralSubtrees::fromASN1( |
|
| 60 | - $seq->getTagged(0) |
|
| 61 | - ->asImplicit(Element::TYPE_SEQUENCE) |
|
| 62 | - ->asSequence()); |
|
| 63 | - } |
|
| 64 | - if ($seq->hasTagged(1)) { |
|
| 65 | - $excluded = GeneralSubtrees::fromASN1( |
|
| 66 | - $seq->getTagged(1) |
|
| 67 | - ->asImplicit(Element::TYPE_SEQUENCE) |
|
| 68 | - ->asSequence()); |
|
| 69 | - } |
|
| 70 | - return new self($critical, $permitted, $excluded); |
|
| 71 | - } |
|
| 48 | + /** |
|
| 49 | + * |
|
| 50 | + * {@inheritdoc} |
|
| 51 | + * @return self |
|
| 52 | + */ |
|
| 53 | + protected static function _fromDER($data, $critical) |
|
| 54 | + { |
|
| 55 | + $seq = Sequence::fromDER($data); |
|
| 56 | + $permitted = null; |
|
| 57 | + $excluded = null; |
|
| 58 | + if ($seq->hasTagged(0)) { |
|
| 59 | + $permitted = GeneralSubtrees::fromASN1( |
|
| 60 | + $seq->getTagged(0) |
|
| 61 | + ->asImplicit(Element::TYPE_SEQUENCE) |
|
| 62 | + ->asSequence()); |
|
| 63 | + } |
|
| 64 | + if ($seq->hasTagged(1)) { |
|
| 65 | + $excluded = GeneralSubtrees::fromASN1( |
|
| 66 | + $seq->getTagged(1) |
|
| 67 | + ->asImplicit(Element::TYPE_SEQUENCE) |
|
| 68 | + ->asSequence()); |
|
| 69 | + } |
|
| 70 | + return new self($critical, $permitted, $excluded); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * Whether permitted subtrees are present. |
|
| 75 | - * |
|
| 76 | - * @return bool |
|
| 77 | - */ |
|
| 78 | - public function hasPermittedSubtrees(): bool |
|
| 79 | - { |
|
| 80 | - return isset($this->_permitted); |
|
| 81 | - } |
|
| 73 | + /** |
|
| 74 | + * Whether permitted subtrees are present. |
|
| 75 | + * |
|
| 76 | + * @return bool |
|
| 77 | + */ |
|
| 78 | + public function hasPermittedSubtrees(): bool |
|
| 79 | + { |
|
| 80 | + return isset($this->_permitted); |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * Get permitted subtrees. |
|
| 85 | - * |
|
| 86 | - * @throws \LogicException |
|
| 87 | - * @return GeneralSubtrees |
|
| 88 | - */ |
|
| 89 | - public function permittedSubtrees(): GeneralSubtrees |
|
| 90 | - { |
|
| 91 | - if (!$this->hasPermittedSubtrees()) { |
|
| 92 | - throw new \LogicException("No permitted subtrees."); |
|
| 93 | - } |
|
| 94 | - return $this->_permitted; |
|
| 95 | - } |
|
| 83 | + /** |
|
| 84 | + * Get permitted subtrees. |
|
| 85 | + * |
|
| 86 | + * @throws \LogicException |
|
| 87 | + * @return GeneralSubtrees |
|
| 88 | + */ |
|
| 89 | + public function permittedSubtrees(): GeneralSubtrees |
|
| 90 | + { |
|
| 91 | + if (!$this->hasPermittedSubtrees()) { |
|
| 92 | + throw new \LogicException("No permitted subtrees."); |
|
| 93 | + } |
|
| 94 | + return $this->_permitted; |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * Whether excluded subtrees are present. |
|
| 99 | - * |
|
| 100 | - * @return bool |
|
| 101 | - */ |
|
| 102 | - public function hasExcludedSubtrees(): bool |
|
| 103 | - { |
|
| 104 | - return isset($this->_excluded); |
|
| 105 | - } |
|
| 97 | + /** |
|
| 98 | + * Whether excluded subtrees are present. |
|
| 99 | + * |
|
| 100 | + * @return bool |
|
| 101 | + */ |
|
| 102 | + public function hasExcludedSubtrees(): bool |
|
| 103 | + { |
|
| 104 | + return isset($this->_excluded); |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * Get excluded subtrees. |
|
| 109 | - * |
|
| 110 | - * @throws \LogicException |
|
| 111 | - * @return GeneralSubtrees |
|
| 112 | - */ |
|
| 113 | - public function excludedSubtrees(): GeneralSubtrees |
|
| 114 | - { |
|
| 115 | - if (!$this->hasExcludedSubtrees()) { |
|
| 116 | - throw new \LogicException("No excluded subtrees."); |
|
| 117 | - } |
|
| 118 | - return $this->_excluded; |
|
| 119 | - } |
|
| 107 | + /** |
|
| 108 | + * Get excluded subtrees. |
|
| 109 | + * |
|
| 110 | + * @throws \LogicException |
|
| 111 | + * @return GeneralSubtrees |
|
| 112 | + */ |
|
| 113 | + public function excludedSubtrees(): GeneralSubtrees |
|
| 114 | + { |
|
| 115 | + if (!$this->hasExcludedSubtrees()) { |
|
| 116 | + throw new \LogicException("No excluded subtrees."); |
|
| 117 | + } |
|
| 118 | + return $this->_excluded; |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | - /** |
|
| 122 | - * |
|
| 123 | - * {@inheritdoc} |
|
| 124 | - * @return Sequence |
|
| 125 | - */ |
|
| 126 | - protected function _valueASN1() |
|
| 127 | - { |
|
| 128 | - $elements = array(); |
|
| 129 | - if (isset($this->_permitted)) { |
|
| 130 | - $elements[] = new ImplicitlyTaggedType(0, $this->_permitted->toASN1()); |
|
| 131 | - } |
|
| 132 | - if (isset($this->_excluded)) { |
|
| 133 | - $elements[] = new ImplicitlyTaggedType(1, $this->_excluded->toASN1()); |
|
| 134 | - } |
|
| 135 | - return new Sequence(...$elements); |
|
| 136 | - } |
|
| 121 | + /** |
|
| 122 | + * |
|
| 123 | + * {@inheritdoc} |
|
| 124 | + * @return Sequence |
|
| 125 | + */ |
|
| 126 | + protected function _valueASN1() |
|
| 127 | + { |
|
| 128 | + $elements = array(); |
|
| 129 | + if (isset($this->_permitted)) { |
|
| 130 | + $elements[] = new ImplicitlyTaggedType(0, $this->_permitted->toASN1()); |
|
| 131 | + } |
|
| 132 | + if (isset($this->_excluded)) { |
|
| 133 | + $elements[] = new ImplicitlyTaggedType(1, $this->_excluded->toASN1()); |
|
| 134 | + } |
|
| 135 | + return new Sequence(...$elements); |
|
| 136 | + } |
|
| 137 | 137 | } |
@@ -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; |
| 6 | 6 | |
@@ -19,214 +19,214 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | abstract class Extension |
| 21 | 21 | { |
| 22 | - // OID's from standard certificate extensions |
|
| 23 | - const OID_OBSOLETE_AUTHORITY_KEY_IDENTIFIER = "2.5.29.1"; |
|
| 24 | - const OID_OBSOLETE_KEY_ATTRIBUTES = "2.5.29.2"; |
|
| 25 | - const OID_OBSOLETE_CERTIFICATE_POLICIES = "2.5.29.3"; |
|
| 26 | - const OID_OBSOLETE_KEY_USAGE_RESTRICTION = "2.5.29.4"; |
|
| 27 | - const OID_OBSOLETE_POLICY_MAPPING = "2.5.29.5"; |
|
| 28 | - const OID_OBSOLETE_SUBTREES_CONSTRAINT = "2.5.29.6"; |
|
| 29 | - const OID_OBSOLETE_SUBJECT_ALT_NAME = "2.5.29.7"; |
|
| 30 | - const OID_OBSOLETE_ISSUER_ALT_NAME = "2.5.29.8"; |
|
| 31 | - const OID_SUBJECT_DIRECTORY_ATTRIBUTES = "2.5.29.9"; |
|
| 32 | - const OID_OBSOLETE_BASIC_CONSTRAINTS = "2.5.29.10"; |
|
| 33 | - const OID_SUBJECT_KEY_IDENTIFIER = "2.5.29.14"; |
|
| 34 | - const OID_KEY_USAGE = "2.5.29.15"; |
|
| 35 | - const OID_PRIVATE_KEY_USAGE_PERIOD = "2.5.29.16"; |
|
| 36 | - const OID_SUBJECT_ALT_NAME = "2.5.29.17"; |
|
| 37 | - const OID_ISSUER_ALT_NAME = "2.5.29.18"; |
|
| 38 | - const OID_BASIC_CONSTRAINTS = "2.5.29.19"; |
|
| 39 | - const OID_CRL_NUMBER = "2.5.29.20"; |
|
| 40 | - const OID_REASON_CODE = "2.5.29.21"; |
|
| 41 | - const OID_OBSOLETE_EXPIRATION_DATE = "2.5.29.22"; |
|
| 42 | - const OID_INSTRUCTION_CODE = "2.5.29.23"; |
|
| 43 | - const OID_INVALIDITY_DATE = "2.5.29.24"; |
|
| 44 | - const OID_OBSOLETE_CRL_DISTRIBUTION_POINTS = "2.5.29.25"; |
|
| 45 | - const OID_OBSOLETE_ISSUING_DISTRIBUTION_POINT = "2.5.29.26"; |
|
| 46 | - const OID_DELTA_CRL_INDICATOR = "2.5.29.27"; |
|
| 47 | - const OID_ISSUING_DISTRIBUTION_POINT = "2.5.29.28"; |
|
| 48 | - const OID_CERTIFICATE_ISSUER = "2.5.29.29"; |
|
| 49 | - const OID_NAME_CONSTRAINTS = "2.5.29.30"; |
|
| 50 | - const OID_CRL_DISTRIBUTION_POINTS = "2.5.29.31"; |
|
| 51 | - const OID_CERTIFICATE_POLICIES = "2.5.29.32"; |
|
| 52 | - const OID_POLICY_MAPPINGS = "2.5.29.33"; |
|
| 53 | - const OID_OBSOLETE_POLICY_CONSTRAINTS = "2.5.29.34"; |
|
| 54 | - const OID_AUTHORITY_KEY_IDENTIFIER = "2.5.29.35"; |
|
| 55 | - const OID_POLICY_CONSTRAINTS = "2.5.29.36"; |
|
| 56 | - const OID_EXT_KEY_USAGE = "2.5.29.37"; |
|
| 57 | - const OID_AUTHORITY_ATTRIBUTE_IDENTIFIER = "2.5.29.38"; |
|
| 58 | - const OID_ROLE_SPEC_CERT_IDENTIFIER = "2.5.29.39"; |
|
| 59 | - const OID_CRL_STREAM_IDENTIFIER = "2.5.29.40"; |
|
| 60 | - const OID_BASIC_ATT_CONSTRAINTS = "2.5.29.41"; |
|
| 61 | - const OID_DELEGATED_NAME_CONSTRAINTS = "2.5.29.42"; |
|
| 62 | - const OID_TIME_SPECIFICATION = "2.5.29.43"; |
|
| 63 | - const OID_CRL_SCOPE = "2.5.29.44"; |
|
| 64 | - const OID_STATUS_REFERRALS = "2.5.29.45"; |
|
| 65 | - const OID_FRESHEST_CRL = "2.5.29.46"; |
|
| 66 | - const OID_ORDERED_LIST = "2.5.29.47"; |
|
| 67 | - const OID_ATTRIBUTE_DESCRIPTOR = "2.5.29.48"; |
|
| 68 | - const OID_USER_NOTICE = "2.5.29.49"; |
|
| 69 | - const OID_SOA_IDENTIFIER = "2.5.29.50"; |
|
| 70 | - const OID_BASE_UPDATE_TIME = "2.5.29.51"; |
|
| 71 | - const OID_ACCEPTABLE_CERT_POLICIES = "2.5.29.52"; |
|
| 72 | - const OID_DELTA_INFO = "2.5.29.53"; |
|
| 73 | - const OID_INHIBIT_ANY_POLICY = "2.5.29.54"; |
|
| 74 | - const OID_TARGET_INFORMATION = "2.5.29.55"; |
|
| 75 | - const OID_NO_REV_AVAIL = "2.5.29.56"; |
|
| 76 | - const OID_ACCEPTABLE_PRIVILEGE_POLICIES = "2.5.29.57"; |
|
| 77 | - const OID_TO_BE_REVOKED = "2.5.29.58"; |
|
| 78 | - const OID_REVOKED_GROUPS = "2.5.29.59"; |
|
| 79 | - const OID_EXPIRED_CERTS_ON_CRL = "2.5.29.60"; |
|
| 80 | - const OID_INDIRECT_ISSUER = "2.5.29.61"; |
|
| 81 | - const OID_NO_ASSERTION = "2.5.29.62"; |
|
| 82 | - const OID_AA_ISSUING_DISTRIBUTION_POINT = "2.5.29.63"; |
|
| 83 | - const OID_ISSUED_ON_BEHALF_OF = "2.5.29.64"; |
|
| 84 | - const OID_SINGLE_USE = "2.5.29.65"; |
|
| 85 | - const OID_GROUP_AC = "2.5.29.66"; |
|
| 86 | - const OID_ALLOWED_ATT_ASS = "2.5.29.67"; |
|
| 87 | - const OID_ATTRIBUTE_MAPPINGS = "2.5.29.68"; |
|
| 88 | - const OID_HOLDER_NAME_CONSTRAINTS = "2.5.29.69"; |
|
| 22 | + // OID's from standard certificate extensions |
|
| 23 | + const OID_OBSOLETE_AUTHORITY_KEY_IDENTIFIER = "2.5.29.1"; |
|
| 24 | + const OID_OBSOLETE_KEY_ATTRIBUTES = "2.5.29.2"; |
|
| 25 | + const OID_OBSOLETE_CERTIFICATE_POLICIES = "2.5.29.3"; |
|
| 26 | + const OID_OBSOLETE_KEY_USAGE_RESTRICTION = "2.5.29.4"; |
|
| 27 | + const OID_OBSOLETE_POLICY_MAPPING = "2.5.29.5"; |
|
| 28 | + const OID_OBSOLETE_SUBTREES_CONSTRAINT = "2.5.29.6"; |
|
| 29 | + const OID_OBSOLETE_SUBJECT_ALT_NAME = "2.5.29.7"; |
|
| 30 | + const OID_OBSOLETE_ISSUER_ALT_NAME = "2.5.29.8"; |
|
| 31 | + const OID_SUBJECT_DIRECTORY_ATTRIBUTES = "2.5.29.9"; |
|
| 32 | + const OID_OBSOLETE_BASIC_CONSTRAINTS = "2.5.29.10"; |
|
| 33 | + const OID_SUBJECT_KEY_IDENTIFIER = "2.5.29.14"; |
|
| 34 | + const OID_KEY_USAGE = "2.5.29.15"; |
|
| 35 | + const OID_PRIVATE_KEY_USAGE_PERIOD = "2.5.29.16"; |
|
| 36 | + const OID_SUBJECT_ALT_NAME = "2.5.29.17"; |
|
| 37 | + const OID_ISSUER_ALT_NAME = "2.5.29.18"; |
|
| 38 | + const OID_BASIC_CONSTRAINTS = "2.5.29.19"; |
|
| 39 | + const OID_CRL_NUMBER = "2.5.29.20"; |
|
| 40 | + const OID_REASON_CODE = "2.5.29.21"; |
|
| 41 | + const OID_OBSOLETE_EXPIRATION_DATE = "2.5.29.22"; |
|
| 42 | + const OID_INSTRUCTION_CODE = "2.5.29.23"; |
|
| 43 | + const OID_INVALIDITY_DATE = "2.5.29.24"; |
|
| 44 | + const OID_OBSOLETE_CRL_DISTRIBUTION_POINTS = "2.5.29.25"; |
|
| 45 | + const OID_OBSOLETE_ISSUING_DISTRIBUTION_POINT = "2.5.29.26"; |
|
| 46 | + const OID_DELTA_CRL_INDICATOR = "2.5.29.27"; |
|
| 47 | + const OID_ISSUING_DISTRIBUTION_POINT = "2.5.29.28"; |
|
| 48 | + const OID_CERTIFICATE_ISSUER = "2.5.29.29"; |
|
| 49 | + const OID_NAME_CONSTRAINTS = "2.5.29.30"; |
|
| 50 | + const OID_CRL_DISTRIBUTION_POINTS = "2.5.29.31"; |
|
| 51 | + const OID_CERTIFICATE_POLICIES = "2.5.29.32"; |
|
| 52 | + const OID_POLICY_MAPPINGS = "2.5.29.33"; |
|
| 53 | + const OID_OBSOLETE_POLICY_CONSTRAINTS = "2.5.29.34"; |
|
| 54 | + const OID_AUTHORITY_KEY_IDENTIFIER = "2.5.29.35"; |
|
| 55 | + const OID_POLICY_CONSTRAINTS = "2.5.29.36"; |
|
| 56 | + const OID_EXT_KEY_USAGE = "2.5.29.37"; |
|
| 57 | + const OID_AUTHORITY_ATTRIBUTE_IDENTIFIER = "2.5.29.38"; |
|
| 58 | + const OID_ROLE_SPEC_CERT_IDENTIFIER = "2.5.29.39"; |
|
| 59 | + const OID_CRL_STREAM_IDENTIFIER = "2.5.29.40"; |
|
| 60 | + const OID_BASIC_ATT_CONSTRAINTS = "2.5.29.41"; |
|
| 61 | + const OID_DELEGATED_NAME_CONSTRAINTS = "2.5.29.42"; |
|
| 62 | + const OID_TIME_SPECIFICATION = "2.5.29.43"; |
|
| 63 | + const OID_CRL_SCOPE = "2.5.29.44"; |
|
| 64 | + const OID_STATUS_REFERRALS = "2.5.29.45"; |
|
| 65 | + const OID_FRESHEST_CRL = "2.5.29.46"; |
|
| 66 | + const OID_ORDERED_LIST = "2.5.29.47"; |
|
| 67 | + const OID_ATTRIBUTE_DESCRIPTOR = "2.5.29.48"; |
|
| 68 | + const OID_USER_NOTICE = "2.5.29.49"; |
|
| 69 | + const OID_SOA_IDENTIFIER = "2.5.29.50"; |
|
| 70 | + const OID_BASE_UPDATE_TIME = "2.5.29.51"; |
|
| 71 | + const OID_ACCEPTABLE_CERT_POLICIES = "2.5.29.52"; |
|
| 72 | + const OID_DELTA_INFO = "2.5.29.53"; |
|
| 73 | + const OID_INHIBIT_ANY_POLICY = "2.5.29.54"; |
|
| 74 | + const OID_TARGET_INFORMATION = "2.5.29.55"; |
|
| 75 | + const OID_NO_REV_AVAIL = "2.5.29.56"; |
|
| 76 | + const OID_ACCEPTABLE_PRIVILEGE_POLICIES = "2.5.29.57"; |
|
| 77 | + const OID_TO_BE_REVOKED = "2.5.29.58"; |
|
| 78 | + const OID_REVOKED_GROUPS = "2.5.29.59"; |
|
| 79 | + const OID_EXPIRED_CERTS_ON_CRL = "2.5.29.60"; |
|
| 80 | + const OID_INDIRECT_ISSUER = "2.5.29.61"; |
|
| 81 | + const OID_NO_ASSERTION = "2.5.29.62"; |
|
| 82 | + const OID_AA_ISSUING_DISTRIBUTION_POINT = "2.5.29.63"; |
|
| 83 | + const OID_ISSUED_ON_BEHALF_OF = "2.5.29.64"; |
|
| 84 | + const OID_SINGLE_USE = "2.5.29.65"; |
|
| 85 | + const OID_GROUP_AC = "2.5.29.66"; |
|
| 86 | + const OID_ALLOWED_ATT_ASS = "2.5.29.67"; |
|
| 87 | + const OID_ATTRIBUTE_MAPPINGS = "2.5.29.68"; |
|
| 88 | + const OID_HOLDER_NAME_CONSTRAINTS = "2.5.29.69"; |
|
| 89 | 89 | |
| 90 | - // OID's from private certificate extensions arc |
|
| 91 | - const OID_AA_CONTROLS = "1.3.6.1.5.5.7.1.6"; |
|
| 90 | + // OID's from private certificate extensions arc |
|
| 91 | + const OID_AA_CONTROLS = "1.3.6.1.5.5.7.1.6"; |
|
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * Mapping from extension ID to implementation class name. |
|
| 95 | - * |
|
| 96 | - * @internal |
|
| 97 | - * |
|
| 98 | - * @var array |
|
| 99 | - */ |
|
| 100 | - const MAP_OID_TO_CLASS = array( |
|
| 101 | - /* @formatter:off */ |
|
| 102 | - self::OID_AUTHORITY_KEY_IDENTIFIER => AuthorityKeyIdentifierExtension::class, |
|
| 103 | - self::OID_SUBJECT_KEY_IDENTIFIER => SubjectKeyIdentifierExtension::class, |
|
| 104 | - self::OID_KEY_USAGE => KeyUsageExtension::class, |
|
| 105 | - self::OID_CERTIFICATE_POLICIES => CertificatePoliciesExtension::class, |
|
| 106 | - self::OID_POLICY_MAPPINGS => PolicyMappingsExtension::class, |
|
| 107 | - self::OID_SUBJECT_ALT_NAME => SubjectAlternativeNameExtension::class, |
|
| 108 | - self::OID_ISSUER_ALT_NAME => IssuerAlternativeNameExtension::class, |
|
| 109 | - self::OID_SUBJECT_DIRECTORY_ATTRIBUTES => SubjectDirectoryAttributesExtension::class, |
|
| 110 | - self::OID_BASIC_CONSTRAINTS => BasicConstraintsExtension::class, |
|
| 111 | - self::OID_NAME_CONSTRAINTS => NameConstraintsExtension::class, |
|
| 112 | - self::OID_POLICY_CONSTRAINTS => PolicyConstraintsExtension::class, |
|
| 113 | - self::OID_EXT_KEY_USAGE => ExtendedKeyUsageExtension::class, |
|
| 114 | - self::OID_CRL_DISTRIBUTION_POINTS => CRLDistributionPointsExtension::class, |
|
| 115 | - self::OID_INHIBIT_ANY_POLICY => InhibitAnyPolicyExtension::class, |
|
| 116 | - self::OID_FRESHEST_CRL => FreshestCRLExtension::class, |
|
| 117 | - self::OID_NO_REV_AVAIL => NoRevocationAvailableExtension::class, |
|
| 118 | - self::OID_TARGET_INFORMATION => TargetInformationExtension::class, |
|
| 119 | - self::OID_AA_CONTROLS => AAControlsExtension::class |
|
| 120 | - /* @formatter:on */ |
|
| 121 | - ); |
|
| 93 | + /** |
|
| 94 | + * Mapping from extension ID to implementation class name. |
|
| 95 | + * |
|
| 96 | + * @internal |
|
| 97 | + * |
|
| 98 | + * @var array |
|
| 99 | + */ |
|
| 100 | + const MAP_OID_TO_CLASS = array( |
|
| 101 | + /* @formatter:off */ |
|
| 102 | + self::OID_AUTHORITY_KEY_IDENTIFIER => AuthorityKeyIdentifierExtension::class, |
|
| 103 | + self::OID_SUBJECT_KEY_IDENTIFIER => SubjectKeyIdentifierExtension::class, |
|
| 104 | + self::OID_KEY_USAGE => KeyUsageExtension::class, |
|
| 105 | + self::OID_CERTIFICATE_POLICIES => CertificatePoliciesExtension::class, |
|
| 106 | + self::OID_POLICY_MAPPINGS => PolicyMappingsExtension::class, |
|
| 107 | + self::OID_SUBJECT_ALT_NAME => SubjectAlternativeNameExtension::class, |
|
| 108 | + self::OID_ISSUER_ALT_NAME => IssuerAlternativeNameExtension::class, |
|
| 109 | + self::OID_SUBJECT_DIRECTORY_ATTRIBUTES => SubjectDirectoryAttributesExtension::class, |
|
| 110 | + self::OID_BASIC_CONSTRAINTS => BasicConstraintsExtension::class, |
|
| 111 | + self::OID_NAME_CONSTRAINTS => NameConstraintsExtension::class, |
|
| 112 | + self::OID_POLICY_CONSTRAINTS => PolicyConstraintsExtension::class, |
|
| 113 | + self::OID_EXT_KEY_USAGE => ExtendedKeyUsageExtension::class, |
|
| 114 | + self::OID_CRL_DISTRIBUTION_POINTS => CRLDistributionPointsExtension::class, |
|
| 115 | + self::OID_INHIBIT_ANY_POLICY => InhibitAnyPolicyExtension::class, |
|
| 116 | + self::OID_FRESHEST_CRL => FreshestCRLExtension::class, |
|
| 117 | + self::OID_NO_REV_AVAIL => NoRevocationAvailableExtension::class, |
|
| 118 | + self::OID_TARGET_INFORMATION => TargetInformationExtension::class, |
|
| 119 | + self::OID_AA_CONTROLS => AAControlsExtension::class |
|
| 120 | + /* @formatter:on */ |
|
| 121 | + ); |
|
| 122 | 122 | |
| 123 | - /** |
|
| 124 | - * Extension's OID. |
|
| 125 | - * |
|
| 126 | - * @var string $_oid |
|
| 127 | - */ |
|
| 128 | - protected $_oid; |
|
| 123 | + /** |
|
| 124 | + * Extension's OID. |
|
| 125 | + * |
|
| 126 | + * @var string $_oid |
|
| 127 | + */ |
|
| 128 | + protected $_oid; |
|
| 129 | 129 | |
| 130 | - /** |
|
| 131 | - * Whether extension is critical. |
|
| 132 | - * |
|
| 133 | - * @var bool $_critical |
|
| 134 | - */ |
|
| 135 | - protected $_critical; |
|
| 130 | + /** |
|
| 131 | + * Whether extension is critical. |
|
| 132 | + * |
|
| 133 | + * @var bool $_critical |
|
| 134 | + */ |
|
| 135 | + protected $_critical; |
|
| 136 | 136 | |
| 137 | - /** |
|
| 138 | - * Get ASN.1 structure of the extension value. |
|
| 139 | - * |
|
| 140 | - * @return Element |
|
| 141 | - */ |
|
| 142 | - abstract protected function _valueASN1(); |
|
| 137 | + /** |
|
| 138 | + * Get ASN.1 structure of the extension value. |
|
| 139 | + * |
|
| 140 | + * @return Element |
|
| 141 | + */ |
|
| 142 | + abstract protected function _valueASN1(); |
|
| 143 | 143 | |
| 144 | - /** |
|
| 145 | - * Parse extension value from DER. |
|
| 146 | - * |
|
| 147 | - * @param string $data DER data |
|
| 148 | - * @param bool $critical Whether extension is critical |
|
| 149 | - * @throws \BadMethodCallException |
|
| 150 | - * @return self |
|
| 151 | - */ |
|
| 152 | - protected static function _fromDER($data, $critical) |
|
| 153 | - { |
|
| 154 | - throw new \BadMethodCallException( |
|
| 155 | - __FUNCTION__ . " must be implemented in derived class."); |
|
| 156 | - } |
|
| 144 | + /** |
|
| 145 | + * Parse extension value from DER. |
|
| 146 | + * |
|
| 147 | + * @param string $data DER data |
|
| 148 | + * @param bool $critical Whether extension is critical |
|
| 149 | + * @throws \BadMethodCallException |
|
| 150 | + * @return self |
|
| 151 | + */ |
|
| 152 | + protected static function _fromDER($data, $critical) |
|
| 153 | + { |
|
| 154 | + throw new \BadMethodCallException( |
|
| 155 | + __FUNCTION__ . " must be implemented in derived class."); |
|
| 156 | + } |
|
| 157 | 157 | |
| 158 | - /** |
|
| 159 | - * Constructor. |
|
| 160 | - * |
|
| 161 | - * @param string $oid Extension OID |
|
| 162 | - * @param bool $critical Whether extension is critical |
|
| 163 | - */ |
|
| 164 | - public function __construct(string $oid, bool $critical) |
|
| 165 | - { |
|
| 166 | - $this->_oid = $oid; |
|
| 167 | - $this->_critical = $critical; |
|
| 168 | - } |
|
| 158 | + /** |
|
| 159 | + * Constructor. |
|
| 160 | + * |
|
| 161 | + * @param string $oid Extension OID |
|
| 162 | + * @param bool $critical Whether extension is critical |
|
| 163 | + */ |
|
| 164 | + public function __construct(string $oid, bool $critical) |
|
| 165 | + { |
|
| 166 | + $this->_oid = $oid; |
|
| 167 | + $this->_critical = $critical; |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | - /** |
|
| 171 | - * Initialize from ASN.1. |
|
| 172 | - * |
|
| 173 | - * @param Sequence $seq |
|
| 174 | - * @return self |
|
| 175 | - */ |
|
| 176 | - public static function fromASN1(Sequence $seq) |
|
| 177 | - { |
|
| 178 | - $extnID = $seq->at(0) |
|
| 179 | - ->asObjectIdentifier() |
|
| 180 | - ->oid(); |
|
| 181 | - $critical = false; |
|
| 182 | - $idx = 1; |
|
| 183 | - if ($seq->has($idx, Element::TYPE_BOOLEAN)) { |
|
| 184 | - $critical = $seq->at($idx++) |
|
| 185 | - ->asBoolean() |
|
| 186 | - ->value(); |
|
| 187 | - } |
|
| 188 | - $data = $seq->at($idx) |
|
| 189 | - ->asOctetString() |
|
| 190 | - ->string(); |
|
| 191 | - if (array_key_exists($extnID, self::MAP_OID_TO_CLASS)) { |
|
| 192 | - $cls = self::MAP_OID_TO_CLASS[$extnID]; |
|
| 193 | - return $cls::_fromDER($data, $critical); |
|
| 194 | - } |
|
| 195 | - return new UnknownExtension($extnID, $critical, new DERData($data)); |
|
| 196 | - } |
|
| 170 | + /** |
|
| 171 | + * Initialize from ASN.1. |
|
| 172 | + * |
|
| 173 | + * @param Sequence $seq |
|
| 174 | + * @return self |
|
| 175 | + */ |
|
| 176 | + public static function fromASN1(Sequence $seq) |
|
| 177 | + { |
|
| 178 | + $extnID = $seq->at(0) |
|
| 179 | + ->asObjectIdentifier() |
|
| 180 | + ->oid(); |
|
| 181 | + $critical = false; |
|
| 182 | + $idx = 1; |
|
| 183 | + if ($seq->has($idx, Element::TYPE_BOOLEAN)) { |
|
| 184 | + $critical = $seq->at($idx++) |
|
| 185 | + ->asBoolean() |
|
| 186 | + ->value(); |
|
| 187 | + } |
|
| 188 | + $data = $seq->at($idx) |
|
| 189 | + ->asOctetString() |
|
| 190 | + ->string(); |
|
| 191 | + if (array_key_exists($extnID, self::MAP_OID_TO_CLASS)) { |
|
| 192 | + $cls = self::MAP_OID_TO_CLASS[$extnID]; |
|
| 193 | + return $cls::_fromDER($data, $critical); |
|
| 194 | + } |
|
| 195 | + return new UnknownExtension($extnID, $critical, new DERData($data)); |
|
| 196 | + } |
|
| 197 | 197 | |
| 198 | - /** |
|
| 199 | - * Get extension OID. |
|
| 200 | - * |
|
| 201 | - * @return string |
|
| 202 | - */ |
|
| 203 | - public function oid(): string |
|
| 204 | - { |
|
| 205 | - return $this->_oid; |
|
| 206 | - } |
|
| 198 | + /** |
|
| 199 | + * Get extension OID. |
|
| 200 | + * |
|
| 201 | + * @return string |
|
| 202 | + */ |
|
| 203 | + public function oid(): string |
|
| 204 | + { |
|
| 205 | + return $this->_oid; |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | - /** |
|
| 209 | - * Check whether extension is critical. |
|
| 210 | - * |
|
| 211 | - * @return bool |
|
| 212 | - */ |
|
| 213 | - public function isCritical(): bool |
|
| 214 | - { |
|
| 215 | - return $this->_critical; |
|
| 216 | - } |
|
| 208 | + /** |
|
| 209 | + * Check whether extension is critical. |
|
| 210 | + * |
|
| 211 | + * @return bool |
|
| 212 | + */ |
|
| 213 | + public function isCritical(): bool |
|
| 214 | + { |
|
| 215 | + return $this->_critical; |
|
| 216 | + } |
|
| 217 | 217 | |
| 218 | - /** |
|
| 219 | - * Generate ASN.1 structure. |
|
| 220 | - * |
|
| 221 | - * @return Sequence |
|
| 222 | - */ |
|
| 223 | - public function toASN1(): Sequence |
|
| 224 | - { |
|
| 225 | - $elements = array(new ObjectIdentifier($this->_oid)); |
|
| 226 | - if ($this->_critical) { |
|
| 227 | - $elements[] = new Boolean(true); |
|
| 228 | - } |
|
| 229 | - $elements[] = new OctetString($this->_valueASN1()->toDER()); |
|
| 230 | - return new Sequence(...$elements); |
|
| 231 | - } |
|
| 218 | + /** |
|
| 219 | + * Generate ASN.1 structure. |
|
| 220 | + * |
|
| 221 | + * @return Sequence |
|
| 222 | + */ |
|
| 223 | + public function toASN1(): Sequence |
|
| 224 | + { |
|
| 225 | + $elements = array(new ObjectIdentifier($this->_oid)); |
|
| 226 | + if ($this->_critical) { |
|
| 227 | + $elements[] = new Boolean(true); |
|
| 228 | + } |
|
| 229 | + $elements[] = new OctetString($this->_valueASN1()->toDER()); |
|
| 230 | + return new Sequence(...$elements); |
|
| 231 | + } |
|
| 232 | 232 | } |
@@ -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; |
| 6 | 6 | |