@@ -19,87 +19,87 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class OtherName extends GeneralName |
| 21 | 21 | { |
| 22 | - /** |
|
| 23 | - * Type OID. |
|
| 24 | - * |
|
| 25 | - * @var string $_type |
|
| 26 | - */ |
|
| 27 | - protected $_type; |
|
| 22 | + /** |
|
| 23 | + * Type OID. |
|
| 24 | + * |
|
| 25 | + * @var string $_type |
|
| 26 | + */ |
|
| 27 | + protected $_type; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Value. |
|
| 31 | - * |
|
| 32 | - * @var Element $_element |
|
| 33 | - */ |
|
| 34 | - protected $_element; |
|
| 29 | + /** |
|
| 30 | + * Value. |
|
| 31 | + * |
|
| 32 | + * @var Element $_element |
|
| 33 | + */ |
|
| 34 | + protected $_element; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Constructor. |
|
| 38 | - * |
|
| 39 | - * @param string $type_id OID |
|
| 40 | - * @param Element $el |
|
| 41 | - */ |
|
| 42 | - public function __construct(string $type_id, Element $el) |
|
| 43 | - { |
|
| 44 | - $this->_tag = self::TAG_OTHER_NAME; |
|
| 45 | - $this->_type = $type_id; |
|
| 46 | - $this->_element = $el; |
|
| 47 | - } |
|
| 36 | + /** |
|
| 37 | + * Constructor. |
|
| 38 | + * |
|
| 39 | + * @param string $type_id OID |
|
| 40 | + * @param Element $el |
|
| 41 | + */ |
|
| 42 | + public function __construct(string $type_id, Element $el) |
|
| 43 | + { |
|
| 44 | + $this->_tag = self::TAG_OTHER_NAME; |
|
| 45 | + $this->_type = $type_id; |
|
| 46 | + $this->_element = $el; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * |
|
| 51 | - * @param UnspecifiedType $el |
|
| 52 | - * @return self |
|
| 53 | - */ |
|
| 54 | - public static function fromChosenASN1(UnspecifiedType $el): self |
|
| 55 | - { |
|
| 56 | - $seq = $el->asSequence(); |
|
| 57 | - $type_id = $seq->at(0) |
|
| 58 | - ->asObjectIdentifier() |
|
| 59 | - ->oid(); |
|
| 60 | - $value = $seq->getTagged(0) |
|
| 61 | - ->asExplicit() |
|
| 62 | - ->asElement(); |
|
| 63 | - return new self($type_id, $value); |
|
| 64 | - } |
|
| 49 | + /** |
|
| 50 | + * |
|
| 51 | + * @param UnspecifiedType $el |
|
| 52 | + * @return self |
|
| 53 | + */ |
|
| 54 | + public static function fromChosenASN1(UnspecifiedType $el): self |
|
| 55 | + { |
|
| 56 | + $seq = $el->asSequence(); |
|
| 57 | + $type_id = $seq->at(0) |
|
| 58 | + ->asObjectIdentifier() |
|
| 59 | + ->oid(); |
|
| 60 | + $value = $seq->getTagged(0) |
|
| 61 | + ->asExplicit() |
|
| 62 | + ->asElement(); |
|
| 63 | + return new self($type_id, $value); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * |
|
| 68 | - * {@inheritdoc} |
|
| 69 | - */ |
|
| 70 | - public function string(): string |
|
| 71 | - { |
|
| 72 | - return $this->_type . "/#" . bin2hex($this->_element->toDER()); |
|
| 73 | - } |
|
| 66 | + /** |
|
| 67 | + * |
|
| 68 | + * {@inheritdoc} |
|
| 69 | + */ |
|
| 70 | + public function string(): string |
|
| 71 | + { |
|
| 72 | + return $this->_type . "/#" . bin2hex($this->_element->toDER()); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * Get type OID. |
|
| 77 | - * |
|
| 78 | - * @return string |
|
| 79 | - */ |
|
| 80 | - public function type(): string |
|
| 81 | - { |
|
| 82 | - return $this->_type; |
|
| 83 | - } |
|
| 75 | + /** |
|
| 76 | + * Get type OID. |
|
| 77 | + * |
|
| 78 | + * @return string |
|
| 79 | + */ |
|
| 80 | + public function type(): string |
|
| 81 | + { |
|
| 82 | + return $this->_type; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * Get value element. |
|
| 87 | - * |
|
| 88 | - * @return Element |
|
| 89 | - */ |
|
| 90 | - public function value(): Element |
|
| 91 | - { |
|
| 92 | - return $this->_element; |
|
| 93 | - } |
|
| 85 | + /** |
|
| 86 | + * Get value element. |
|
| 87 | + * |
|
| 88 | + * @return Element |
|
| 89 | + */ |
|
| 90 | + public function value(): Element |
|
| 91 | + { |
|
| 92 | + return $this->_element; |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * |
|
| 97 | - * {@inheritdoc} |
|
| 98 | - */ |
|
| 99 | - protected function _choiceASN1(): TaggedType |
|
| 100 | - { |
|
| 101 | - return new ImplicitlyTaggedType($this->_tag, |
|
| 102 | - new Sequence(new ObjectIdentifier($this->_type), |
|
| 103 | - new ExplicitlyTaggedType(0, $this->_element))); |
|
| 104 | - } |
|
| 95 | + /** |
|
| 96 | + * |
|
| 97 | + * {@inheritdoc} |
|
| 98 | + */ |
|
| 99 | + protected function _choiceASN1(): TaggedType |
|
| 100 | + { |
|
| 101 | + return new ImplicitlyTaggedType($this->_tag, |
|
| 102 | + new Sequence(new ObjectIdentifier($this->_type), |
|
| 103 | + new ExplicitlyTaggedType(0, $this->_element))); |
|
| 104 | + } |
|
| 105 | 105 | } |
@@ -17,59 +17,59 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class UniformResourceIdentifier extends GeneralName |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * URI. |
|
| 22 | - * |
|
| 23 | - * @var string $_uri |
|
| 24 | - */ |
|
| 25 | - protected $_uri; |
|
| 20 | + /** |
|
| 21 | + * URI. |
|
| 22 | + * |
|
| 23 | + * @var string $_uri |
|
| 24 | + */ |
|
| 25 | + protected $_uri; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Constructor. |
|
| 29 | - * |
|
| 30 | - * @param string $uri |
|
| 31 | - */ |
|
| 32 | - public function __construct(string $uri) |
|
| 33 | - { |
|
| 34 | - $this->_tag = self::TAG_URI; |
|
| 35 | - $this->_uri = $uri; |
|
| 36 | - } |
|
| 27 | + /** |
|
| 28 | + * Constructor. |
|
| 29 | + * |
|
| 30 | + * @param string $uri |
|
| 31 | + */ |
|
| 32 | + public function __construct(string $uri) |
|
| 33 | + { |
|
| 34 | + $this->_tag = self::TAG_URI; |
|
| 35 | + $this->_uri = $uri; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * |
|
| 40 | - * @param UnspecifiedType $el |
|
| 41 | - * @return self |
|
| 42 | - */ |
|
| 43 | - public static function fromChosenASN1(UnspecifiedType $el): self |
|
| 44 | - { |
|
| 45 | - return new self($el->asIA5String()->string()); |
|
| 46 | - } |
|
| 38 | + /** |
|
| 39 | + * |
|
| 40 | + * @param UnspecifiedType $el |
|
| 41 | + * @return self |
|
| 42 | + */ |
|
| 43 | + public static function fromChosenASN1(UnspecifiedType $el): self |
|
| 44 | + { |
|
| 45 | + return new self($el->asIA5String()->string()); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * |
|
| 50 | - * {@inheritdoc} |
|
| 51 | - */ |
|
| 52 | - public function string(): string |
|
| 53 | - { |
|
| 54 | - return $this->_uri; |
|
| 55 | - } |
|
| 48 | + /** |
|
| 49 | + * |
|
| 50 | + * {@inheritdoc} |
|
| 51 | + */ |
|
| 52 | + public function string(): string |
|
| 53 | + { |
|
| 54 | + return $this->_uri; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Get URI. |
|
| 59 | - * |
|
| 60 | - * @return string |
|
| 61 | - */ |
|
| 62 | - public function uri(): string |
|
| 63 | - { |
|
| 64 | - return $this->_uri; |
|
| 65 | - } |
|
| 57 | + /** |
|
| 58 | + * Get URI. |
|
| 59 | + * |
|
| 60 | + * @return string |
|
| 61 | + */ |
|
| 62 | + public function uri(): string |
|
| 63 | + { |
|
| 64 | + return $this->_uri; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * |
|
| 69 | - * {@inheritdoc} |
|
| 70 | - */ |
|
| 71 | - protected function _choiceASN1(): TaggedType |
|
| 72 | - { |
|
| 73 | - return new ImplicitlyTaggedType($this->_tag, new IA5String($this->_uri)); |
|
| 74 | - } |
|
| 67 | + /** |
|
| 68 | + * |
|
| 69 | + * {@inheritdoc} |
|
| 70 | + */ |
|
| 71 | + protected function _choiceASN1(): TaggedType |
|
| 72 | + { |
|
| 73 | + return new ImplicitlyTaggedType($this->_tag, new IA5String($this->_uri)); |
|
| 74 | + } |
|
| 75 | 75 | } |
@@ -16,60 +16,60 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class RegisteredID extends GeneralName |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * Object identifier. |
|
| 21 | - * |
|
| 22 | - * @var string $_oid |
|
| 23 | - */ |
|
| 24 | - protected $_oid; |
|
| 19 | + /** |
|
| 20 | + * Object identifier. |
|
| 21 | + * |
|
| 22 | + * @var string $_oid |
|
| 23 | + */ |
|
| 24 | + protected $_oid; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Constructor. |
|
| 28 | - * |
|
| 29 | - * @param string $oid OID in dotted format |
|
| 30 | - */ |
|
| 31 | - public function __construct(string $oid) |
|
| 32 | - { |
|
| 33 | - $this->_tag = self::TAG_REGISTERED_ID; |
|
| 34 | - $this->_oid = $oid; |
|
| 35 | - } |
|
| 26 | + /** |
|
| 27 | + * Constructor. |
|
| 28 | + * |
|
| 29 | + * @param string $oid OID in dotted format |
|
| 30 | + */ |
|
| 31 | + public function __construct(string $oid) |
|
| 32 | + { |
|
| 33 | + $this->_tag = self::TAG_REGISTERED_ID; |
|
| 34 | + $this->_oid = $oid; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * |
|
| 39 | - * @param UnspecifiedType $el |
|
| 40 | - * @return self |
|
| 41 | - */ |
|
| 42 | - public static function fromChosenASN1(UnspecifiedType $el): self |
|
| 43 | - { |
|
| 44 | - return new self($el->asObjectIdentifier()->oid()); |
|
| 45 | - } |
|
| 37 | + /** |
|
| 38 | + * |
|
| 39 | + * @param UnspecifiedType $el |
|
| 40 | + * @return self |
|
| 41 | + */ |
|
| 42 | + public static function fromChosenASN1(UnspecifiedType $el): self |
|
| 43 | + { |
|
| 44 | + return new self($el->asObjectIdentifier()->oid()); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * |
|
| 49 | - * {@inheritdoc} |
|
| 50 | - */ |
|
| 51 | - public function string(): string |
|
| 52 | - { |
|
| 53 | - return $this->_oid; |
|
| 54 | - } |
|
| 47 | + /** |
|
| 48 | + * |
|
| 49 | + * {@inheritdoc} |
|
| 50 | + */ |
|
| 51 | + public function string(): string |
|
| 52 | + { |
|
| 53 | + return $this->_oid; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Get object identifier in dotted format. |
|
| 58 | - * |
|
| 59 | - * @return string OID |
|
| 60 | - */ |
|
| 61 | - public function oid(): string |
|
| 62 | - { |
|
| 63 | - return $this->_oid; |
|
| 64 | - } |
|
| 56 | + /** |
|
| 57 | + * Get object identifier in dotted format. |
|
| 58 | + * |
|
| 59 | + * @return string OID |
|
| 60 | + */ |
|
| 61 | + public function oid(): string |
|
| 62 | + { |
|
| 63 | + return $this->_oid; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * |
|
| 68 | - * {@inheritdoc} |
|
| 69 | - */ |
|
| 70 | - protected function _choiceASN1(): TaggedType |
|
| 71 | - { |
|
| 72 | - return new ImplicitlyTaggedType($this->_tag, |
|
| 73 | - new ObjectIdentifier($this->_oid)); |
|
| 74 | - } |
|
| 66 | + /** |
|
| 67 | + * |
|
| 68 | + * {@inheritdoc} |
|
| 69 | + */ |
|
| 70 | + protected function _choiceASN1(): TaggedType |
|
| 71 | + { |
|
| 72 | + return new ImplicitlyTaggedType($this->_tag, |
|
| 73 | + new ObjectIdentifier($this->_oid)); |
|
| 74 | + } |
|
| 75 | 75 | } |
@@ -16,72 +16,72 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class DirectoryName extends GeneralName |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * Directory name. |
|
| 21 | - * |
|
| 22 | - * @var Name $_dn |
|
| 23 | - */ |
|
| 24 | - protected $_dn; |
|
| 19 | + /** |
|
| 20 | + * Directory name. |
|
| 21 | + * |
|
| 22 | + * @var Name $_dn |
|
| 23 | + */ |
|
| 24 | + protected $_dn; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Constructor. |
|
| 28 | - * |
|
| 29 | - * @param Name $dn |
|
| 30 | - */ |
|
| 31 | - public function __construct(Name $dn) |
|
| 32 | - { |
|
| 33 | - $this->_tag = self::TAG_DIRECTORY_NAME; |
|
| 34 | - $this->_dn = $dn; |
|
| 35 | - } |
|
| 26 | + /** |
|
| 27 | + * Constructor. |
|
| 28 | + * |
|
| 29 | + * @param Name $dn |
|
| 30 | + */ |
|
| 31 | + public function __construct(Name $dn) |
|
| 32 | + { |
|
| 33 | + $this->_tag = self::TAG_DIRECTORY_NAME; |
|
| 34 | + $this->_dn = $dn; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * |
|
| 39 | - * @param UnspecifiedType $el |
|
| 40 | - * @return self |
|
| 41 | - */ |
|
| 42 | - public static function fromChosenASN1(UnspecifiedType $el): self |
|
| 43 | - { |
|
| 44 | - return new self(Name::fromASN1($el->asSequence())); |
|
| 45 | - } |
|
| 37 | + /** |
|
| 38 | + * |
|
| 39 | + * @param UnspecifiedType $el |
|
| 40 | + * @return self |
|
| 41 | + */ |
|
| 42 | + public static function fromChosenASN1(UnspecifiedType $el): self |
|
| 43 | + { |
|
| 44 | + return new self(Name::fromASN1($el->asSequence())); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Initialize from distinguished name string. |
|
| 49 | - * |
|
| 50 | - * @param string $str |
|
| 51 | - * @return self |
|
| 52 | - */ |
|
| 53 | - public static function fromDNString(string $str): self |
|
| 54 | - { |
|
| 55 | - return new self(Name::fromString($str)); |
|
| 56 | - } |
|
| 47 | + /** |
|
| 48 | + * Initialize from distinguished name string. |
|
| 49 | + * |
|
| 50 | + * @param string $str |
|
| 51 | + * @return self |
|
| 52 | + */ |
|
| 53 | + public static function fromDNString(string $str): self |
|
| 54 | + { |
|
| 55 | + return new self(Name::fromString($str)); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * |
|
| 60 | - * {@inheritdoc} |
|
| 61 | - */ |
|
| 62 | - public function string(): string |
|
| 63 | - { |
|
| 64 | - return $this->_dn->toString(); |
|
| 65 | - } |
|
| 58 | + /** |
|
| 59 | + * |
|
| 60 | + * {@inheritdoc} |
|
| 61 | + */ |
|
| 62 | + public function string(): string |
|
| 63 | + { |
|
| 64 | + return $this->_dn->toString(); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * Get directory name. |
|
| 69 | - * |
|
| 70 | - * @return Name |
|
| 71 | - */ |
|
| 72 | - public function dn(): Name |
|
| 73 | - { |
|
| 74 | - return $this->_dn; |
|
| 75 | - } |
|
| 67 | + /** |
|
| 68 | + * Get directory name. |
|
| 69 | + * |
|
| 70 | + * @return Name |
|
| 71 | + */ |
|
| 72 | + public function dn(): Name |
|
| 73 | + { |
|
| 74 | + return $this->_dn; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * |
|
| 79 | - * {@inheritdoc} |
|
| 80 | - */ |
|
| 81 | - protected function _choiceASN1(): TaggedType |
|
| 82 | - { |
|
| 83 | - // Name type is itself a CHOICE, so explicit tagging must be |
|
| 84 | - // employed to avoid ambiguities |
|
| 85 | - return new ExplicitlyTaggedType($this->_tag, $this->_dn->toASN1()); |
|
| 86 | - } |
|
| 77 | + /** |
|
| 78 | + * |
|
| 79 | + * {@inheritdoc} |
|
| 80 | + */ |
|
| 81 | + protected function _choiceASN1(): TaggedType |
|
| 82 | + { |
|
| 83 | + // Name type is itself a CHOICE, so explicit tagging must be |
|
| 84 | + // employed to avoid ambiguities |
|
| 85 | + return new ExplicitlyTaggedType($this->_tag, $this->_dn->toASN1()); |
|
| 86 | + } |
|
| 87 | 87 | } |
@@ -16,59 +16,59 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class DNSName extends GeneralName |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * DNS name. |
|
| 21 | - * |
|
| 22 | - * @var string |
|
| 23 | - */ |
|
| 24 | - protected $_name; |
|
| 19 | + /** |
|
| 20 | + * DNS name. |
|
| 21 | + * |
|
| 22 | + * @var string |
|
| 23 | + */ |
|
| 24 | + protected $_name; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Constructor. |
|
| 28 | - * |
|
| 29 | - * @param string $name Domain name |
|
| 30 | - */ |
|
| 31 | - public function __construct(string $name) |
|
| 32 | - { |
|
| 33 | - $this->_tag = self::TAG_DNS_NAME; |
|
| 34 | - $this->_name = $name; |
|
| 35 | - } |
|
| 26 | + /** |
|
| 27 | + * Constructor. |
|
| 28 | + * |
|
| 29 | + * @param string $name Domain name |
|
| 30 | + */ |
|
| 31 | + public function __construct(string $name) |
|
| 32 | + { |
|
| 33 | + $this->_tag = self::TAG_DNS_NAME; |
|
| 34 | + $this->_name = $name; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * |
|
| 39 | - * @param UnspecifiedType $el |
|
| 40 | - * @return self |
|
| 41 | - */ |
|
| 42 | - public static function fromChosenASN1(UnspecifiedType $el): self |
|
| 43 | - { |
|
| 44 | - return new self($el->asIA5String()->string()); |
|
| 45 | - } |
|
| 37 | + /** |
|
| 38 | + * |
|
| 39 | + * @param UnspecifiedType $el |
|
| 40 | + * @return self |
|
| 41 | + */ |
|
| 42 | + public static function fromChosenASN1(UnspecifiedType $el): self |
|
| 43 | + { |
|
| 44 | + return new self($el->asIA5String()->string()); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * |
|
| 49 | - * {@inheritdoc} |
|
| 50 | - */ |
|
| 51 | - public function string(): string |
|
| 52 | - { |
|
| 53 | - return $this->_name; |
|
| 54 | - } |
|
| 47 | + /** |
|
| 48 | + * |
|
| 49 | + * {@inheritdoc} |
|
| 50 | + */ |
|
| 51 | + public function string(): string |
|
| 52 | + { |
|
| 53 | + return $this->_name; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Get DNS name. |
|
| 58 | - * |
|
| 59 | - * @return string |
|
| 60 | - */ |
|
| 61 | - public function name(): string |
|
| 62 | - { |
|
| 63 | - return $this->_name; |
|
| 64 | - } |
|
| 56 | + /** |
|
| 57 | + * Get DNS name. |
|
| 58 | + * |
|
| 59 | + * @return string |
|
| 60 | + */ |
|
| 61 | + public function name(): string |
|
| 62 | + { |
|
| 63 | + return $this->_name; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * |
|
| 68 | - * {@inheritdoc} |
|
| 69 | - */ |
|
| 70 | - protected function _choiceASN1(): TaggedType |
|
| 71 | - { |
|
| 72 | - return new ImplicitlyTaggedType($this->_tag, new IA5String($this->_name)); |
|
| 73 | - } |
|
| 66 | + /** |
|
| 67 | + * |
|
| 68 | + * {@inheritdoc} |
|
| 69 | + */ |
|
| 70 | + protected function _choiceASN1(): TaggedType |
|
| 71 | + { |
|
| 72 | + return new ImplicitlyTaggedType($this->_tag, new IA5String($this->_name)); |
|
| 73 | + } |
|
| 74 | 74 | } |
@@ -18,47 +18,47 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class X400Address extends GeneralName |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * |
|
| 23 | - * @var \ASN1\Element |
|
| 24 | - */ |
|
| 25 | - protected $_element; |
|
| 21 | + /** |
|
| 22 | + * |
|
| 23 | + * @var \ASN1\Element |
|
| 24 | + */ |
|
| 25 | + protected $_element; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Constructor. |
|
| 29 | - */ |
|
| 30 | - protected function __construct() |
|
| 31 | - { |
|
| 32 | - $this->_tag = self::TAG_X400_ADDRESS; |
|
| 33 | - } |
|
| 27 | + /** |
|
| 28 | + * Constructor. |
|
| 29 | + */ |
|
| 30 | + protected function __construct() |
|
| 31 | + { |
|
| 32 | + $this->_tag = self::TAG_X400_ADDRESS; |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * |
|
| 37 | - * @param UnspecifiedType $el |
|
| 38 | - * @return self |
|
| 39 | - */ |
|
| 40 | - public static function fromChosenASN1(UnspecifiedType $el): self |
|
| 41 | - { |
|
| 42 | - $obj = new self(); |
|
| 43 | - $obj->_element = $el->asSequence(); |
|
| 44 | - return $obj; |
|
| 45 | - } |
|
| 35 | + /** |
|
| 36 | + * |
|
| 37 | + * @param UnspecifiedType $el |
|
| 38 | + * @return self |
|
| 39 | + */ |
|
| 40 | + public static function fromChosenASN1(UnspecifiedType $el): self |
|
| 41 | + { |
|
| 42 | + $obj = new self(); |
|
| 43 | + $obj->_element = $el->asSequence(); |
|
| 44 | + return $obj; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * |
|
| 49 | - * {@inheritdoc} |
|
| 50 | - */ |
|
| 51 | - public function string(): string |
|
| 52 | - { |
|
| 53 | - return bin2hex($this->_element->toDER()); |
|
| 54 | - } |
|
| 47 | + /** |
|
| 48 | + * |
|
| 49 | + * {@inheritdoc} |
|
| 50 | + */ |
|
| 51 | + public function string(): string |
|
| 52 | + { |
|
| 53 | + return bin2hex($this->_element->toDER()); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * |
|
| 58 | - * {@inheritdoc} |
|
| 59 | - */ |
|
| 60 | - protected function _choiceASN1(): TaggedType |
|
| 61 | - { |
|
| 62 | - return new ImplicitlyTaggedType($this->_tag, $this->_element); |
|
| 63 | - } |
|
| 56 | + /** |
|
| 57 | + * |
|
| 58 | + * {@inheritdoc} |
|
| 59 | + */ |
|
| 60 | + protected function _choiceASN1(): TaggedType |
|
| 61 | + { |
|
| 62 | + return new ImplicitlyTaggedType($this->_tag, $this->_element); |
|
| 63 | + } |
|
| 64 | 64 | } |
@@ -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): self |
|
| 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): self |
|
| 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): self |
|
| 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): self |
|
| 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 | } |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | public static function fromPEMs(PEM ...$pems): self |
| 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 | } |
@@ -13,86 +13,86 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class Validity |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * Not before time. |
|
| 18 | - * |
|
| 19 | - * @var Time $_notBefore |
|
| 20 | - */ |
|
| 21 | - protected $_notBefore; |
|
| 16 | + /** |
|
| 17 | + * Not before time. |
|
| 18 | + * |
|
| 19 | + * @var Time $_notBefore |
|
| 20 | + */ |
|
| 21 | + protected $_notBefore; |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Not after time. |
|
| 25 | - * |
|
| 26 | - * @var Time $_notAfter |
|
| 27 | - */ |
|
| 28 | - protected $_notAfter; |
|
| 23 | + /** |
|
| 24 | + * Not after time. |
|
| 25 | + * |
|
| 26 | + * @var Time $_notAfter |
|
| 27 | + */ |
|
| 28 | + protected $_notAfter; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Constructor. |
|
| 32 | - * |
|
| 33 | - * @param Time $not_before |
|
| 34 | - * @param Time $not_after |
|
| 35 | - */ |
|
| 36 | - public function __construct(Time $not_before, Time $not_after) |
|
| 37 | - { |
|
| 38 | - $this->_notBefore = $not_before; |
|
| 39 | - $this->_notAfter = $not_after; |
|
| 40 | - } |
|
| 30 | + /** |
|
| 31 | + * Constructor. |
|
| 32 | + * |
|
| 33 | + * @param Time $not_before |
|
| 34 | + * @param Time $not_after |
|
| 35 | + */ |
|
| 36 | + public function __construct(Time $not_before, Time $not_after) |
|
| 37 | + { |
|
| 38 | + $this->_notBefore = $not_before; |
|
| 39 | + $this->_notAfter = $not_after; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Initialize from ASN.1. |
|
| 44 | - * |
|
| 45 | - * @param Sequence $seq |
|
| 46 | - */ |
|
| 47 | - public static function fromASN1(Sequence $seq): self |
|
| 48 | - { |
|
| 49 | - $nb = Time::fromASN1($seq->at(0)->asTime()); |
|
| 50 | - $na = Time::fromASN1($seq->at(1)->asTime()); |
|
| 51 | - return new self($nb, $na); |
|
| 52 | - } |
|
| 42 | + /** |
|
| 43 | + * Initialize from ASN.1. |
|
| 44 | + * |
|
| 45 | + * @param Sequence $seq |
|
| 46 | + */ |
|
| 47 | + public static function fromASN1(Sequence $seq): self |
|
| 48 | + { |
|
| 49 | + $nb = Time::fromASN1($seq->at(0)->asTime()); |
|
| 50 | + $na = Time::fromASN1($seq->at(1)->asTime()); |
|
| 51 | + return new self($nb, $na); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Initialize from date strings. |
|
| 56 | - * |
|
| 57 | - * @param string|null $nb_date Not before date |
|
| 58 | - * @param string|null $na_date Not after date |
|
| 59 | - * @param string|null $tz Timezone string |
|
| 60 | - * @return self |
|
| 61 | - */ |
|
| 62 | - public static function fromStrings($nb_date, $na_date, $tz = null): self |
|
| 63 | - { |
|
| 64 | - return new self(Time::fromString($nb_date, $tz), |
|
| 65 | - Time::fromString($na_date, $tz)); |
|
| 66 | - } |
|
| 54 | + /** |
|
| 55 | + * Initialize from date strings. |
|
| 56 | + * |
|
| 57 | + * @param string|null $nb_date Not before date |
|
| 58 | + * @param string|null $na_date Not after date |
|
| 59 | + * @param string|null $tz Timezone string |
|
| 60 | + * @return self |
|
| 61 | + */ |
|
| 62 | + public static function fromStrings($nb_date, $na_date, $tz = null): self |
|
| 63 | + { |
|
| 64 | + return new self(Time::fromString($nb_date, $tz), |
|
| 65 | + Time::fromString($na_date, $tz)); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * Get not before time. |
|
| 70 | - * |
|
| 71 | - * @return Time |
|
| 72 | - */ |
|
| 73 | - public function notBefore(): Time |
|
| 74 | - { |
|
| 75 | - return $this->_notBefore; |
|
| 76 | - } |
|
| 68 | + /** |
|
| 69 | + * Get not before time. |
|
| 70 | + * |
|
| 71 | + * @return Time |
|
| 72 | + */ |
|
| 73 | + public function notBefore(): Time |
|
| 74 | + { |
|
| 75 | + return $this->_notBefore; |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Get not after time. |
|
| 80 | - * |
|
| 81 | - * @return Time |
|
| 82 | - */ |
|
| 83 | - public function notAfter(): Time |
|
| 84 | - { |
|
| 85 | - return $this->_notAfter; |
|
| 86 | - } |
|
| 78 | + /** |
|
| 79 | + * Get not after time. |
|
| 80 | + * |
|
| 81 | + * @return Time |
|
| 82 | + */ |
|
| 83 | + public function notAfter(): Time |
|
| 84 | + { |
|
| 85 | + return $this->_notAfter; |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * Generate ASN.1 structure. |
|
| 90 | - * |
|
| 91 | - * @return Sequence |
|
| 92 | - */ |
|
| 93 | - public function toASN1(): Sequence |
|
| 94 | - { |
|
| 95 | - return new Sequence($this->_notBefore->toASN1(), |
|
| 96 | - $this->_notAfter->toASN1()); |
|
| 97 | - } |
|
| 88 | + /** |
|
| 89 | + * Generate ASN.1 structure. |
|
| 90 | + * |
|
| 91 | + * @return Sequence |
|
| 92 | + */ |
|
| 93 | + public function toASN1(): Sequence |
|
| 94 | + { |
|
| 95 | + return new Sequence($this->_notBefore->toASN1(), |
|
| 96 | + $this->_notAfter->toASN1()); |
|
| 97 | + } |
|
| 98 | 98 | } |
@@ -53,7 +53,7 @@ |
||
| 53 | 53 | public static function fromPEMs(PEM ...$pems): self |
| 54 | 54 | { |
| 55 | 55 | $certs = array_map( |
| 56 | - function ($pem) { |
|
| 56 | + function($pem) { |
|
| 57 | 57 | return Certificate::fromPEM($pem); |
| 58 | 58 | }, $pems); |
| 59 | 59 | return new self(...$certs); |
@@ -12,208 +12,208 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class CertificateBundle implements \Countable, \IteratorAggregate |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * Certificates. |
|
| 17 | - * |
|
| 18 | - * @var Certificate[] $_certs |
|
| 19 | - */ |
|
| 20 | - protected $_certs; |
|
| 15 | + /** |
|
| 16 | + * Certificates. |
|
| 17 | + * |
|
| 18 | + * @var Certificate[] $_certs |
|
| 19 | + */ |
|
| 20 | + protected $_certs; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Mapping from public key id to array of certificates. |
|
| 24 | - * |
|
| 25 | - * @var null|(Certificate[])[] |
|
| 26 | - */ |
|
| 27 | - private $_keyIdMap; |
|
| 22 | + /** |
|
| 23 | + * Mapping from public key id to array of certificates. |
|
| 24 | + * |
|
| 25 | + * @var null|(Certificate[])[] |
|
| 26 | + */ |
|
| 27 | + private $_keyIdMap; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Constructor. |
|
| 31 | - * |
|
| 32 | - * @param Certificate ...$certs Certificate objects |
|
| 33 | - */ |
|
| 34 | - public function __construct(Certificate ...$certs) |
|
| 35 | - { |
|
| 36 | - $this->_certs = $certs; |
|
| 37 | - } |
|
| 29 | + /** |
|
| 30 | + * Constructor. |
|
| 31 | + * |
|
| 32 | + * @param Certificate ...$certs Certificate objects |
|
| 33 | + */ |
|
| 34 | + public function __construct(Certificate ...$certs) |
|
| 35 | + { |
|
| 36 | + $this->_certs = $certs; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Reset internal cached variables on clone. |
|
| 41 | - */ |
|
| 42 | - public function __clone() |
|
| 43 | - { |
|
| 44 | - $this->_keyIdMap = null; |
|
| 45 | - } |
|
| 39 | + /** |
|
| 40 | + * Reset internal cached variables on clone. |
|
| 41 | + */ |
|
| 42 | + public function __clone() |
|
| 43 | + { |
|
| 44 | + $this->_keyIdMap = null; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Initialize from PEMs. |
|
| 49 | - * |
|
| 50 | - * @param PEM ...$pems PEM objects |
|
| 51 | - * @return self |
|
| 52 | - */ |
|
| 53 | - public static function fromPEMs(PEM ...$pems): self |
|
| 54 | - { |
|
| 55 | - $certs = array_map( |
|
| 56 | - function ($pem) { |
|
| 57 | - return Certificate::fromPEM($pem); |
|
| 58 | - }, $pems); |
|
| 59 | - return new self(...$certs); |
|
| 60 | - } |
|
| 47 | + /** |
|
| 48 | + * Initialize from PEMs. |
|
| 49 | + * |
|
| 50 | + * @param PEM ...$pems PEM objects |
|
| 51 | + * @return self |
|
| 52 | + */ |
|
| 53 | + public static function fromPEMs(PEM ...$pems): self |
|
| 54 | + { |
|
| 55 | + $certs = array_map( |
|
| 56 | + function ($pem) { |
|
| 57 | + return Certificate::fromPEM($pem); |
|
| 58 | + }, $pems); |
|
| 59 | + return new self(...$certs); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Initialize from PEM bundle. |
|
| 64 | - * |
|
| 65 | - * @param PEMBundle $pem_bundle |
|
| 66 | - * @return self |
|
| 67 | - */ |
|
| 68 | - public static function fromPEMBundle(PEMBundle $pem_bundle): self |
|
| 69 | - { |
|
| 70 | - return self::fromPEMs(...$pem_bundle->all()); |
|
| 71 | - } |
|
| 62 | + /** |
|
| 63 | + * Initialize from PEM bundle. |
|
| 64 | + * |
|
| 65 | + * @param PEMBundle $pem_bundle |
|
| 66 | + * @return self |
|
| 67 | + */ |
|
| 68 | + public static function fromPEMBundle(PEMBundle $pem_bundle): self |
|
| 69 | + { |
|
| 70 | + return self::fromPEMs(...$pem_bundle->all()); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * Get self with certificates added. |
|
| 75 | - * |
|
| 76 | - * @param Certificate ...$cert |
|
| 77 | - * @return self |
|
| 78 | - */ |
|
| 79 | - public function withCertificates(Certificate ...$cert): self |
|
| 80 | - { |
|
| 81 | - $obj = clone $this; |
|
| 82 | - $obj->_certs = array_merge($obj->_certs, $cert); |
|
| 83 | - return $obj; |
|
| 84 | - } |
|
| 73 | + /** |
|
| 74 | + * Get self with certificates added. |
|
| 75 | + * |
|
| 76 | + * @param Certificate ...$cert |
|
| 77 | + * @return self |
|
| 78 | + */ |
|
| 79 | + public function withCertificates(Certificate ...$cert): self |
|
| 80 | + { |
|
| 81 | + $obj = clone $this; |
|
| 82 | + $obj->_certs = array_merge($obj->_certs, $cert); |
|
| 83 | + return $obj; |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * Get self with certificates from PEMBundle added. |
|
| 88 | - * |
|
| 89 | - * @param PEMBundle $pem_bundle |
|
| 90 | - * @return self |
|
| 91 | - */ |
|
| 92 | - public function withPEMBundle(PEMBundle $pem_bundle): self |
|
| 93 | - { |
|
| 94 | - $certs = $this->_certs; |
|
| 95 | - foreach ($pem_bundle as $pem) { |
|
| 96 | - $certs[] = Certificate::fromPEM($pem); |
|
| 97 | - } |
|
| 98 | - return new self(...$certs); |
|
| 99 | - } |
|
| 86 | + /** |
|
| 87 | + * Get self with certificates from PEMBundle added. |
|
| 88 | + * |
|
| 89 | + * @param PEMBundle $pem_bundle |
|
| 90 | + * @return self |
|
| 91 | + */ |
|
| 92 | + public function withPEMBundle(PEMBundle $pem_bundle): self |
|
| 93 | + { |
|
| 94 | + $certs = $this->_certs; |
|
| 95 | + foreach ($pem_bundle as $pem) { |
|
| 96 | + $certs[] = Certificate::fromPEM($pem); |
|
| 97 | + } |
|
| 98 | + return new self(...$certs); |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * Get self with single certificate from PEM added. |
|
| 103 | - * |
|
| 104 | - * @param PEM $pem |
|
| 105 | - * @return self |
|
| 106 | - */ |
|
| 107 | - public function withPEM(PEM $pem): self |
|
| 108 | - { |
|
| 109 | - $certs = $this->_certs; |
|
| 110 | - $certs[] = Certificate::fromPEM($pem); |
|
| 111 | - return new self(...$certs); |
|
| 112 | - } |
|
| 101 | + /** |
|
| 102 | + * Get self with single certificate from PEM added. |
|
| 103 | + * |
|
| 104 | + * @param PEM $pem |
|
| 105 | + * @return self |
|
| 106 | + */ |
|
| 107 | + public function withPEM(PEM $pem): self |
|
| 108 | + { |
|
| 109 | + $certs = $this->_certs; |
|
| 110 | + $certs[] = Certificate::fromPEM($pem); |
|
| 111 | + return new self(...$certs); |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - /** |
|
| 115 | - * Check whether bundle contains a given certificate. |
|
| 116 | - * |
|
| 117 | - * @param Certificate $cert |
|
| 118 | - * @return bool |
|
| 119 | - */ |
|
| 120 | - public function contains(Certificate $cert): bool |
|
| 121 | - { |
|
| 122 | - $id = self::_getCertKeyId($cert); |
|
| 123 | - $map = $this->_getKeyIdMap(); |
|
| 124 | - if (!isset($map[$id])) { |
|
| 125 | - return false; |
|
| 126 | - } |
|
| 127 | - foreach ($map[$id] as $c) { |
|
| 128 | - /** @var Certificate $c */ |
|
| 129 | - if ($cert->equals($c)) { |
|
| 130 | - return true; |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - return false; |
|
| 134 | - } |
|
| 114 | + /** |
|
| 115 | + * Check whether bundle contains a given certificate. |
|
| 116 | + * |
|
| 117 | + * @param Certificate $cert |
|
| 118 | + * @return bool |
|
| 119 | + */ |
|
| 120 | + public function contains(Certificate $cert): bool |
|
| 121 | + { |
|
| 122 | + $id = self::_getCertKeyId($cert); |
|
| 123 | + $map = $this->_getKeyIdMap(); |
|
| 124 | + if (!isset($map[$id])) { |
|
| 125 | + return false; |
|
| 126 | + } |
|
| 127 | + foreach ($map[$id] as $c) { |
|
| 128 | + /** @var Certificate $c */ |
|
| 129 | + if ($cert->equals($c)) { |
|
| 130 | + return true; |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + return false; |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - /** |
|
| 137 | - * Get all certificates that have given subject key identifier. |
|
| 138 | - * |
|
| 139 | - * @param string $id |
|
| 140 | - * @return Certificate[] |
|
| 141 | - */ |
|
| 142 | - public function allBySubjectKeyIdentifier(string $id): array |
|
| 143 | - { |
|
| 144 | - $map = $this->_getKeyIdMap(); |
|
| 145 | - if (!isset($map[$id])) { |
|
| 146 | - return array(); |
|
| 147 | - } |
|
| 148 | - return $map[$id]; |
|
| 149 | - } |
|
| 136 | + /** |
|
| 137 | + * Get all certificates that have given subject key identifier. |
|
| 138 | + * |
|
| 139 | + * @param string $id |
|
| 140 | + * @return Certificate[] |
|
| 141 | + */ |
|
| 142 | + public function allBySubjectKeyIdentifier(string $id): array |
|
| 143 | + { |
|
| 144 | + $map = $this->_getKeyIdMap(); |
|
| 145 | + if (!isset($map[$id])) { |
|
| 146 | + return array(); |
|
| 147 | + } |
|
| 148 | + return $map[$id]; |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - /** |
|
| 152 | - * Get all certificates in a bundle. |
|
| 153 | - * |
|
| 154 | - * @return Certificate[] |
|
| 155 | - */ |
|
| 156 | - public function all(): array |
|
| 157 | - { |
|
| 158 | - return $this->_certs; |
|
| 159 | - } |
|
| 151 | + /** |
|
| 152 | + * Get all certificates in a bundle. |
|
| 153 | + * |
|
| 154 | + * @return Certificate[] |
|
| 155 | + */ |
|
| 156 | + public function all(): array |
|
| 157 | + { |
|
| 158 | + return $this->_certs; |
|
| 159 | + } |
|
| 160 | 160 | |
| 161 | - /** |
|
| 162 | - * Get certificate mapping by public key id. |
|
| 163 | - * |
|
| 164 | - * @return (Certificate[])[] |
|
| 165 | - */ |
|
| 166 | - private function _getKeyIdMap(): array |
|
| 167 | - { |
|
| 168 | - // lazily build mapping |
|
| 169 | - if (!isset($this->_keyIdMap)) { |
|
| 170 | - $this->_keyIdMap = array(); |
|
| 171 | - foreach ($this->_certs as $cert) { |
|
| 172 | - $id = self::_getCertKeyId($cert); |
|
| 173 | - if (!isset($this->_keyIdMap[$id])) { |
|
| 174 | - $this->_keyIdMap[$id] = array(); |
|
| 175 | - } |
|
| 176 | - array_push($this->_keyIdMap[$id], $cert); |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - return $this->_keyIdMap; |
|
| 180 | - } |
|
| 161 | + /** |
|
| 162 | + * Get certificate mapping by public key id. |
|
| 163 | + * |
|
| 164 | + * @return (Certificate[])[] |
|
| 165 | + */ |
|
| 166 | + private function _getKeyIdMap(): array |
|
| 167 | + { |
|
| 168 | + // lazily build mapping |
|
| 169 | + if (!isset($this->_keyIdMap)) { |
|
| 170 | + $this->_keyIdMap = array(); |
|
| 171 | + foreach ($this->_certs as $cert) { |
|
| 172 | + $id = self::_getCertKeyId($cert); |
|
| 173 | + if (!isset($this->_keyIdMap[$id])) { |
|
| 174 | + $this->_keyIdMap[$id] = array(); |
|
| 175 | + } |
|
| 176 | + array_push($this->_keyIdMap[$id], $cert); |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + return $this->_keyIdMap; |
|
| 180 | + } |
|
| 181 | 181 | |
| 182 | - /** |
|
| 183 | - * Get public key id for the certificate. |
|
| 184 | - * |
|
| 185 | - * @param Certificate $cert |
|
| 186 | - * @return string |
|
| 187 | - */ |
|
| 188 | - private static function _getCertKeyId(Certificate $cert): string |
|
| 189 | - { |
|
| 190 | - $exts = $cert->tbsCertificate()->extensions(); |
|
| 191 | - if ($exts->hasSubjectKeyIdentifier()) { |
|
| 192 | - return $exts->subjectKeyIdentifier()->keyIdentifier(); |
|
| 193 | - } |
|
| 194 | - return $cert->tbsCertificate() |
|
| 195 | - ->subjectPublicKeyInfo() |
|
| 196 | - ->keyIdentifier(); |
|
| 197 | - } |
|
| 182 | + /** |
|
| 183 | + * Get public key id for the certificate. |
|
| 184 | + * |
|
| 185 | + * @param Certificate $cert |
|
| 186 | + * @return string |
|
| 187 | + */ |
|
| 188 | + private static function _getCertKeyId(Certificate $cert): string |
|
| 189 | + { |
|
| 190 | + $exts = $cert->tbsCertificate()->extensions(); |
|
| 191 | + if ($exts->hasSubjectKeyIdentifier()) { |
|
| 192 | + return $exts->subjectKeyIdentifier()->keyIdentifier(); |
|
| 193 | + } |
|
| 194 | + return $cert->tbsCertificate() |
|
| 195 | + ->subjectPublicKeyInfo() |
|
| 196 | + ->keyIdentifier(); |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | - /** |
|
| 200 | - * |
|
| 201 | - * @see \Countable::count() |
|
| 202 | - * @return int |
|
| 203 | - */ |
|
| 204 | - public function count(): int |
|
| 205 | - { |
|
| 206 | - return count($this->_certs); |
|
| 207 | - } |
|
| 199 | + /** |
|
| 200 | + * |
|
| 201 | + * @see \Countable::count() |
|
| 202 | + * @return int |
|
| 203 | + */ |
|
| 204 | + public function count(): int |
|
| 205 | + { |
|
| 206 | + return count($this->_certs); |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | - /** |
|
| 210 | - * Get iterator for certificates. |
|
| 211 | - * |
|
| 212 | - * @see \IteratorAggregate::getIterator() |
|
| 213 | - * @return \ArrayIterator |
|
| 214 | - */ |
|
| 215 | - public function getIterator(): \ArrayIterator |
|
| 216 | - { |
|
| 217 | - return new \ArrayIterator($this->_certs); |
|
| 218 | - } |
|
| 209 | + /** |
|
| 210 | + * Get iterator for certificates. |
|
| 211 | + * |
|
| 212 | + * @see \IteratorAggregate::getIterator() |
|
| 213 | + * @return \ArrayIterator |
|
| 214 | + */ |
|
| 215 | + public function getIterator(): \ArrayIterator |
|
| 216 | + { |
|
| 217 | + return new \ArrayIterator($this->_certs); |
|
| 218 | + } |
|
| 219 | 219 | } |