@@ -15,89 +15,89 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class GeneralSubtrees implements \Countable, \IteratorAggregate |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * Subtrees. |
|
| 20 | - * |
|
| 21 | - * @var GeneralSubtree[] |
|
| 22 | - */ |
|
| 23 | - protected $_subtrees; |
|
| 18 | + /** |
|
| 19 | + * Subtrees. |
|
| 20 | + * |
|
| 21 | + * @var GeneralSubtree[] |
|
| 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 | - * |
|
| 40 | - * @return self |
|
| 41 | - */ |
|
| 42 | - public static function fromASN1(Sequence $seq): self |
|
| 43 | - { |
|
| 44 | - $subtrees = array_map( |
|
| 45 | - function (UnspecifiedType $el) { |
|
| 46 | - return GeneralSubtree::fromASN1($el->asSequence()); |
|
| 47 | - }, $seq->elements()); |
|
| 48 | - if (!count($subtrees)) { |
|
| 49 | - throw new \UnexpectedValueException( |
|
| 50 | - 'GeneralSubtrees must contain at least one GeneralSubtree.'); |
|
| 51 | - } |
|
| 52 | - return new self(...$subtrees); |
|
| 53 | - } |
|
| 35 | + /** |
|
| 36 | + * Initialize from ASN.1. |
|
| 37 | + * |
|
| 38 | + * @param Sequence $seq |
|
| 39 | + * |
|
| 40 | + * @return self |
|
| 41 | + */ |
|
| 42 | + public static function fromASN1(Sequence $seq): self |
|
| 43 | + { |
|
| 44 | + $subtrees = array_map( |
|
| 45 | + function (UnspecifiedType $el) { |
|
| 46 | + return GeneralSubtree::fromASN1($el->asSequence()); |
|
| 47 | + }, $seq->elements()); |
|
| 48 | + if (!count($subtrees)) { |
|
| 49 | + throw new \UnexpectedValueException( |
|
| 50 | + 'GeneralSubtrees must contain at least one GeneralSubtree.'); |
|
| 51 | + } |
|
| 52 | + return new self(...$subtrees); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Get all subtrees. |
|
| 57 | - * |
|
| 58 | - * @return GeneralSubtree[] |
|
| 59 | - */ |
|
| 60 | - public function all(): array |
|
| 61 | - { |
|
| 62 | - return $this->_subtrees; |
|
| 63 | - } |
|
| 55 | + /** |
|
| 56 | + * Get all subtrees. |
|
| 57 | + * |
|
| 58 | + * @return GeneralSubtree[] |
|
| 59 | + */ |
|
| 60 | + public function all(): array |
|
| 61 | + { |
|
| 62 | + return $this->_subtrees; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * Generate ASN.1 structure. |
|
| 67 | - * |
|
| 68 | - * @return Sequence |
|
| 69 | - */ |
|
| 70 | - public function toASN1(): Sequence |
|
| 71 | - { |
|
| 72 | - if (!count($this->_subtrees)) { |
|
| 73 | - throw new \LogicException('No subtrees.'); |
|
| 74 | - } |
|
| 75 | - $elements = array_map( |
|
| 76 | - function (GeneralSubtree $gs) { |
|
| 77 | - return $gs->toASN1(); |
|
| 78 | - }, $this->_subtrees); |
|
| 79 | - return new Sequence(...$elements); |
|
| 80 | - } |
|
| 65 | + /** |
|
| 66 | + * Generate ASN.1 structure. |
|
| 67 | + * |
|
| 68 | + * @return Sequence |
|
| 69 | + */ |
|
| 70 | + public function toASN1(): Sequence |
|
| 71 | + { |
|
| 72 | + if (!count($this->_subtrees)) { |
|
| 73 | + throw new \LogicException('No subtrees.'); |
|
| 74 | + } |
|
| 75 | + $elements = array_map( |
|
| 76 | + function (GeneralSubtree $gs) { |
|
| 77 | + return $gs->toASN1(); |
|
| 78 | + }, $this->_subtrees); |
|
| 79 | + return new Sequence(...$elements); |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * @see \Countable::count() |
|
| 84 | - * |
|
| 85 | - * @return int |
|
| 86 | - */ |
|
| 87 | - public function count(): int |
|
| 88 | - { |
|
| 89 | - return count($this->_subtrees); |
|
| 90 | - } |
|
| 82 | + /** |
|
| 83 | + * @see \Countable::count() |
|
| 84 | + * |
|
| 85 | + * @return int |
|
| 86 | + */ |
|
| 87 | + public function count(): int |
|
| 88 | + { |
|
| 89 | + return count($this->_subtrees); |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * Get iterator for subtrees. |
|
| 94 | - * |
|
| 95 | - * @see \IteratorAggregate::getIterator() |
|
| 96 | - * |
|
| 97 | - * @return \ArrayIterator |
|
| 98 | - */ |
|
| 99 | - public function getIterator(): \ArrayIterator |
|
| 100 | - { |
|
| 101 | - return new \ArrayIterator($this->_subtrees); |
|
| 102 | - } |
|
| 92 | + /** |
|
| 93 | + * Get iterator for subtrees. |
|
| 94 | + * |
|
| 95 | + * @see \IteratorAggregate::getIterator() |
|
| 96 | + * |
|
| 97 | + * @return \ArrayIterator |
|
| 98 | + */ |
|
| 99 | + public function getIterator(): \ArrayIterator |
|
| 100 | + { |
|
| 101 | + return new \ArrayIterator($this->_subtrees); |
|
| 102 | + } |
|
| 103 | 103 | } |
@@ -12,78 +12,78 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class UnknownExtension extends Extension |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * Decoded extension value. |
|
| 17 | - * |
|
| 18 | - * @var null|Element |
|
| 19 | - */ |
|
| 20 | - protected $_element; |
|
| 15 | + /** |
|
| 16 | + * Decoded extension value. |
|
| 17 | + * |
|
| 18 | + * @var null|Element |
|
| 19 | + */ |
|
| 20 | + protected $_element; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Raw extension value. |
|
| 24 | - * |
|
| 25 | - * @var string |
|
| 26 | - */ |
|
| 27 | - protected $_data; |
|
| 22 | + /** |
|
| 23 | + * Raw extension value. |
|
| 24 | + * |
|
| 25 | + * @var string |
|
| 26 | + */ |
|
| 27 | + protected $_data; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Constructor. |
|
| 31 | - * |
|
| 32 | - * @param string $oid |
|
| 33 | - * @param bool $critical |
|
| 34 | - * @param Element $element |
|
| 35 | - */ |
|
| 36 | - public function __construct(string $oid, bool $critical, Element $element) |
|
| 37 | - { |
|
| 38 | - parent::__construct($oid, $critical); |
|
| 39 | - $this->_element = $element; |
|
| 40 | - $this->_data = $element->toDER(); |
|
| 41 | - } |
|
| 29 | + /** |
|
| 30 | + * Constructor. |
|
| 31 | + * |
|
| 32 | + * @param string $oid |
|
| 33 | + * @param bool $critical |
|
| 34 | + * @param Element $element |
|
| 35 | + */ |
|
| 36 | + public function __construct(string $oid, bool $critical, Element $element) |
|
| 37 | + { |
|
| 38 | + parent::__construct($oid, $critical); |
|
| 39 | + $this->_element = $element; |
|
| 40 | + $this->_data = $element->toDER(); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Create instance from a raw encoded extension value. |
|
| 45 | - * |
|
| 46 | - * @param string $oid |
|
| 47 | - * @param bool $critical |
|
| 48 | - * @param string $data |
|
| 49 | - * |
|
| 50 | - * @return self |
|
| 51 | - */ |
|
| 52 | - public static function fromRawString(string $oid, bool $critical, |
|
| 53 | - string $data): self |
|
| 54 | - { |
|
| 55 | - $obj = new self($oid, $critical, new OctetString('')); |
|
| 56 | - $obj->_element = null; |
|
| 57 | - $obj->_data = $data; |
|
| 58 | - return $obj; |
|
| 59 | - } |
|
| 43 | + /** |
|
| 44 | + * Create instance from a raw encoded extension value. |
|
| 45 | + * |
|
| 46 | + * @param string $oid |
|
| 47 | + * @param bool $critical |
|
| 48 | + * @param string $data |
|
| 49 | + * |
|
| 50 | + * @return self |
|
| 51 | + */ |
|
| 52 | + public static function fromRawString(string $oid, bool $critical, |
|
| 53 | + string $data): self |
|
| 54 | + { |
|
| 55 | + $obj = new self($oid, $critical, new OctetString('')); |
|
| 56 | + $obj->_element = null; |
|
| 57 | + $obj->_data = $data; |
|
| 58 | + return $obj; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Get the encoded extension value. |
|
| 63 | - * |
|
| 64 | - * @return string |
|
| 65 | - */ |
|
| 66 | - public function extensionValue(): string |
|
| 67 | - { |
|
| 68 | - return $this->_data; |
|
| 69 | - } |
|
| 61 | + /** |
|
| 62 | + * Get the encoded extension value. |
|
| 63 | + * |
|
| 64 | + * @return string |
|
| 65 | + */ |
|
| 66 | + public function extensionValue(): string |
|
| 67 | + { |
|
| 68 | + return $this->_data; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * {@inheritdoc} |
|
| 73 | - */ |
|
| 74 | - protected function _extnValue(): OctetString |
|
| 75 | - { |
|
| 76 | - return new OctetString($this->_data); |
|
| 77 | - } |
|
| 71 | + /** |
|
| 72 | + * {@inheritdoc} |
|
| 73 | + */ |
|
| 74 | + protected function _extnValue(): OctetString |
|
| 75 | + { |
|
| 76 | + return new OctetString($this->_data); |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * {@inheritdoc} |
|
| 81 | - */ |
|
| 82 | - protected function _valueASN1(): Element |
|
| 83 | - { |
|
| 84 | - if (!isset($this->_element)) { |
|
| 85 | - throw new \RuntimeException('Extension value is not DER encoded.'); |
|
| 86 | - } |
|
| 87 | - return $this->_element; |
|
| 88 | - } |
|
| 79 | + /** |
|
| 80 | + * {@inheritdoc} |
|
| 81 | + */ |
|
| 82 | + protected function _valueASN1(): Element |
|
| 83 | + { |
|
| 84 | + if (!isset($this->_element)) { |
|
| 85 | + throw new \RuntimeException('Extension value is not DER encoded.'); |
|
| 86 | + } |
|
| 87 | + return $this->_element; |
|
| 88 | + } |
|
| 89 | 89 | } |
@@ -9,31 +9,31 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | class AuthorityAccessDescription extends AccessDescription |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * Access method OID's. |
|
| 14 | - * |
|
| 15 | - * @var string |
|
| 16 | - */ |
|
| 17 | - const OID_METHOD_OSCP = '1.3.6.1.5.5.7.48.1'; |
|
| 18 | - const OID_METHOD_CA_ISSUERS = '1.3.6.1.5.5.7.48.2'; |
|
| 12 | + /** |
|
| 13 | + * Access method OID's. |
|
| 14 | + * |
|
| 15 | + * @var string |
|
| 16 | + */ |
|
| 17 | + const OID_METHOD_OSCP = '1.3.6.1.5.5.7.48.1'; |
|
| 18 | + const OID_METHOD_CA_ISSUERS = '1.3.6.1.5.5.7.48.2'; |
|
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Check whether access method is OSCP. |
|
| 22 | - * |
|
| 23 | - * @return bool |
|
| 24 | - */ |
|
| 25 | - public function isOSCPMethod(): bool |
|
| 26 | - { |
|
| 27 | - return self::OID_METHOD_OSCP === $this->_accessMethod; |
|
| 28 | - } |
|
| 20 | + /** |
|
| 21 | + * Check whether access method is OSCP. |
|
| 22 | + * |
|
| 23 | + * @return bool |
|
| 24 | + */ |
|
| 25 | + public function isOSCPMethod(): bool |
|
| 26 | + { |
|
| 27 | + return self::OID_METHOD_OSCP === $this->_accessMethod; |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Check whether access method is CA issuers. |
|
| 32 | - * |
|
| 33 | - * @return bool |
|
| 34 | - */ |
|
| 35 | - public function isCAIssuersMethod(): bool |
|
| 36 | - { |
|
| 37 | - return self::OID_METHOD_CA_ISSUERS === $this->_accessMethod; |
|
| 38 | - } |
|
| 30 | + /** |
|
| 31 | + * Check whether access method is CA issuers. |
|
| 32 | + * |
|
| 33 | + * @return bool |
|
| 34 | + */ |
|
| 35 | + public function isCAIssuersMethod(): bool |
|
| 36 | + { |
|
| 37 | + return self::OID_METHOD_CA_ISSUERS === $this->_accessMethod; |
|
| 38 | + } |
|
| 39 | 39 | } |
@@ -9,31 +9,31 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | class SubjectAccessDescription extends AccessDescription |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * Access method OID's. |
|
| 14 | - * |
|
| 15 | - * @var string |
|
| 16 | - */ |
|
| 17 | - const OID_METHOD_TIME_STAMPING = '1.3.6.1.5.5.7.48.3'; |
|
| 18 | - const OID_METHOD_CA_REPOSITORY = '1.3.6.1.5.5.7.48.5'; |
|
| 12 | + /** |
|
| 13 | + * Access method OID's. |
|
| 14 | + * |
|
| 15 | + * @var string |
|
| 16 | + */ |
|
| 17 | + const OID_METHOD_TIME_STAMPING = '1.3.6.1.5.5.7.48.3'; |
|
| 18 | + const OID_METHOD_CA_REPOSITORY = '1.3.6.1.5.5.7.48.5'; |
|
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Check whether access method is time stamping. |
|
| 22 | - * |
|
| 23 | - * @return bool |
|
| 24 | - */ |
|
| 25 | - public function isTimeStampingMethod(): bool |
|
| 26 | - { |
|
| 27 | - return self::OID_METHOD_TIME_STAMPING === $this->_accessMethod; |
|
| 28 | - } |
|
| 20 | + /** |
|
| 21 | + * Check whether access method is time stamping. |
|
| 22 | + * |
|
| 23 | + * @return bool |
|
| 24 | + */ |
|
| 25 | + public function isTimeStampingMethod(): bool |
|
| 26 | + { |
|
| 27 | + return self::OID_METHOD_TIME_STAMPING === $this->_accessMethod; |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Check whether access method is CA repository. |
|
| 32 | - * |
|
| 33 | - * @return bool |
|
| 34 | - */ |
|
| 35 | - public function isCARepositoryMethod(): bool |
|
| 36 | - { |
|
| 37 | - return self::OID_METHOD_CA_REPOSITORY === $this->_accessMethod; |
|
| 38 | - } |
|
| 30 | + /** |
|
| 31 | + * Check whether access method is CA repository. |
|
| 32 | + * |
|
| 33 | + * @return bool |
|
| 34 | + */ |
|
| 35 | + public function isCARepositoryMethod(): bool |
|
| 36 | + { |
|
| 37 | + return self::OID_METHOD_CA_REPOSITORY === $this->_accessMethod; |
|
| 38 | + } |
|
| 39 | 39 | } |
@@ -17,73 +17,73 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | abstract class AccessDescription |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * Access method OID. |
|
| 22 | - * |
|
| 23 | - * @var string |
|
| 24 | - */ |
|
| 25 | - protected $_accessMethod; |
|
| 20 | + /** |
|
| 21 | + * Access method OID. |
|
| 22 | + * |
|
| 23 | + * @var string |
|
| 24 | + */ |
|
| 25 | + protected $_accessMethod; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Access location. |
|
| 29 | - * |
|
| 30 | - * @var GeneralName |
|
| 31 | - */ |
|
| 32 | - protected $_accessLocation; |
|
| 27 | + /** |
|
| 28 | + * Access location. |
|
| 29 | + * |
|
| 30 | + * @var GeneralName |
|
| 31 | + */ |
|
| 32 | + protected $_accessLocation; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Constructor. |
|
| 36 | - * |
|
| 37 | - * @param string $method Access method OID |
|
| 38 | - * @param GeneralName $location Access location |
|
| 39 | - */ |
|
| 40 | - public function __construct(string $method, GeneralName $location) |
|
| 41 | - { |
|
| 42 | - $this->_accessMethod = $method; |
|
| 43 | - $this->_accessLocation = $location; |
|
| 44 | - } |
|
| 34 | + /** |
|
| 35 | + * Constructor. |
|
| 36 | + * |
|
| 37 | + * @param string $method Access method OID |
|
| 38 | + * @param GeneralName $location Access location |
|
| 39 | + */ |
|
| 40 | + public function __construct(string $method, GeneralName $location) |
|
| 41 | + { |
|
| 42 | + $this->_accessMethod = $method; |
|
| 43 | + $this->_accessLocation = $location; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Initialize from ASN.1. |
|
| 48 | - * |
|
| 49 | - * @param Sequence $seq |
|
| 50 | - * |
|
| 51 | - * @return self |
|
| 52 | - */ |
|
| 53 | - public static function fromASN1(Sequence $seq): self |
|
| 54 | - { |
|
| 55 | - return new static($seq->at(0)->asObjectIdentifier()->oid(), |
|
| 56 | - GeneralName::fromASN1($seq->at(1)->asTagged())); |
|
| 57 | - } |
|
| 46 | + /** |
|
| 47 | + * Initialize from ASN.1. |
|
| 48 | + * |
|
| 49 | + * @param Sequence $seq |
|
| 50 | + * |
|
| 51 | + * @return self |
|
| 52 | + */ |
|
| 53 | + public static function fromASN1(Sequence $seq): self |
|
| 54 | + { |
|
| 55 | + return new static($seq->at(0)->asObjectIdentifier()->oid(), |
|
| 56 | + GeneralName::fromASN1($seq->at(1)->asTagged())); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Get the access method OID. |
|
| 61 | - * |
|
| 62 | - * @return string |
|
| 63 | - */ |
|
| 64 | - public function accessMethod(): string |
|
| 65 | - { |
|
| 66 | - return $this->_accessMethod; |
|
| 67 | - } |
|
| 59 | + /** |
|
| 60 | + * Get the access method OID. |
|
| 61 | + * |
|
| 62 | + * @return string |
|
| 63 | + */ |
|
| 64 | + public function accessMethod(): string |
|
| 65 | + { |
|
| 66 | + return $this->_accessMethod; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * Get the access location. |
|
| 71 | - * |
|
| 72 | - * @return GeneralName |
|
| 73 | - */ |
|
| 74 | - public function accessLocation(): GeneralName |
|
| 75 | - { |
|
| 76 | - return $this->_accessLocation; |
|
| 77 | - } |
|
| 69 | + /** |
|
| 70 | + * Get the access location. |
|
| 71 | + * |
|
| 72 | + * @return GeneralName |
|
| 73 | + */ |
|
| 74 | + public function accessLocation(): GeneralName |
|
| 75 | + { |
|
| 76 | + return $this->_accessLocation; |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * Generate ASN.1 structure. |
|
| 81 | - * |
|
| 82 | - * @return Sequence |
|
| 83 | - */ |
|
| 84 | - public function toASN1(): Sequence |
|
| 85 | - { |
|
| 86 | - return new Sequence(new ObjectIdentifier($this->_accessMethod), |
|
| 87 | - $this->_accessLocation->toASN1()); |
|
| 88 | - } |
|
| 79 | + /** |
|
| 80 | + * Generate ASN.1 structure. |
|
| 81 | + * |
|
| 82 | + * @return Sequence |
|
| 83 | + */ |
|
| 84 | + public function toASN1(): Sequence |
|
| 85 | + { |
|
| 86 | + return new Sequence(new ObjectIdentifier($this->_accessMethod), |
|
| 87 | + $this->_accessLocation->toASN1()); |
|
| 88 | + } |
|
| 89 | 89 | } |
@@ -13,16 +13,16 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class FreshestCRLExtension extends CRLDistributionPointsExtension |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * Constructor. |
|
| 18 | - * |
|
| 19 | - * @param bool $critical |
|
| 20 | - * @param DistributionPoint ...$distribution_points |
|
| 21 | - */ |
|
| 22 | - public function __construct(bool $critical, |
|
| 23 | - DistributionPoint ...$distribution_points) |
|
| 24 | - { |
|
| 25 | - Extension::__construct(self::OID_FRESHEST_CRL, $critical); |
|
| 26 | - $this->_distributionPoints = $distribution_points; |
|
| 27 | - } |
|
| 16 | + /** |
|
| 17 | + * Constructor. |
|
| 18 | + * |
|
| 19 | + * @param bool $critical |
|
| 20 | + * @param DistributionPoint ...$distribution_points |
|
| 21 | + */ |
|
| 22 | + public function __construct(bool $critical, |
|
| 23 | + DistributionPoint ...$distribution_points) |
|
| 24 | + { |
|
| 25 | + Extension::__construct(self::OID_FRESHEST_CRL, $critical); |
|
| 26 | + $this->_distributionPoints = $distribution_points; |
|
| 27 | + } |
|
| 28 | 28 | } |
@@ -16,134 +16,134 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class CertificatePoliciesExtension extends Extension implements \Countable, \IteratorAggregate |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * Policy information terms. |
|
| 21 | - * |
|
| 22 | - * @var PolicyInformation[] |
|
| 23 | - */ |
|
| 24 | - protected $_policies; |
|
| 19 | + /** |
|
| 20 | + * Policy information terms. |
|
| 21 | + * |
|
| 22 | + * @var PolicyInformation[] |
|
| 23 | + */ |
|
| 24 | + protected $_policies; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Constructor. |
|
| 28 | - * |
|
| 29 | - * @param bool $critical |
|
| 30 | - * @param PolicyInformation ...$policies |
|
| 31 | - */ |
|
| 32 | - public function __construct(bool $critical, PolicyInformation ...$policies) |
|
| 33 | - { |
|
| 34 | - parent::__construct(Extension::OID_CERTIFICATE_POLICIES, $critical); |
|
| 35 | - $this->_policies = []; |
|
| 36 | - foreach ($policies as $policy) { |
|
| 37 | - $this->_policies[$policy->oid()] = $policy; |
|
| 38 | - } |
|
| 39 | - } |
|
| 26 | + /** |
|
| 27 | + * Constructor. |
|
| 28 | + * |
|
| 29 | + * @param bool $critical |
|
| 30 | + * @param PolicyInformation ...$policies |
|
| 31 | + */ |
|
| 32 | + public function __construct(bool $critical, PolicyInformation ...$policies) |
|
| 33 | + { |
|
| 34 | + parent::__construct(Extension::OID_CERTIFICATE_POLICIES, $critical); |
|
| 35 | + $this->_policies = []; |
|
| 36 | + foreach ($policies as $policy) { |
|
| 37 | + $this->_policies[$policy->oid()] = $policy; |
|
| 38 | + } |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Check whether policy information by OID is present. |
|
| 43 | - * |
|
| 44 | - * @param string $oid |
|
| 45 | - * |
|
| 46 | - * @return bool |
|
| 47 | - */ |
|
| 48 | - public function has(string $oid): bool |
|
| 49 | - { |
|
| 50 | - return isset($this->_policies[$oid]); |
|
| 51 | - } |
|
| 41 | + /** |
|
| 42 | + * Check whether policy information by OID is present. |
|
| 43 | + * |
|
| 44 | + * @param string $oid |
|
| 45 | + * |
|
| 46 | + * @return bool |
|
| 47 | + */ |
|
| 48 | + public function has(string $oid): bool |
|
| 49 | + { |
|
| 50 | + return isset($this->_policies[$oid]); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Get policy information by OID. |
|
| 55 | - * |
|
| 56 | - * @param string $oid |
|
| 57 | - * |
|
| 58 | - * @throws \LogicException If not set |
|
| 59 | - * |
|
| 60 | - * @return PolicyInformation |
|
| 61 | - */ |
|
| 62 | - public function get(string $oid): PolicyInformation |
|
| 63 | - { |
|
| 64 | - if (!$this->has($oid)) { |
|
| 65 | - throw new \LogicException("Not certificate policy by OID {$oid}."); |
|
| 66 | - } |
|
| 67 | - return $this->_policies[$oid]; |
|
| 68 | - } |
|
| 53 | + /** |
|
| 54 | + * Get policy information by OID. |
|
| 55 | + * |
|
| 56 | + * @param string $oid |
|
| 57 | + * |
|
| 58 | + * @throws \LogicException If not set |
|
| 59 | + * |
|
| 60 | + * @return PolicyInformation |
|
| 61 | + */ |
|
| 62 | + public function get(string $oid): PolicyInformation |
|
| 63 | + { |
|
| 64 | + if (!$this->has($oid)) { |
|
| 65 | + throw new \LogicException("Not certificate policy by OID {$oid}."); |
|
| 66 | + } |
|
| 67 | + return $this->_policies[$oid]; |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * Check whether anyPolicy is present. |
|
| 72 | - * |
|
| 73 | - * @return bool |
|
| 74 | - */ |
|
| 75 | - public function hasAnyPolicy(): bool |
|
| 76 | - { |
|
| 77 | - return $this->has(PolicyInformation::OID_ANY_POLICY); |
|
| 78 | - } |
|
| 70 | + /** |
|
| 71 | + * Check whether anyPolicy is present. |
|
| 72 | + * |
|
| 73 | + * @return bool |
|
| 74 | + */ |
|
| 75 | + public function hasAnyPolicy(): bool |
|
| 76 | + { |
|
| 77 | + return $this->has(PolicyInformation::OID_ANY_POLICY); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * Get anyPolicy information. |
|
| 82 | - * |
|
| 83 | - * @throws \LogicException if anyPolicy is not present |
|
| 84 | - * |
|
| 85 | - * @return PolicyInformation |
|
| 86 | - */ |
|
| 87 | - public function anyPolicy(): PolicyInformation |
|
| 88 | - { |
|
| 89 | - if (!$this->hasAnyPolicy()) { |
|
| 90 | - throw new \LogicException('No anyPolicy.'); |
|
| 91 | - } |
|
| 92 | - return $this->get(PolicyInformation::OID_ANY_POLICY); |
|
| 93 | - } |
|
| 80 | + /** |
|
| 81 | + * Get anyPolicy information. |
|
| 82 | + * |
|
| 83 | + * @throws \LogicException if anyPolicy is not present |
|
| 84 | + * |
|
| 85 | + * @return PolicyInformation |
|
| 86 | + */ |
|
| 87 | + public function anyPolicy(): PolicyInformation |
|
| 88 | + { |
|
| 89 | + if (!$this->hasAnyPolicy()) { |
|
| 90 | + throw new \LogicException('No anyPolicy.'); |
|
| 91 | + } |
|
| 92 | + return $this->get(PolicyInformation::OID_ANY_POLICY); |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * Get the number of policies. |
|
| 97 | - * |
|
| 98 | - * @see \Countable::count() |
|
| 99 | - * |
|
| 100 | - * @return int |
|
| 101 | - */ |
|
| 102 | - public function count(): int |
|
| 103 | - { |
|
| 104 | - return count($this->_policies); |
|
| 105 | - } |
|
| 95 | + /** |
|
| 96 | + * Get the number of policies. |
|
| 97 | + * |
|
| 98 | + * @see \Countable::count() |
|
| 99 | + * |
|
| 100 | + * @return int |
|
| 101 | + */ |
|
| 102 | + public function count(): int |
|
| 103 | + { |
|
| 104 | + return count($this->_policies); |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * Get iterator for policy information terms. |
|
| 109 | - * |
|
| 110 | - * @see \IteratorAggregate::getIterator() |
|
| 111 | - * |
|
| 112 | - * @return \ArrayIterator |
|
| 113 | - */ |
|
| 114 | - public function getIterator(): \ArrayIterator |
|
| 115 | - { |
|
| 116 | - return new \ArrayIterator($this->_policies); |
|
| 117 | - } |
|
| 107 | + /** |
|
| 108 | + * Get iterator for policy information terms. |
|
| 109 | + * |
|
| 110 | + * @see \IteratorAggregate::getIterator() |
|
| 111 | + * |
|
| 112 | + * @return \ArrayIterator |
|
| 113 | + */ |
|
| 114 | + public function getIterator(): \ArrayIterator |
|
| 115 | + { |
|
| 116 | + return new \ArrayIterator($this->_policies); |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - /** |
|
| 120 | - * {@inheritdoc} |
|
| 121 | - */ |
|
| 122 | - protected static function _fromDER(string $data, bool $critical): Extension |
|
| 123 | - { |
|
| 124 | - $policies = array_map( |
|
| 125 | - function (UnspecifiedType $el) { |
|
| 126 | - return PolicyInformation::fromASN1($el->asSequence()); |
|
| 127 | - }, UnspecifiedType::fromDER($data)->asSequence()->elements()); |
|
| 128 | - if (!count($policies)) { |
|
| 129 | - throw new \UnexpectedValueException( |
|
| 130 | - 'certificatePolicies must contain at least one PolicyInformation.'); |
|
| 131 | - } |
|
| 132 | - return new self($critical, ...$policies); |
|
| 133 | - } |
|
| 119 | + /** |
|
| 120 | + * {@inheritdoc} |
|
| 121 | + */ |
|
| 122 | + protected static function _fromDER(string $data, bool $critical): Extension |
|
| 123 | + { |
|
| 124 | + $policies = array_map( |
|
| 125 | + function (UnspecifiedType $el) { |
|
| 126 | + return PolicyInformation::fromASN1($el->asSequence()); |
|
| 127 | + }, UnspecifiedType::fromDER($data)->asSequence()->elements()); |
|
| 128 | + if (!count($policies)) { |
|
| 129 | + throw new \UnexpectedValueException( |
|
| 130 | + 'certificatePolicies must contain at least one PolicyInformation.'); |
|
| 131 | + } |
|
| 132 | + return new self($critical, ...$policies); |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - /** |
|
| 136 | - * {@inheritdoc} |
|
| 137 | - */ |
|
| 138 | - protected function _valueASN1(): Element |
|
| 139 | - { |
|
| 140 | - if (!count($this->_policies)) { |
|
| 141 | - throw new \LogicException('No policies.'); |
|
| 142 | - } |
|
| 143 | - $elements = array_map( |
|
| 144 | - function (PolicyInformation $pi) { |
|
| 145 | - return $pi->toASN1(); |
|
| 146 | - }, array_values($this->_policies)); |
|
| 147 | - return new Sequence(...$elements); |
|
| 148 | - } |
|
| 135 | + /** |
|
| 136 | + * {@inheritdoc} |
|
| 137 | + */ |
|
| 138 | + protected function _valueASN1(): Element |
|
| 139 | + { |
|
| 140 | + if (!count($this->_policies)) { |
|
| 141 | + throw new \LogicException('No policies.'); |
|
| 142 | + } |
|
| 143 | + $elements = array_map( |
|
| 144 | + function (PolicyInformation $pi) { |
|
| 145 | + return $pi->toASN1(); |
|
| 146 | + }, array_values($this->_policies)); |
|
| 147 | + return new Sequence(...$elements); |
|
| 148 | + } |
|
| 149 | 149 | } |
@@ -17,114 +17,114 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class PolicyConstraintsExtension extends Extension |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * @var null|int |
|
| 22 | - */ |
|
| 23 | - protected $_requireExplicitPolicy; |
|
| 20 | + /** |
|
| 21 | + * @var null|int |
|
| 22 | + */ |
|
| 23 | + protected $_requireExplicitPolicy; |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @var null|int |
|
| 27 | - */ |
|
| 28 | - protected $_inhibitPolicyMapping; |
|
| 25 | + /** |
|
| 26 | + * @var null|int |
|
| 27 | + */ |
|
| 28 | + protected $_inhibitPolicyMapping; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Constructor. |
|
| 32 | - * |
|
| 33 | - * @param bool $critical |
|
| 34 | - * @param null|int $require_explicit_policy |
|
| 35 | - * @param null|int $inhibit_policy_mapping |
|
| 36 | - */ |
|
| 37 | - public function __construct(bool $critical, |
|
| 38 | - ?int $require_explicit_policy = null, ?int $inhibit_policy_mapping = null) |
|
| 39 | - { |
|
| 40 | - parent::__construct(self::OID_POLICY_CONSTRAINTS, $critical); |
|
| 41 | - $this->_requireExplicitPolicy = $require_explicit_policy; |
|
| 42 | - $this->_inhibitPolicyMapping = $inhibit_policy_mapping; |
|
| 43 | - } |
|
| 30 | + /** |
|
| 31 | + * Constructor. |
|
| 32 | + * |
|
| 33 | + * @param bool $critical |
|
| 34 | + * @param null|int $require_explicit_policy |
|
| 35 | + * @param null|int $inhibit_policy_mapping |
|
| 36 | + */ |
|
| 37 | + public function __construct(bool $critical, |
|
| 38 | + ?int $require_explicit_policy = null, ?int $inhibit_policy_mapping = null) |
|
| 39 | + { |
|
| 40 | + parent::__construct(self::OID_POLICY_CONSTRAINTS, $critical); |
|
| 41 | + $this->_requireExplicitPolicy = $require_explicit_policy; |
|
| 42 | + $this->_inhibitPolicyMapping = $inhibit_policy_mapping; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Whether requireExplicitPolicy is present. |
|
| 47 | - * |
|
| 48 | - * @return bool |
|
| 49 | - */ |
|
| 50 | - public function hasRequireExplicitPolicy(): bool |
|
| 51 | - { |
|
| 52 | - return isset($this->_requireExplicitPolicy); |
|
| 53 | - } |
|
| 45 | + /** |
|
| 46 | + * Whether requireExplicitPolicy is present. |
|
| 47 | + * |
|
| 48 | + * @return bool |
|
| 49 | + */ |
|
| 50 | + public function hasRequireExplicitPolicy(): bool |
|
| 51 | + { |
|
| 52 | + return isset($this->_requireExplicitPolicy); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Get requireExplicitPolicy. |
|
| 57 | - * |
|
| 58 | - * @throws \LogicException If not set |
|
| 59 | - * |
|
| 60 | - * @return int |
|
| 61 | - */ |
|
| 62 | - public function requireExplicitPolicy(): int |
|
| 63 | - { |
|
| 64 | - if (!$this->hasRequireExplicitPolicy()) { |
|
| 65 | - throw new \LogicException('requireExplicitPolicy not set.'); |
|
| 66 | - } |
|
| 67 | - return $this->_requireExplicitPolicy; |
|
| 68 | - } |
|
| 55 | + /** |
|
| 56 | + * Get requireExplicitPolicy. |
|
| 57 | + * |
|
| 58 | + * @throws \LogicException If not set |
|
| 59 | + * |
|
| 60 | + * @return int |
|
| 61 | + */ |
|
| 62 | + public function requireExplicitPolicy(): int |
|
| 63 | + { |
|
| 64 | + if (!$this->hasRequireExplicitPolicy()) { |
|
| 65 | + throw new \LogicException('requireExplicitPolicy not set.'); |
|
| 66 | + } |
|
| 67 | + return $this->_requireExplicitPolicy; |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * Whether inhibitPolicyMapping is present. |
|
| 72 | - * |
|
| 73 | - * @return bool |
|
| 74 | - */ |
|
| 75 | - public function hasInhibitPolicyMapping(): bool |
|
| 76 | - { |
|
| 77 | - return isset($this->_inhibitPolicyMapping); |
|
| 78 | - } |
|
| 70 | + /** |
|
| 71 | + * Whether inhibitPolicyMapping is present. |
|
| 72 | + * |
|
| 73 | + * @return bool |
|
| 74 | + */ |
|
| 75 | + public function hasInhibitPolicyMapping(): bool |
|
| 76 | + { |
|
| 77 | + return isset($this->_inhibitPolicyMapping); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * Get inhibitPolicyMapping. |
|
| 82 | - * |
|
| 83 | - * @throws \LogicException If not set |
|
| 84 | - * |
|
| 85 | - * @return int |
|
| 86 | - */ |
|
| 87 | - public function inhibitPolicyMapping(): int |
|
| 88 | - { |
|
| 89 | - if (!$this->hasInhibitPolicyMapping()) { |
|
| 90 | - throw new \LogicException('inhibitPolicyMapping not set.'); |
|
| 91 | - } |
|
| 92 | - return $this->_inhibitPolicyMapping; |
|
| 93 | - } |
|
| 80 | + /** |
|
| 81 | + * Get inhibitPolicyMapping. |
|
| 82 | + * |
|
| 83 | + * @throws \LogicException If not set |
|
| 84 | + * |
|
| 85 | + * @return int |
|
| 86 | + */ |
|
| 87 | + public function inhibitPolicyMapping(): int |
|
| 88 | + { |
|
| 89 | + if (!$this->hasInhibitPolicyMapping()) { |
|
| 90 | + throw new \LogicException('inhibitPolicyMapping not set.'); |
|
| 91 | + } |
|
| 92 | + return $this->_inhibitPolicyMapping; |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * {@inheritdoc} |
|
| 97 | - */ |
|
| 98 | - protected static function _fromDER(string $data, bool $critical): Extension |
|
| 99 | - { |
|
| 100 | - $seq = UnspecifiedType::fromDER($data)->asSequence(); |
|
| 101 | - $require_explicit_policy = null; |
|
| 102 | - $inhibit_policy_mapping = null; |
|
| 103 | - if ($seq->hasTagged(0)) { |
|
| 104 | - $require_explicit_policy = $seq->getTagged(0) |
|
| 105 | - ->asImplicit(Element::TYPE_INTEGER)->asInteger()->intNumber(); |
|
| 106 | - } |
|
| 107 | - if ($seq->hasTagged(1)) { |
|
| 108 | - $inhibit_policy_mapping = $seq->getTagged(1) |
|
| 109 | - ->asImplicit(Element::TYPE_INTEGER)->asInteger()->intNumber(); |
|
| 110 | - } |
|
| 111 | - return new self($critical, $require_explicit_policy, $inhibit_policy_mapping); |
|
| 112 | - } |
|
| 95 | + /** |
|
| 96 | + * {@inheritdoc} |
|
| 97 | + */ |
|
| 98 | + protected static function _fromDER(string $data, bool $critical): Extension |
|
| 99 | + { |
|
| 100 | + $seq = UnspecifiedType::fromDER($data)->asSequence(); |
|
| 101 | + $require_explicit_policy = null; |
|
| 102 | + $inhibit_policy_mapping = null; |
|
| 103 | + if ($seq->hasTagged(0)) { |
|
| 104 | + $require_explicit_policy = $seq->getTagged(0) |
|
| 105 | + ->asImplicit(Element::TYPE_INTEGER)->asInteger()->intNumber(); |
|
| 106 | + } |
|
| 107 | + if ($seq->hasTagged(1)) { |
|
| 108 | + $inhibit_policy_mapping = $seq->getTagged(1) |
|
| 109 | + ->asImplicit(Element::TYPE_INTEGER)->asInteger()->intNumber(); |
|
| 110 | + } |
|
| 111 | + return new self($critical, $require_explicit_policy, $inhibit_policy_mapping); |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - /** |
|
| 115 | - * {@inheritdoc} |
|
| 116 | - */ |
|
| 117 | - protected function _valueASN1(): Element |
|
| 118 | - { |
|
| 119 | - $elements = []; |
|
| 120 | - if (isset($this->_requireExplicitPolicy)) { |
|
| 121 | - $elements[] = new ImplicitlyTaggedType(0, |
|
| 122 | - new Integer($this->_requireExplicitPolicy)); |
|
| 123 | - } |
|
| 124 | - if (isset($this->_inhibitPolicyMapping)) { |
|
| 125 | - $elements[] = new ImplicitlyTaggedType(1, |
|
| 126 | - new Integer($this->_inhibitPolicyMapping)); |
|
| 127 | - } |
|
| 128 | - return new Sequence(...$elements); |
|
| 129 | - } |
|
| 114 | + /** |
|
| 115 | + * {@inheritdoc} |
|
| 116 | + */ |
|
| 117 | + protected function _valueASN1(): Element |
|
| 118 | + { |
|
| 119 | + $elements = []; |
|
| 120 | + if (isset($this->_requireExplicitPolicy)) { |
|
| 121 | + $elements[] = new ImplicitlyTaggedType(0, |
|
| 122 | + new Integer($this->_requireExplicitPolicy)); |
|
| 123 | + } |
|
| 124 | + if (isset($this->_inhibitPolicyMapping)) { |
|
| 125 | + $elements[] = new ImplicitlyTaggedType(1, |
|
| 126 | + new Integer($this->_inhibitPolicyMapping)); |
|
| 127 | + } |
|
| 128 | + return new Sequence(...$elements); |
|
| 129 | + } |
|
| 130 | 130 | } |
@@ -20,176 +20,176 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | class AuthorityKeyIdentifierExtension extends Extension |
| 22 | 22 | { |
| 23 | - /** |
|
| 24 | - * Key identifier. |
|
| 25 | - * |
|
| 26 | - * @var null|string |
|
| 27 | - */ |
|
| 28 | - protected $_keyIdentifier; |
|
| 23 | + /** |
|
| 24 | + * Key identifier. |
|
| 25 | + * |
|
| 26 | + * @var null|string |
|
| 27 | + */ |
|
| 28 | + protected $_keyIdentifier; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Issuer name. |
|
| 32 | - * |
|
| 33 | - * @var null|GeneralNames |
|
| 34 | - */ |
|
| 35 | - protected $_authorityCertIssuer; |
|
| 30 | + /** |
|
| 31 | + * Issuer name. |
|
| 32 | + * |
|
| 33 | + * @var null|GeneralNames |
|
| 34 | + */ |
|
| 35 | + protected $_authorityCertIssuer; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Issuer serial number as a base 10 integer. |
|
| 39 | - * |
|
| 40 | - * @var null|string |
|
| 41 | - */ |
|
| 42 | - protected $_authorityCertSerialNumber; |
|
| 37 | + /** |
|
| 38 | + * Issuer serial number as a base 10 integer. |
|
| 39 | + * |
|
| 40 | + * @var null|string |
|
| 41 | + */ |
|
| 42 | + protected $_authorityCertSerialNumber; |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Constructor. |
|
| 46 | - * |
|
| 47 | - * @param bool $critical Conforming CA's must mark as non-critical (false) |
|
| 48 | - * @param null|string $keyIdentifier Key identifier |
|
| 49 | - * @param null|GeneralNames $issuer Issuer name |
|
| 50 | - * @param null|int|string $serial Issuer serial number as a base 10 integer |
|
| 51 | - */ |
|
| 52 | - public function __construct(bool $critical, ?string $keyIdentifier, |
|
| 53 | - ?GeneralNames $issuer = null, $serial = null) |
|
| 54 | - { |
|
| 55 | - parent::__construct(self::OID_AUTHORITY_KEY_IDENTIFIER, $critical); |
|
| 56 | - $this->_keyIdentifier = $keyIdentifier; |
|
| 57 | - $this->_authorityCertIssuer = $issuer; |
|
| 58 | - $this->_authorityCertSerialNumber = isset($serial) ? strval($serial) : null; |
|
| 59 | - } |
|
| 44 | + /** |
|
| 45 | + * Constructor. |
|
| 46 | + * |
|
| 47 | + * @param bool $critical Conforming CA's must mark as non-critical (false) |
|
| 48 | + * @param null|string $keyIdentifier Key identifier |
|
| 49 | + * @param null|GeneralNames $issuer Issuer name |
|
| 50 | + * @param null|int|string $serial Issuer serial number as a base 10 integer |
|
| 51 | + */ |
|
| 52 | + public function __construct(bool $critical, ?string $keyIdentifier, |
|
| 53 | + ?GeneralNames $issuer = null, $serial = null) |
|
| 54 | + { |
|
| 55 | + parent::__construct(self::OID_AUTHORITY_KEY_IDENTIFIER, $critical); |
|
| 56 | + $this->_keyIdentifier = $keyIdentifier; |
|
| 57 | + $this->_authorityCertIssuer = $issuer; |
|
| 58 | + $this->_authorityCertSerialNumber = isset($serial) ? strval($serial) : null; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Create from public key info. |
|
| 63 | - * |
|
| 64 | - * @param PublicKeyInfo $pki |
|
| 65 | - * |
|
| 66 | - * @return AuthorityKeyIdentifierExtension |
|
| 67 | - */ |
|
| 68 | - public static function fromPublicKeyInfo(PublicKeyInfo $pki): self |
|
| 69 | - { |
|
| 70 | - return new self(false, $pki->keyIdentifier()); |
|
| 71 | - } |
|
| 61 | + /** |
|
| 62 | + * Create from public key info. |
|
| 63 | + * |
|
| 64 | + * @param PublicKeyInfo $pki |
|
| 65 | + * |
|
| 66 | + * @return AuthorityKeyIdentifierExtension |
|
| 67 | + */ |
|
| 68 | + public static function fromPublicKeyInfo(PublicKeyInfo $pki): self |
|
| 69 | + { |
|
| 70 | + return new self(false, $pki->keyIdentifier()); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * Whether key identifier is present. |
|
| 75 | - * |
|
| 76 | - * @return bool |
|
| 77 | - */ |
|
| 78 | - public function hasKeyIdentifier(): bool |
|
| 79 | - { |
|
| 80 | - return isset($this->_keyIdentifier); |
|
| 81 | - } |
|
| 73 | + /** |
|
| 74 | + * Whether key identifier is present. |
|
| 75 | + * |
|
| 76 | + * @return bool |
|
| 77 | + */ |
|
| 78 | + public function hasKeyIdentifier(): bool |
|
| 79 | + { |
|
| 80 | + return isset($this->_keyIdentifier); |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * Get key identifier. |
|
| 85 | - * |
|
| 86 | - * @throws \LogicException If not set |
|
| 87 | - * |
|
| 88 | - * @return string |
|
| 89 | - */ |
|
| 90 | - public function keyIdentifier(): string |
|
| 91 | - { |
|
| 92 | - if (!$this->hasKeyIdentifier()) { |
|
| 93 | - throw new \LogicException('keyIdentifier not set.'); |
|
| 94 | - } |
|
| 95 | - return $this->_keyIdentifier; |
|
| 96 | - } |
|
| 83 | + /** |
|
| 84 | + * Get key identifier. |
|
| 85 | + * |
|
| 86 | + * @throws \LogicException If not set |
|
| 87 | + * |
|
| 88 | + * @return string |
|
| 89 | + */ |
|
| 90 | + public function keyIdentifier(): string |
|
| 91 | + { |
|
| 92 | + if (!$this->hasKeyIdentifier()) { |
|
| 93 | + throw new \LogicException('keyIdentifier not set.'); |
|
| 94 | + } |
|
| 95 | + return $this->_keyIdentifier; |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * Whether issuer is present. |
|
| 100 | - * |
|
| 101 | - * @return bool |
|
| 102 | - */ |
|
| 103 | - public function hasIssuer(): bool |
|
| 104 | - { |
|
| 105 | - return isset($this->_authorityCertIssuer); |
|
| 106 | - } |
|
| 98 | + /** |
|
| 99 | + * Whether issuer is present. |
|
| 100 | + * |
|
| 101 | + * @return bool |
|
| 102 | + */ |
|
| 103 | + public function hasIssuer(): bool |
|
| 104 | + { |
|
| 105 | + return isset($this->_authorityCertIssuer); |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * Get issuer. |
|
| 110 | - * |
|
| 111 | - * @throws \LogicException If not set |
|
| 112 | - * |
|
| 113 | - * @return GeneralNames |
|
| 114 | - */ |
|
| 115 | - public function issuer(): GeneralNames |
|
| 116 | - { |
|
| 117 | - if (!$this->hasIssuer()) { |
|
| 118 | - throw new \LogicException('authorityCertIssuer not set.'); |
|
| 119 | - } |
|
| 120 | - return $this->_authorityCertIssuer; |
|
| 121 | - } |
|
| 108 | + /** |
|
| 109 | + * Get issuer. |
|
| 110 | + * |
|
| 111 | + * @throws \LogicException If not set |
|
| 112 | + * |
|
| 113 | + * @return GeneralNames |
|
| 114 | + */ |
|
| 115 | + public function issuer(): GeneralNames |
|
| 116 | + { |
|
| 117 | + if (!$this->hasIssuer()) { |
|
| 118 | + throw new \LogicException('authorityCertIssuer not set.'); |
|
| 119 | + } |
|
| 120 | + return $this->_authorityCertIssuer; |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | - /** |
|
| 124 | - * Get serial number. |
|
| 125 | - * |
|
| 126 | - * @throws \LogicException If not set |
|
| 127 | - * |
|
| 128 | - * @return string Base 10 integer string |
|
| 129 | - */ |
|
| 130 | - public function serial(): string |
|
| 131 | - { |
|
| 132 | - // both issuer and serial must be present or both absent |
|
| 133 | - if (!$this->hasIssuer()) { |
|
| 134 | - throw new \LogicException('authorityCertSerialNumber not set.'); |
|
| 135 | - } |
|
| 136 | - return $this->_authorityCertSerialNumber; |
|
| 137 | - } |
|
| 123 | + /** |
|
| 124 | + * Get serial number. |
|
| 125 | + * |
|
| 126 | + * @throws \LogicException If not set |
|
| 127 | + * |
|
| 128 | + * @return string Base 10 integer string |
|
| 129 | + */ |
|
| 130 | + public function serial(): string |
|
| 131 | + { |
|
| 132 | + // both issuer and serial must be present or both absent |
|
| 133 | + if (!$this->hasIssuer()) { |
|
| 134 | + throw new \LogicException('authorityCertSerialNumber not set.'); |
|
| 135 | + } |
|
| 136 | + return $this->_authorityCertSerialNumber; |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - /** |
|
| 140 | - * {@inheritdoc} |
|
| 141 | - */ |
|
| 142 | - protected static function _fromDER(string $data, bool $critical): Extension |
|
| 143 | - { |
|
| 144 | - $seq = UnspecifiedType::fromDER($data)->asSequence(); |
|
| 145 | - $keyIdentifier = null; |
|
| 146 | - $issuer = null; |
|
| 147 | - $serial = null; |
|
| 148 | - if ($seq->hasTagged(0)) { |
|
| 149 | - $keyIdentifier = $seq->getTagged(0) |
|
| 150 | - ->asImplicit(Element::TYPE_OCTET_STRING) |
|
| 151 | - ->asOctetString()->string(); |
|
| 152 | - } |
|
| 153 | - if ($seq->hasTagged(1) || $seq->hasTagged(2)) { |
|
| 154 | - if (!$seq->hasTagged(1) || !$seq->hasTagged(2)) { |
|
| 155 | - throw new \UnexpectedValueException( |
|
| 156 | - 'AuthorityKeyIdentifier must have both' . |
|
| 157 | - ' authorityCertIssuer and authorityCertSerialNumber' . |
|
| 158 | - ' present or both absent.'); |
|
| 159 | - } |
|
| 160 | - $issuer = GeneralNames::fromASN1($seq->getTagged(1) |
|
| 161 | - ->asImplicit(Element::TYPE_SEQUENCE)->asSequence()); |
|
| 162 | - $serial = $seq->getTagged(2)->asImplicit(Element::TYPE_INTEGER) |
|
| 163 | - ->asInteger()->number(); |
|
| 164 | - } |
|
| 165 | - return new self($critical, $keyIdentifier, $issuer, $serial); |
|
| 166 | - } |
|
| 139 | + /** |
|
| 140 | + * {@inheritdoc} |
|
| 141 | + */ |
|
| 142 | + protected static function _fromDER(string $data, bool $critical): Extension |
|
| 143 | + { |
|
| 144 | + $seq = UnspecifiedType::fromDER($data)->asSequence(); |
|
| 145 | + $keyIdentifier = null; |
|
| 146 | + $issuer = null; |
|
| 147 | + $serial = null; |
|
| 148 | + if ($seq->hasTagged(0)) { |
|
| 149 | + $keyIdentifier = $seq->getTagged(0) |
|
| 150 | + ->asImplicit(Element::TYPE_OCTET_STRING) |
|
| 151 | + ->asOctetString()->string(); |
|
| 152 | + } |
|
| 153 | + if ($seq->hasTagged(1) || $seq->hasTagged(2)) { |
|
| 154 | + if (!$seq->hasTagged(1) || !$seq->hasTagged(2)) { |
|
| 155 | + throw new \UnexpectedValueException( |
|
| 156 | + 'AuthorityKeyIdentifier must have both' . |
|
| 157 | + ' authorityCertIssuer and authorityCertSerialNumber' . |
|
| 158 | + ' present or both absent.'); |
|
| 159 | + } |
|
| 160 | + $issuer = GeneralNames::fromASN1($seq->getTagged(1) |
|
| 161 | + ->asImplicit(Element::TYPE_SEQUENCE)->asSequence()); |
|
| 162 | + $serial = $seq->getTagged(2)->asImplicit(Element::TYPE_INTEGER) |
|
| 163 | + ->asInteger()->number(); |
|
| 164 | + } |
|
| 165 | + return new self($critical, $keyIdentifier, $issuer, $serial); |
|
| 166 | + } |
|
| 167 | 167 | |
| 168 | - /** |
|
| 169 | - * {@inheritdoc} |
|
| 170 | - */ |
|
| 171 | - protected function _valueASN1(): Element |
|
| 172 | - { |
|
| 173 | - $elements = []; |
|
| 174 | - if (isset($this->_keyIdentifier)) { |
|
| 175 | - $elements[] = new ImplicitlyTaggedType(0, |
|
| 176 | - new OctetString($this->_keyIdentifier)); |
|
| 177 | - } |
|
| 178 | - // if either issuer or serial is set, both must be set |
|
| 179 | - if (isset($this->_authorityCertIssuer) || |
|
| 180 | - isset($this->_authorityCertSerialNumber)) { |
|
| 181 | - if (!isset($this->_authorityCertIssuer, |
|
| 182 | - $this->_authorityCertSerialNumber)) { |
|
| 183 | - throw new \LogicException( |
|
| 184 | - 'AuthorityKeyIdentifier must have both' . |
|
| 185 | - ' authorityCertIssuer and authorityCertSerialNumber' . |
|
| 186 | - ' present or both absent.'); |
|
| 187 | - } |
|
| 188 | - $elements[] = new ImplicitlyTaggedType(1, |
|
| 189 | - $this->_authorityCertIssuer->toASN1()); |
|
| 190 | - $elements[] = new ImplicitlyTaggedType(2, |
|
| 191 | - new Integer($this->_authorityCertSerialNumber)); |
|
| 192 | - } |
|
| 193 | - return new Sequence(...$elements); |
|
| 194 | - } |
|
| 168 | + /** |
|
| 169 | + * {@inheritdoc} |
|
| 170 | + */ |
|
| 171 | + protected function _valueASN1(): Element |
|
| 172 | + { |
|
| 173 | + $elements = []; |
|
| 174 | + if (isset($this->_keyIdentifier)) { |
|
| 175 | + $elements[] = new ImplicitlyTaggedType(0, |
|
| 176 | + new OctetString($this->_keyIdentifier)); |
|
| 177 | + } |
|
| 178 | + // if either issuer or serial is set, both must be set |
|
| 179 | + if (isset($this->_authorityCertIssuer) || |
|
| 180 | + isset($this->_authorityCertSerialNumber)) { |
|
| 181 | + if (!isset($this->_authorityCertIssuer, |
|
| 182 | + $this->_authorityCertSerialNumber)) { |
|
| 183 | + throw new \LogicException( |
|
| 184 | + 'AuthorityKeyIdentifier must have both' . |
|
| 185 | + ' authorityCertIssuer and authorityCertSerialNumber' . |
|
| 186 | + ' present or both absent.'); |
|
| 187 | + } |
|
| 188 | + $elements[] = new ImplicitlyTaggedType(1, |
|
| 189 | + $this->_authorityCertIssuer->toASN1()); |
|
| 190 | + $elements[] = new ImplicitlyTaggedType(2, |
|
| 191 | + new Integer($this->_authorityCertSerialNumber)); |
|
| 192 | + } |
|
| 193 | + return new Sequence(...$elements); |
|
| 194 | + } |
|
| 195 | 195 | } |