@@ -11,16 +11,16 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class GroupAttributeValue extends IetfAttrSyntax |
| 13 | 13 | { |
| 14 | - const OID = "1.3.6.1.5.5.7.10.4"; |
|
| 14 | + const OID = "1.3.6.1.5.5.7.10.4"; |
|
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Constructor. |
|
| 18 | - * |
|
| 19 | - * @param IetfAttrValue[] $values |
|
| 20 | - */ |
|
| 21 | - public function __construct(IetfAttrValue ...$values) |
|
| 22 | - { |
|
| 23 | - parent::__construct(...$values); |
|
| 24 | - $this->_oid = self::OID; |
|
| 25 | - } |
|
| 16 | + /** |
|
| 17 | + * Constructor. |
|
| 18 | + * |
|
| 19 | + * @param IetfAttrValue[] $values |
|
| 20 | + */ |
|
| 21 | + public function __construct(IetfAttrValue ...$values) |
|
| 22 | + { |
|
| 23 | + parent::__construct(...$values); |
|
| 24 | + $this->_oid = self::OID; |
|
| 25 | + } |
|
| 26 | 26 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types=1); |
|
| 3 | +declare(strict_types = 1); |
|
| 4 | 4 | |
| 5 | 5 | namespace X509\AttributeCertificate\Attribute; |
| 6 | 6 | |
@@ -17,161 +17,161 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class IetfAttrValue |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * Element type tag. |
|
| 22 | - * |
|
| 23 | - * @var int $_type |
|
| 24 | - */ |
|
| 25 | - protected $_type; |
|
| 20 | + /** |
|
| 21 | + * Element type tag. |
|
| 22 | + * |
|
| 23 | + * @var int $_type |
|
| 24 | + */ |
|
| 25 | + protected $_type; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Value. |
|
| 29 | - * |
|
| 30 | - * @var string $_value |
|
| 31 | - */ |
|
| 32 | - protected $_value; |
|
| 27 | + /** |
|
| 28 | + * Value. |
|
| 29 | + * |
|
| 30 | + * @var string $_value |
|
| 31 | + */ |
|
| 32 | + protected $_value; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Constructor. |
|
| 36 | - * |
|
| 37 | - * @param string $value |
|
| 38 | - * @param int $type |
|
| 39 | - */ |
|
| 40 | - public function __construct(string $value, int $type) |
|
| 41 | - { |
|
| 42 | - $this->_type = $type; |
|
| 43 | - $this->_value = $value; |
|
| 44 | - } |
|
| 34 | + /** |
|
| 35 | + * Constructor. |
|
| 36 | + * |
|
| 37 | + * @param string $value |
|
| 38 | + * @param int $type |
|
| 39 | + */ |
|
| 40 | + public function __construct(string $value, int $type) |
|
| 41 | + { |
|
| 42 | + $this->_type = $type; |
|
| 43 | + $this->_value = $value; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Initialize from ASN.1. |
|
| 48 | - * |
|
| 49 | - * @param UnspecifiedType $el |
|
| 50 | - * @throws \UnexpectedValueException |
|
| 51 | - * @return self |
|
| 52 | - */ |
|
| 53 | - public static function fromASN1(UnspecifiedType $el) |
|
| 54 | - { |
|
| 55 | - switch ($el->tag()) { |
|
| 56 | - case Element::TYPE_OCTET_STRING: |
|
| 57 | - case Element::TYPE_UTF8_STRING: |
|
| 58 | - return new self($el->asString()->string(), $el->tag()); |
|
| 59 | - case Element::TYPE_OBJECT_IDENTIFIER: |
|
| 60 | - return new self($el->asObjectIdentifier()->oid(), $el->tag()); |
|
| 61 | - } |
|
| 62 | - throw new \UnexpectedValueException( |
|
| 63 | - "Type " . Element::tagToName($el->tag()) . " not supported."); |
|
| 64 | - } |
|
| 46 | + /** |
|
| 47 | + * Initialize from ASN.1. |
|
| 48 | + * |
|
| 49 | + * @param UnspecifiedType $el |
|
| 50 | + * @throws \UnexpectedValueException |
|
| 51 | + * @return self |
|
| 52 | + */ |
|
| 53 | + public static function fromASN1(UnspecifiedType $el) |
|
| 54 | + { |
|
| 55 | + switch ($el->tag()) { |
|
| 56 | + case Element::TYPE_OCTET_STRING: |
|
| 57 | + case Element::TYPE_UTF8_STRING: |
|
| 58 | + return new self($el->asString()->string(), $el->tag()); |
|
| 59 | + case Element::TYPE_OBJECT_IDENTIFIER: |
|
| 60 | + return new self($el->asObjectIdentifier()->oid(), $el->tag()); |
|
| 61 | + } |
|
| 62 | + throw new \UnexpectedValueException( |
|
| 63 | + "Type " . Element::tagToName($el->tag()) . " not supported."); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * Initialize from octet string. |
|
| 68 | - * |
|
| 69 | - * @param string $octets |
|
| 70 | - * @return self |
|
| 71 | - */ |
|
| 72 | - public static function fromOctets(string $octets) |
|
| 73 | - { |
|
| 74 | - return new self($octets, Element::TYPE_OCTET_STRING); |
|
| 75 | - } |
|
| 66 | + /** |
|
| 67 | + * Initialize from octet string. |
|
| 68 | + * |
|
| 69 | + * @param string $octets |
|
| 70 | + * @return self |
|
| 71 | + */ |
|
| 72 | + public static function fromOctets(string $octets) |
|
| 73 | + { |
|
| 74 | + return new self($octets, Element::TYPE_OCTET_STRING); |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * Initialize from UTF-8 string. |
|
| 79 | - * |
|
| 80 | - * @param string $str |
|
| 81 | - * @return self |
|
| 82 | - */ |
|
| 83 | - public static function fromString(string $str) |
|
| 84 | - { |
|
| 85 | - return new self($str, Element::TYPE_UTF8_STRING); |
|
| 86 | - } |
|
| 77 | + /** |
|
| 78 | + * Initialize from UTF-8 string. |
|
| 79 | + * |
|
| 80 | + * @param string $str |
|
| 81 | + * @return self |
|
| 82 | + */ |
|
| 83 | + public static function fromString(string $str) |
|
| 84 | + { |
|
| 85 | + return new self($str, Element::TYPE_UTF8_STRING); |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * Initialize from OID. |
|
| 90 | - * |
|
| 91 | - * @param string $oid |
|
| 92 | - * @return self |
|
| 93 | - */ |
|
| 94 | - public static function fromOID(string $oid) |
|
| 95 | - { |
|
| 96 | - return new self($oid, Element::TYPE_OBJECT_IDENTIFIER); |
|
| 97 | - } |
|
| 88 | + /** |
|
| 89 | + * Initialize from OID. |
|
| 90 | + * |
|
| 91 | + * @param string $oid |
|
| 92 | + * @return self |
|
| 93 | + */ |
|
| 94 | + public static function fromOID(string $oid) |
|
| 95 | + { |
|
| 96 | + return new self($oid, Element::TYPE_OBJECT_IDENTIFIER); |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * Get type tag. |
|
| 101 | - * |
|
| 102 | - * @return int |
|
| 103 | - */ |
|
| 104 | - public function type(): int |
|
| 105 | - { |
|
| 106 | - return $this->_type; |
|
| 107 | - } |
|
| 99 | + /** |
|
| 100 | + * Get type tag. |
|
| 101 | + * |
|
| 102 | + * @return int |
|
| 103 | + */ |
|
| 104 | + public function type(): int |
|
| 105 | + { |
|
| 106 | + return $this->_type; |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * Whether value type is octets. |
|
| 111 | - * |
|
| 112 | - * @return bool |
|
| 113 | - */ |
|
| 114 | - public function isOctets(): bool |
|
| 115 | - { |
|
| 116 | - return $this->_type === Element::TYPE_OCTET_STRING; |
|
| 117 | - } |
|
| 109 | + /** |
|
| 110 | + * Whether value type is octets. |
|
| 111 | + * |
|
| 112 | + * @return bool |
|
| 113 | + */ |
|
| 114 | + public function isOctets(): bool |
|
| 115 | + { |
|
| 116 | + return $this->_type === Element::TYPE_OCTET_STRING; |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - /** |
|
| 120 | - * Whether value type is OID. |
|
| 121 | - * |
|
| 122 | - * @return bool |
|
| 123 | - */ |
|
| 124 | - public function isOID(): bool |
|
| 125 | - { |
|
| 126 | - return $this->_type === Element::TYPE_OBJECT_IDENTIFIER; |
|
| 127 | - } |
|
| 119 | + /** |
|
| 120 | + * Whether value type is OID. |
|
| 121 | + * |
|
| 122 | + * @return bool |
|
| 123 | + */ |
|
| 124 | + public function isOID(): bool |
|
| 125 | + { |
|
| 126 | + return $this->_type === Element::TYPE_OBJECT_IDENTIFIER; |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - /** |
|
| 130 | - * Whether value type is string. |
|
| 131 | - * |
|
| 132 | - * @return bool |
|
| 133 | - */ |
|
| 134 | - public function isString(): bool |
|
| 135 | - { |
|
| 136 | - return $this->_type === Element::TYPE_UTF8_STRING; |
|
| 137 | - } |
|
| 129 | + /** |
|
| 130 | + * Whether value type is string. |
|
| 131 | + * |
|
| 132 | + * @return bool |
|
| 133 | + */ |
|
| 134 | + public function isString(): bool |
|
| 135 | + { |
|
| 136 | + return $this->_type === Element::TYPE_UTF8_STRING; |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - /** |
|
| 140 | - * Get value. |
|
| 141 | - * |
|
| 142 | - * @return string |
|
| 143 | - */ |
|
| 144 | - public function value(): string |
|
| 145 | - { |
|
| 146 | - return $this->_value; |
|
| 147 | - } |
|
| 139 | + /** |
|
| 140 | + * Get value. |
|
| 141 | + * |
|
| 142 | + * @return string |
|
| 143 | + */ |
|
| 144 | + public function value(): string |
|
| 145 | + { |
|
| 146 | + return $this->_value; |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - /** |
|
| 150 | - * Generate ASN.1 structure. |
|
| 151 | - * |
|
| 152 | - * @throws \LogicException |
|
| 153 | - * @return Element |
|
| 154 | - */ |
|
| 155 | - public function toASN1(): Element |
|
| 156 | - { |
|
| 157 | - switch ($this->_type) { |
|
| 158 | - case Element::TYPE_OCTET_STRING: |
|
| 159 | - return new OctetString($this->_value); |
|
| 160 | - case Element::TYPE_UTF8_STRING: |
|
| 161 | - return new UTF8String($this->_value); |
|
| 162 | - case Element::TYPE_OBJECT_IDENTIFIER: |
|
| 163 | - return new ObjectIdentifier($this->_value); |
|
| 164 | - } |
|
| 165 | - throw new \LogicException( |
|
| 166 | - "Type " . Element::tagToName($this->_type) . " not supported."); |
|
| 167 | - } |
|
| 149 | + /** |
|
| 150 | + * Generate ASN.1 structure. |
|
| 151 | + * |
|
| 152 | + * @throws \LogicException |
|
| 153 | + * @return Element |
|
| 154 | + */ |
|
| 155 | + public function toASN1(): Element |
|
| 156 | + { |
|
| 157 | + switch ($this->_type) { |
|
| 158 | + case Element::TYPE_OCTET_STRING: |
|
| 159 | + return new OctetString($this->_value); |
|
| 160 | + case Element::TYPE_UTF8_STRING: |
|
| 161 | + return new UTF8String($this->_value); |
|
| 162 | + case Element::TYPE_OBJECT_IDENTIFIER: |
|
| 163 | + return new ObjectIdentifier($this->_value); |
|
| 164 | + } |
|
| 165 | + throw new \LogicException( |
|
| 166 | + "Type " . Element::tagToName($this->_type) . " not supported."); |
|
| 167 | + } |
|
| 168 | 168 | |
| 169 | - /** |
|
| 170 | - * |
|
| 171 | - * @return string |
|
| 172 | - */ |
|
| 173 | - public function __toString() |
|
| 174 | - { |
|
| 175 | - return $this->_value; |
|
| 176 | - } |
|
| 169 | + /** |
|
| 170 | + * |
|
| 171 | + * @return string |
|
| 172 | + */ |
|
| 173 | + public function __toString() |
|
| 174 | + { |
|
| 175 | + return $this->_value; |
|
| 176 | + } |
|
| 177 | 177 | } |
@@ -53,11 +53,11 @@ discard block |
||
| 53 | 53 | public static function fromASN1(UnspecifiedType $el) |
| 54 | 54 | { |
| 55 | 55 | switch ($el->tag()) { |
| 56 | - case Element::TYPE_OCTET_STRING: |
|
| 57 | - case Element::TYPE_UTF8_STRING: |
|
| 58 | - return new self($el->asString()->string(), $el->tag()); |
|
| 59 | - case Element::TYPE_OBJECT_IDENTIFIER: |
|
| 60 | - return new self($el->asObjectIdentifier()->oid(), $el->tag()); |
|
| 56 | + case Element::TYPE_OCTET_STRING: |
|
| 57 | + case Element::TYPE_UTF8_STRING: |
|
| 58 | + return new self($el->asString()->string(), $el->tag()); |
|
| 59 | + case Element::TYPE_OBJECT_IDENTIFIER: |
|
| 60 | + return new self($el->asObjectIdentifier()->oid(), $el->tag()); |
|
| 61 | 61 | } |
| 62 | 62 | throw new \UnexpectedValueException( |
| 63 | 63 | "Type " . Element::tagToName($el->tag()) . " not supported."); |
@@ -155,12 +155,12 @@ discard block |
||
| 155 | 155 | public function toASN1(): Element |
| 156 | 156 | { |
| 157 | 157 | switch ($this->_type) { |
| 158 | - case Element::TYPE_OCTET_STRING: |
|
| 159 | - return new OctetString($this->_value); |
|
| 160 | - case Element::TYPE_UTF8_STRING: |
|
| 161 | - return new UTF8String($this->_value); |
|
| 162 | - case Element::TYPE_OBJECT_IDENTIFIER: |
|
| 163 | - return new ObjectIdentifier($this->_value); |
|
| 158 | + case Element::TYPE_OCTET_STRING: |
|
| 159 | + return new OctetString($this->_value); |
|
| 160 | + case Element::TYPE_UTF8_STRING: |
|
| 161 | + return new UTF8String($this->_value); |
|
| 162 | + case Element::TYPE_OBJECT_IDENTIFIER: |
|
| 163 | + return new ObjectIdentifier($this->_value); |
|
| 164 | 164 | } |
| 165 | 165 | throw new \LogicException( |
| 166 | 166 | "Type " . Element::tagToName($this->_type) . " not supported."); |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types=1); |
|
| 3 | +declare(strict_types = 1); |
|
| 4 | 4 | |
| 5 | 5 | namespace X509\AttributeCertificate\Attribute; |
| 6 | 6 | |
@@ -11,16 +11,16 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class ChargingIdentityAttributeValue extends IetfAttrSyntax |
| 13 | 13 | { |
| 14 | - const OID = "1.3.6.1.5.5.7.10.3"; |
|
| 14 | + const OID = "1.3.6.1.5.5.7.10.3"; |
|
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Constructor. |
|
| 18 | - * |
|
| 19 | - * @param IetfAttrValue[] $values |
|
| 20 | - */ |
|
| 21 | - public function __construct(IetfAttrValue ...$values) |
|
| 22 | - { |
|
| 23 | - parent::__construct(...$values); |
|
| 24 | - $this->_oid = self::OID; |
|
| 25 | - } |
|
| 16 | + /** |
|
| 17 | + * Constructor. |
|
| 18 | + * |
|
| 19 | + * @param IetfAttrValue[] $values |
|
| 20 | + */ |
|
| 21 | + public function __construct(IetfAttrValue ...$values) |
|
| 22 | + { |
|
| 23 | + parent::__construct(...$values); |
|
| 24 | + $this->_oid = self::OID; |
|
| 25 | + } |
|
| 26 | 26 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types=1); |
|
| 3 | +declare(strict_types = 1); |
|
| 4 | 4 | |
| 5 | 5 | namespace X509\AttributeCertificate\Attribute; |
| 6 | 6 | |
@@ -23,154 +23,154 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | class RoleAttributeValue extends AttributeValue |
| 25 | 25 | { |
| 26 | - /** |
|
| 27 | - * Issuing authority. |
|
| 28 | - * |
|
| 29 | - * @var GeneralNames $_roleAuthority |
|
| 30 | - */ |
|
| 31 | - protected $_roleAuthority; |
|
| 26 | + /** |
|
| 27 | + * Issuing authority. |
|
| 28 | + * |
|
| 29 | + * @var GeneralNames $_roleAuthority |
|
| 30 | + */ |
|
| 31 | + protected $_roleAuthority; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Role name. |
|
| 35 | - * |
|
| 36 | - * @var GeneralName $_roleName |
|
| 37 | - */ |
|
| 38 | - protected $_roleName; |
|
| 33 | + /** |
|
| 34 | + * Role name. |
|
| 35 | + * |
|
| 36 | + * @var GeneralName $_roleName |
|
| 37 | + */ |
|
| 38 | + protected $_roleName; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Constructor. |
|
| 42 | - * |
|
| 43 | - * @param GeneralName $name Role name |
|
| 44 | - * @param GeneralNames|null $authority Issuing authority |
|
| 45 | - */ |
|
| 46 | - public function __construct(GeneralName $name, GeneralNames $authority = null) |
|
| 47 | - { |
|
| 48 | - $this->_roleAuthority = $authority; |
|
| 49 | - $this->_roleName = $name; |
|
| 50 | - $this->_oid = AttributeType::OID_ROLE; |
|
| 51 | - } |
|
| 40 | + /** |
|
| 41 | + * Constructor. |
|
| 42 | + * |
|
| 43 | + * @param GeneralName $name Role name |
|
| 44 | + * @param GeneralNames|null $authority Issuing authority |
|
| 45 | + */ |
|
| 46 | + public function __construct(GeneralName $name, GeneralNames $authority = null) |
|
| 47 | + { |
|
| 48 | + $this->_roleAuthority = $authority; |
|
| 49 | + $this->_roleName = $name; |
|
| 50 | + $this->_oid = AttributeType::OID_ROLE; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Initialize from a role string. |
|
| 55 | - * |
|
| 56 | - * @param string $role_name Role name in URI format |
|
| 57 | - * @param GeneralNames|null $authority Issuing authority |
|
| 58 | - * @return self |
|
| 59 | - */ |
|
| 60 | - public static function fromString(string $role_name, GeneralNames $authority = null) |
|
| 61 | - { |
|
| 62 | - return new self(new UniformResourceIdentifier($role_name), $authority); |
|
| 63 | - } |
|
| 53 | + /** |
|
| 54 | + * Initialize from a role string. |
|
| 55 | + * |
|
| 56 | + * @param string $role_name Role name in URI format |
|
| 57 | + * @param GeneralNames|null $authority Issuing authority |
|
| 58 | + * @return self |
|
| 59 | + */ |
|
| 60 | + public static function fromString(string $role_name, GeneralNames $authority = null) |
|
| 61 | + { |
|
| 62 | + return new self(new UniformResourceIdentifier($role_name), $authority); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * |
|
| 67 | - * @param UnspecifiedType $el |
|
| 68 | - * @return self |
|
| 69 | - */ |
|
| 70 | - public static function fromASN1(UnspecifiedType $el) |
|
| 71 | - { |
|
| 72 | - $seq = $el->asSequence(); |
|
| 73 | - $authority = null; |
|
| 74 | - if ($seq->hasTagged(0)) { |
|
| 75 | - $authority = GeneralNames::fromASN1( |
|
| 76 | - $seq->getTagged(0) |
|
| 77 | - ->asImplicit(Element::TYPE_SEQUENCE) |
|
| 78 | - ->asSequence()); |
|
| 79 | - } |
|
| 80 | - $name = GeneralName::fromASN1( |
|
| 81 | - $seq->getTagged(1) |
|
| 82 | - ->asExplicit() |
|
| 83 | - ->asTagged()); |
|
| 84 | - return new self($name, $authority); |
|
| 85 | - } |
|
| 65 | + /** |
|
| 66 | + * |
|
| 67 | + * @param UnspecifiedType $el |
|
| 68 | + * @return self |
|
| 69 | + */ |
|
| 70 | + public static function fromASN1(UnspecifiedType $el) |
|
| 71 | + { |
|
| 72 | + $seq = $el->asSequence(); |
|
| 73 | + $authority = null; |
|
| 74 | + if ($seq->hasTagged(0)) { |
|
| 75 | + $authority = GeneralNames::fromASN1( |
|
| 76 | + $seq->getTagged(0) |
|
| 77 | + ->asImplicit(Element::TYPE_SEQUENCE) |
|
| 78 | + ->asSequence()); |
|
| 79 | + } |
|
| 80 | + $name = GeneralName::fromASN1( |
|
| 81 | + $seq->getTagged(1) |
|
| 82 | + ->asExplicit() |
|
| 83 | + ->asTagged()); |
|
| 84 | + return new self($name, $authority); |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * Check whether issuing authority is present. |
|
| 89 | - * |
|
| 90 | - * @return bool |
|
| 91 | - */ |
|
| 92 | - public function hasRoleAuthority(): bool |
|
| 93 | - { |
|
| 94 | - return isset($this->_roleAuthority); |
|
| 95 | - } |
|
| 87 | + /** |
|
| 88 | + * Check whether issuing authority is present. |
|
| 89 | + * |
|
| 90 | + * @return bool |
|
| 91 | + */ |
|
| 92 | + public function hasRoleAuthority(): bool |
|
| 93 | + { |
|
| 94 | + return isset($this->_roleAuthority); |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * Get issuing authority. |
|
| 99 | - * |
|
| 100 | - * @throws \LogicException |
|
| 101 | - * @return GeneralNames |
|
| 102 | - */ |
|
| 103 | - public function roleAuthority(): GeneralNames |
|
| 104 | - { |
|
| 105 | - if (!$this->hasRoleAuthority()) { |
|
| 106 | - throw new \LogicException("roleAuthority not set."); |
|
| 107 | - } |
|
| 108 | - return $this->_roleAuthority; |
|
| 109 | - } |
|
| 97 | + /** |
|
| 98 | + * Get issuing authority. |
|
| 99 | + * |
|
| 100 | + * @throws \LogicException |
|
| 101 | + * @return GeneralNames |
|
| 102 | + */ |
|
| 103 | + public function roleAuthority(): GeneralNames |
|
| 104 | + { |
|
| 105 | + if (!$this->hasRoleAuthority()) { |
|
| 106 | + throw new \LogicException("roleAuthority not set."); |
|
| 107 | + } |
|
| 108 | + return $this->_roleAuthority; |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * Get role name. |
|
| 113 | - * |
|
| 114 | - * @return GeneralName |
|
| 115 | - */ |
|
| 116 | - public function roleName(): GeneralName |
|
| 117 | - { |
|
| 118 | - return $this->_roleName; |
|
| 119 | - } |
|
| 111 | + /** |
|
| 112 | + * Get role name. |
|
| 113 | + * |
|
| 114 | + * @return GeneralName |
|
| 115 | + */ |
|
| 116 | + public function roleName(): GeneralName |
|
| 117 | + { |
|
| 118 | + return $this->_roleName; |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | - /** |
|
| 122 | - * |
|
| 123 | - * @see \X501\ASN1\AttributeValue\AttributeValue::toASN1() |
|
| 124 | - * @return Sequence |
|
| 125 | - */ |
|
| 126 | - public function toASN1(): Sequence |
|
| 127 | - { |
|
| 128 | - $elements = array(); |
|
| 129 | - if (isset($this->_roleAuthority)) { |
|
| 130 | - $elements[] = new ImplicitlyTaggedType(0, |
|
| 131 | - $this->_roleAuthority->toASN1()); |
|
| 132 | - } |
|
| 133 | - $elements[] = new ExplicitlyTaggedType(1, $this->_roleName->toASN1()); |
|
| 134 | - return new Sequence(...$elements); |
|
| 135 | - } |
|
| 121 | + /** |
|
| 122 | + * |
|
| 123 | + * @see \X501\ASN1\AttributeValue\AttributeValue::toASN1() |
|
| 124 | + * @return Sequence |
|
| 125 | + */ |
|
| 126 | + public function toASN1(): Sequence |
|
| 127 | + { |
|
| 128 | + $elements = array(); |
|
| 129 | + if (isset($this->_roleAuthority)) { |
|
| 130 | + $elements[] = new ImplicitlyTaggedType(0, |
|
| 131 | + $this->_roleAuthority->toASN1()); |
|
| 132 | + } |
|
| 133 | + $elements[] = new ExplicitlyTaggedType(1, $this->_roleName->toASN1()); |
|
| 134 | + return new Sequence(...$elements); |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | - /** |
|
| 138 | - * |
|
| 139 | - * @see \X501\ASN1\AttributeValue\AttributeValue::stringValue() |
|
| 140 | - * @return string |
|
| 141 | - */ |
|
| 142 | - public function stringValue(): string |
|
| 143 | - { |
|
| 144 | - return "#" . bin2hex($this->toASN1()->toDER()); |
|
| 145 | - } |
|
| 137 | + /** |
|
| 138 | + * |
|
| 139 | + * @see \X501\ASN1\AttributeValue\AttributeValue::stringValue() |
|
| 140 | + * @return string |
|
| 141 | + */ |
|
| 142 | + public function stringValue(): string |
|
| 143 | + { |
|
| 144 | + return "#" . bin2hex($this->toASN1()->toDER()); |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - /** |
|
| 148 | - * |
|
| 149 | - * @see \X501\ASN1\AttributeValue\AttributeValue::equalityMatchingRule() |
|
| 150 | - * @return BinaryMatch |
|
| 151 | - */ |
|
| 152 | - public function equalityMatchingRule(): BinaryMatch |
|
| 153 | - { |
|
| 154 | - return new BinaryMatch(); |
|
| 155 | - } |
|
| 147 | + /** |
|
| 148 | + * |
|
| 149 | + * @see \X501\ASN1\AttributeValue\AttributeValue::equalityMatchingRule() |
|
| 150 | + * @return BinaryMatch |
|
| 151 | + */ |
|
| 152 | + public function equalityMatchingRule(): BinaryMatch |
|
| 153 | + { |
|
| 154 | + return new BinaryMatch(); |
|
| 155 | + } |
|
| 156 | 156 | |
| 157 | - /** |
|
| 158 | - * |
|
| 159 | - * @see \X501\ASN1\AttributeValue\AttributeValue::rfc2253String() |
|
| 160 | - * @return string |
|
| 161 | - */ |
|
| 162 | - public function rfc2253String(): string |
|
| 163 | - { |
|
| 164 | - return $this->stringValue(); |
|
| 165 | - } |
|
| 157 | + /** |
|
| 158 | + * |
|
| 159 | + * @see \X501\ASN1\AttributeValue\AttributeValue::rfc2253String() |
|
| 160 | + * @return string |
|
| 161 | + */ |
|
| 162 | + public function rfc2253String(): string |
|
| 163 | + { |
|
| 164 | + return $this->stringValue(); |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | - /** |
|
| 168 | - * |
|
| 169 | - * @see \X501\ASN1\AttributeValue\AttributeValue::_transcodedString() |
|
| 170 | - * @return string |
|
| 171 | - */ |
|
| 172 | - protected function _transcodedString(): string |
|
| 173 | - { |
|
| 174 | - return $this->stringValue(); |
|
| 175 | - } |
|
| 167 | + /** |
|
| 168 | + * |
|
| 169 | + * @see \X501\ASN1\AttributeValue\AttributeValue::_transcodedString() |
|
| 170 | + * @return string |
|
| 171 | + */ |
|
| 172 | + protected function _transcodedString(): string |
|
| 173 | + { |
|
| 174 | + return $this->stringValue(); |
|
| 175 | + } |
|
| 176 | 176 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types=1); |
|
| 3 | +declare(strict_types = 1); |
|
| 4 | 4 | |
| 5 | 5 | namespace X509\AttributeCertificate\Attribute; |
| 6 | 6 | |
@@ -13,19 +13,19 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class AuthenticationInfoAttributeValue extends SvceAuthInfo |
| 15 | 15 | { |
| 16 | - const OID = "1.3.6.1.5.5.7.10.1"; |
|
| 16 | + const OID = "1.3.6.1.5.5.7.10.1"; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Constructor. |
|
| 20 | - * |
|
| 21 | - * @param GeneralName $service |
|
| 22 | - * @param GeneralName $ident |
|
| 23 | - * @param string|null $auth_info |
|
| 24 | - */ |
|
| 25 | - public function __construct(GeneralName $service, GeneralName $ident, |
|
| 26 | - string $auth_info = null) |
|
| 27 | - { |
|
| 28 | - parent::__construct($service, $ident, $auth_info); |
|
| 29 | - $this->_oid = self::OID; |
|
| 30 | - } |
|
| 18 | + /** |
|
| 19 | + * Constructor. |
|
| 20 | + * |
|
| 21 | + * @param GeneralName $service |
|
| 22 | + * @param GeneralName $ident |
|
| 23 | + * @param string|null $auth_info |
|
| 24 | + */ |
|
| 25 | + public function __construct(GeneralName $service, GeneralName $ident, |
|
| 26 | + string $auth_info = null) |
|
| 27 | + { |
|
| 28 | + parent::__construct($service, $ident, $auth_info); |
|
| 29 | + $this->_oid = self::OID; |
|
| 30 | + } |
|
| 31 | 31 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types=1); |
|
| 3 | +declare(strict_types = 1); |
|
| 4 | 4 | |
| 5 | 5 | namespace X509\AttributeCertificate\Attribute; |
| 6 | 6 | |
@@ -20,203 +20,203 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | class AttributeCertificate |
| 22 | 22 | { |
| 23 | - /** |
|
| 24 | - * Attribute certificate info. |
|
| 25 | - * |
|
| 26 | - * @var AttributeCertificateInfo $_acinfo |
|
| 27 | - */ |
|
| 28 | - protected $_acinfo; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Signature algorithm identifier. |
|
| 32 | - * |
|
| 33 | - * @var SignatureAlgorithmIdentifier $_signatureAlgorithm |
|
| 34 | - */ |
|
| 35 | - protected $_signatureAlgorithm; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Signature value. |
|
| 39 | - * |
|
| 40 | - * @var Signature $_signatureValue |
|
| 41 | - */ |
|
| 42 | - protected $_signatureValue; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Constructor. |
|
| 46 | - * |
|
| 47 | - * @param AttributeCertificateInfo $acinfo |
|
| 48 | - * @param SignatureAlgorithmIdentifier $algo |
|
| 49 | - * @param Signature $signature |
|
| 50 | - */ |
|
| 51 | - public function __construct(AttributeCertificateInfo $acinfo, |
|
| 52 | - SignatureAlgorithmIdentifier $algo, Signature $signature) |
|
| 53 | - { |
|
| 54 | - $this->_acinfo = $acinfo; |
|
| 55 | - $this->_signatureAlgorithm = $algo; |
|
| 56 | - $this->_signatureValue = $signature; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * Initialize from ASN.1. |
|
| 61 | - * |
|
| 62 | - * @param Sequence $seq |
|
| 63 | - * @return self |
|
| 64 | - */ |
|
| 65 | - public static function fromASN1(Sequence $seq) |
|
| 66 | - { |
|
| 67 | - $acinfo = AttributeCertificateInfo::fromASN1($seq->at(0)->asSequence()); |
|
| 68 | - $algo = AlgorithmIdentifier::fromASN1($seq->at(1)->asSequence()); |
|
| 69 | - if (!$algo instanceof SignatureAlgorithmIdentifier) { |
|
| 70 | - throw new \UnexpectedValueException( |
|
| 71 | - "Unsupported signature algorithm " . $algo->oid() . "."); |
|
| 72 | - } |
|
| 73 | - $signature = Signature::fromSignatureData( |
|
| 74 | - $seq->at(2) |
|
| 75 | - ->asBitString() |
|
| 76 | - ->string(), $algo); |
|
| 77 | - return new self($acinfo, $algo, $signature); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Initialize from DER data. |
|
| 82 | - * |
|
| 83 | - * @param string $data |
|
| 84 | - * @return self |
|
| 85 | - */ |
|
| 86 | - public static function fromDER(string $data) |
|
| 87 | - { |
|
| 88 | - return self::fromASN1(Sequence::fromDER($data)); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Initialize from PEM. |
|
| 93 | - * |
|
| 94 | - * @param PEM $pem |
|
| 95 | - * @throws \UnexpectedValueException |
|
| 96 | - * @return self |
|
| 97 | - */ |
|
| 98 | - public static function fromPEM(PEM $pem) |
|
| 99 | - { |
|
| 100 | - if ($pem->type() !== PEM::TYPE_ATTRIBUTE_CERTIFICATE) { |
|
| 101 | - throw new \UnexpectedValueException("Invalid PEM type."); |
|
| 102 | - } |
|
| 103 | - return self::fromDER($pem->data()); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Get attribute certificate info. |
|
| 108 | - * |
|
| 109 | - * @return AttributeCertificateInfo |
|
| 110 | - */ |
|
| 111 | - public function acinfo(): AttributeCertificateInfo |
|
| 112 | - { |
|
| 113 | - return $this->_acinfo; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * Get signature algorithm identifier. |
|
| 118 | - * |
|
| 119 | - * @return SignatureAlgorithmIdentifier |
|
| 120 | - */ |
|
| 121 | - public function signatureAlgorithm(): SignatureAlgorithmIdentifier |
|
| 122 | - { |
|
| 123 | - return $this->_signatureAlgorithm; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Get signature value. |
|
| 128 | - * |
|
| 129 | - * @return Signature |
|
| 130 | - */ |
|
| 131 | - public function signatureValue(): Signature |
|
| 132 | - { |
|
| 133 | - return $this->_signatureValue; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Get ASN.1 structure. |
|
| 138 | - * |
|
| 139 | - * @return Sequence |
|
| 140 | - */ |
|
| 141 | - public function toASN1(): Sequence |
|
| 142 | - { |
|
| 143 | - return new Sequence($this->_acinfo->toASN1(), |
|
| 144 | - $this->_signatureAlgorithm->toASN1(), |
|
| 145 | - $this->_signatureValue->bitString()); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * Get attribute certificate as a DER. |
|
| 150 | - * |
|
| 151 | - * @return string |
|
| 152 | - */ |
|
| 153 | - public function toDER(): string |
|
| 154 | - { |
|
| 155 | - return $this->toASN1()->toDER(); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * Get attribute certificate as a PEM. |
|
| 160 | - * |
|
| 161 | - * @return PEM |
|
| 162 | - */ |
|
| 163 | - public function toPEM(): PEM |
|
| 164 | - { |
|
| 165 | - return new PEM(PEM::TYPE_ATTRIBUTE_CERTIFICATE, $this->toDER()); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * Check whether attribute certificate is issued to the subject identified |
|
| 170 | - * by given public key certificate. |
|
| 171 | - * |
|
| 172 | - * @param Certificate $cert Certificate |
|
| 173 | - * @return boolean |
|
| 174 | - */ |
|
| 175 | - public function isHeldBy(Certificate $cert): bool |
|
| 176 | - { |
|
| 177 | - if (!$this->_acinfo->holder()->identifiesPKC($cert)) { |
|
| 178 | - return false; |
|
| 179 | - } |
|
| 180 | - return true; |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * Check whether attribute certificate is issued by given public key |
|
| 185 | - * certificate. |
|
| 186 | - * |
|
| 187 | - * @param Certificate $cert Certificate |
|
| 188 | - * @return boolean |
|
| 189 | - */ |
|
| 190 | - public function isIssuedBy(Certificate $cert): bool |
|
| 191 | - { |
|
| 192 | - if (!$this->_acinfo->issuer()->identifiesPKC($cert)) { |
|
| 193 | - return false; |
|
| 194 | - } |
|
| 195 | - return true; |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - /** |
|
| 199 | - * Verify signature. |
|
| 200 | - * |
|
| 201 | - * @param PublicKeyInfo $pubkey_info Signer's public key |
|
| 202 | - * @param Crypto|null $crypto Crypto engine, use default if not set |
|
| 203 | - * @return bool |
|
| 204 | - */ |
|
| 205 | - public function verify(PublicKeyInfo $pubkey_info, Crypto $crypto = null): bool |
|
| 206 | - { |
|
| 207 | - $crypto = $crypto ?: Crypto::getDefault(); |
|
| 208 | - $data = $this->_acinfo->toASN1()->toDER(); |
|
| 209 | - return $crypto->verify($data, $this->_signatureValue, $pubkey_info, |
|
| 210 | - $this->_signatureAlgorithm); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * Get attribute certificate as a PEM formatted string. |
|
| 215 | - * |
|
| 216 | - * @return string |
|
| 217 | - */ |
|
| 218 | - public function __toString() |
|
| 219 | - { |
|
| 220 | - return $this->toPEM()->string(); |
|
| 221 | - } |
|
| 23 | + /** |
|
| 24 | + * Attribute certificate info. |
|
| 25 | + * |
|
| 26 | + * @var AttributeCertificateInfo $_acinfo |
|
| 27 | + */ |
|
| 28 | + protected $_acinfo; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Signature algorithm identifier. |
|
| 32 | + * |
|
| 33 | + * @var SignatureAlgorithmIdentifier $_signatureAlgorithm |
|
| 34 | + */ |
|
| 35 | + protected $_signatureAlgorithm; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Signature value. |
|
| 39 | + * |
|
| 40 | + * @var Signature $_signatureValue |
|
| 41 | + */ |
|
| 42 | + protected $_signatureValue; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Constructor. |
|
| 46 | + * |
|
| 47 | + * @param AttributeCertificateInfo $acinfo |
|
| 48 | + * @param SignatureAlgorithmIdentifier $algo |
|
| 49 | + * @param Signature $signature |
|
| 50 | + */ |
|
| 51 | + public function __construct(AttributeCertificateInfo $acinfo, |
|
| 52 | + SignatureAlgorithmIdentifier $algo, Signature $signature) |
|
| 53 | + { |
|
| 54 | + $this->_acinfo = $acinfo; |
|
| 55 | + $this->_signatureAlgorithm = $algo; |
|
| 56 | + $this->_signatureValue = $signature; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * Initialize from ASN.1. |
|
| 61 | + * |
|
| 62 | + * @param Sequence $seq |
|
| 63 | + * @return self |
|
| 64 | + */ |
|
| 65 | + public static function fromASN1(Sequence $seq) |
|
| 66 | + { |
|
| 67 | + $acinfo = AttributeCertificateInfo::fromASN1($seq->at(0)->asSequence()); |
|
| 68 | + $algo = AlgorithmIdentifier::fromASN1($seq->at(1)->asSequence()); |
|
| 69 | + if (!$algo instanceof SignatureAlgorithmIdentifier) { |
|
| 70 | + throw new \UnexpectedValueException( |
|
| 71 | + "Unsupported signature algorithm " . $algo->oid() . "."); |
|
| 72 | + } |
|
| 73 | + $signature = Signature::fromSignatureData( |
|
| 74 | + $seq->at(2) |
|
| 75 | + ->asBitString() |
|
| 76 | + ->string(), $algo); |
|
| 77 | + return new self($acinfo, $algo, $signature); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Initialize from DER data. |
|
| 82 | + * |
|
| 83 | + * @param string $data |
|
| 84 | + * @return self |
|
| 85 | + */ |
|
| 86 | + public static function fromDER(string $data) |
|
| 87 | + { |
|
| 88 | + return self::fromASN1(Sequence::fromDER($data)); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Initialize from PEM. |
|
| 93 | + * |
|
| 94 | + * @param PEM $pem |
|
| 95 | + * @throws \UnexpectedValueException |
|
| 96 | + * @return self |
|
| 97 | + */ |
|
| 98 | + public static function fromPEM(PEM $pem) |
|
| 99 | + { |
|
| 100 | + if ($pem->type() !== PEM::TYPE_ATTRIBUTE_CERTIFICATE) { |
|
| 101 | + throw new \UnexpectedValueException("Invalid PEM type."); |
|
| 102 | + } |
|
| 103 | + return self::fromDER($pem->data()); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Get attribute certificate info. |
|
| 108 | + * |
|
| 109 | + * @return AttributeCertificateInfo |
|
| 110 | + */ |
|
| 111 | + public function acinfo(): AttributeCertificateInfo |
|
| 112 | + { |
|
| 113 | + return $this->_acinfo; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * Get signature algorithm identifier. |
|
| 118 | + * |
|
| 119 | + * @return SignatureAlgorithmIdentifier |
|
| 120 | + */ |
|
| 121 | + public function signatureAlgorithm(): SignatureAlgorithmIdentifier |
|
| 122 | + { |
|
| 123 | + return $this->_signatureAlgorithm; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Get signature value. |
|
| 128 | + * |
|
| 129 | + * @return Signature |
|
| 130 | + */ |
|
| 131 | + public function signatureValue(): Signature |
|
| 132 | + { |
|
| 133 | + return $this->_signatureValue; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Get ASN.1 structure. |
|
| 138 | + * |
|
| 139 | + * @return Sequence |
|
| 140 | + */ |
|
| 141 | + public function toASN1(): Sequence |
|
| 142 | + { |
|
| 143 | + return new Sequence($this->_acinfo->toASN1(), |
|
| 144 | + $this->_signatureAlgorithm->toASN1(), |
|
| 145 | + $this->_signatureValue->bitString()); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * Get attribute certificate as a DER. |
|
| 150 | + * |
|
| 151 | + * @return string |
|
| 152 | + */ |
|
| 153 | + public function toDER(): string |
|
| 154 | + { |
|
| 155 | + return $this->toASN1()->toDER(); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * Get attribute certificate as a PEM. |
|
| 160 | + * |
|
| 161 | + * @return PEM |
|
| 162 | + */ |
|
| 163 | + public function toPEM(): PEM |
|
| 164 | + { |
|
| 165 | + return new PEM(PEM::TYPE_ATTRIBUTE_CERTIFICATE, $this->toDER()); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * Check whether attribute certificate is issued to the subject identified |
|
| 170 | + * by given public key certificate. |
|
| 171 | + * |
|
| 172 | + * @param Certificate $cert Certificate |
|
| 173 | + * @return boolean |
|
| 174 | + */ |
|
| 175 | + public function isHeldBy(Certificate $cert): bool |
|
| 176 | + { |
|
| 177 | + if (!$this->_acinfo->holder()->identifiesPKC($cert)) { |
|
| 178 | + return false; |
|
| 179 | + } |
|
| 180 | + return true; |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * Check whether attribute certificate is issued by given public key |
|
| 185 | + * certificate. |
|
| 186 | + * |
|
| 187 | + * @param Certificate $cert Certificate |
|
| 188 | + * @return boolean |
|
| 189 | + */ |
|
| 190 | + public function isIssuedBy(Certificate $cert): bool |
|
| 191 | + { |
|
| 192 | + if (!$this->_acinfo->issuer()->identifiesPKC($cert)) { |
|
| 193 | + return false; |
|
| 194 | + } |
|
| 195 | + return true; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * Verify signature. |
|
| 200 | + * |
|
| 201 | + * @param PublicKeyInfo $pubkey_info Signer's public key |
|
| 202 | + * @param Crypto|null $crypto Crypto engine, use default if not set |
|
| 203 | + * @return bool |
|
| 204 | + */ |
|
| 205 | + public function verify(PublicKeyInfo $pubkey_info, Crypto $crypto = null): bool |
|
| 206 | + { |
|
| 207 | + $crypto = $crypto ?: Crypto::getDefault(); |
|
| 208 | + $data = $this->_acinfo->toASN1()->toDER(); |
|
| 209 | + return $crypto->verify($data, $this->_signatureValue, $pubkey_info, |
|
| 210 | + $this->_signatureAlgorithm); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * Get attribute certificate as a PEM formatted string. |
|
| 215 | + * |
|
| 216 | + * @return string |
|
| 217 | + */ |
|
| 218 | + public function __toString() |
|
| 219 | + { |
|
| 220 | + return $this->toPEM()->string(); |
|
| 221 | + } |
|
| 222 | 222 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types=1); |
|
| 3 | +declare(strict_types = 1); |
|
| 4 | 4 | |
| 5 | 5 | namespace X509\AttributeCertificate; |
| 6 | 6 | |
@@ -22,435 +22,435 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | class AttributeCertificateInfo |
| 24 | 24 | { |
| 25 | - const VERSION_2 = 1; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * AC version. |
|
| 29 | - * |
|
| 30 | - * @var int $_version |
|
| 31 | - */ |
|
| 32 | - protected $_version; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * AC holder. |
|
| 36 | - * |
|
| 37 | - * @var Holder $_holder |
|
| 38 | - */ |
|
| 39 | - protected $_holder; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * AC issuer. |
|
| 43 | - * |
|
| 44 | - * @var AttCertIssuer $_issuer |
|
| 45 | - */ |
|
| 46 | - protected $_issuer; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * Signature algorithm identifier. |
|
| 50 | - * |
|
| 51 | - * @var SignatureAlgorithmIdentifier $_signature |
|
| 52 | - */ |
|
| 53 | - protected $_signature; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * AC serial number. |
|
| 57 | - * |
|
| 58 | - * @var int|string $_serialNumber |
|
| 59 | - */ |
|
| 60 | - protected $_serialNumber; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Validity period. |
|
| 64 | - * |
|
| 65 | - * @var AttCertValidityPeriod $_attrCertValidityPeriod |
|
| 66 | - */ |
|
| 67 | - protected $_attrCertValidityPeriod; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Attributes. |
|
| 71 | - * |
|
| 72 | - * @var Attributes $_attributes |
|
| 73 | - */ |
|
| 74 | - protected $_attributes; |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Issuer unique identifier. |
|
| 78 | - * |
|
| 79 | - * @var UniqueIdentifier|null $_issuerUniqueID |
|
| 80 | - */ |
|
| 81 | - protected $_issuerUniqueID; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Extensions. |
|
| 85 | - * |
|
| 86 | - * @var Extensions $_extensions |
|
| 87 | - */ |
|
| 88 | - protected $_extensions; |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * Constructor. |
|
| 92 | - * |
|
| 93 | - * @param Holder $holder AC holder |
|
| 94 | - * @param AttCertIssuer $issuer AC issuer |
|
| 95 | - * @param AttCertValidityPeriod $validity Validity |
|
| 96 | - * @param Attributes $attribs Attributes |
|
| 97 | - */ |
|
| 98 | - public function __construct(Holder $holder, AttCertIssuer $issuer, |
|
| 99 | - AttCertValidityPeriod $validity, Attributes $attribs) |
|
| 100 | - { |
|
| 101 | - $this->_version = self::VERSION_2; |
|
| 102 | - $this->_holder = $holder; |
|
| 103 | - $this->_issuer = $issuer; |
|
| 104 | - $this->_attrCertValidityPeriod = $validity; |
|
| 105 | - $this->_attributes = $attribs; |
|
| 106 | - $this->_extensions = new Extensions(); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Initialize from ASN.1. |
|
| 111 | - * |
|
| 112 | - * @param Sequence $seq |
|
| 113 | - * @throws \UnexpectedValueException |
|
| 114 | - * @return self |
|
| 115 | - */ |
|
| 116 | - public static function fromASN1(Sequence $seq) |
|
| 117 | - { |
|
| 118 | - $version = $seq->at(0) |
|
| 119 | - ->asInteger() |
|
| 120 | - ->number(); |
|
| 121 | - if ($version != self::VERSION_2) { |
|
| 122 | - throw new \UnexpectedValueException("Version must be 2."); |
|
| 123 | - } |
|
| 124 | - $holder = Holder::fromASN1($seq->at(1)->asSequence()); |
|
| 125 | - $issuer = AttCertIssuer::fromASN1($seq->at(2)); |
|
| 126 | - $signature = AlgorithmIdentifier::fromASN1($seq->at(3)->asSequence()); |
|
| 127 | - if (!$signature instanceof SignatureAlgorithmIdentifier) { |
|
| 128 | - throw new \UnexpectedValueException( |
|
| 129 | - "Unsupported signature algorithm " . $signature->oid() . "."); |
|
| 130 | - } |
|
| 131 | - $serial = $seq->at(4) |
|
| 132 | - ->asInteger() |
|
| 133 | - ->number(); |
|
| 134 | - $validity = AttCertValidityPeriod::fromASN1($seq->at(5)->asSequence()); |
|
| 135 | - $attribs = Attributes::fromASN1($seq->at(6)->asSequence()); |
|
| 136 | - $obj = new self($holder, $issuer, $validity, $attribs); |
|
| 137 | - $obj->_signature = $signature; |
|
| 138 | - $obj->_serialNumber = $serial; |
|
| 139 | - $idx = 7; |
|
| 140 | - if ($seq->has($idx, Element::TYPE_BIT_STRING)) { |
|
| 141 | - $obj->_issuerUniqueID = UniqueIdentifier::fromASN1( |
|
| 142 | - $seq->at($idx++)->asBitString()); |
|
| 143 | - } |
|
| 144 | - if ($seq->has($idx, Element::TYPE_SEQUENCE)) { |
|
| 145 | - $obj->_extensions = Extensions::fromASN1( |
|
| 146 | - $seq->at($idx++)->asSequence()); |
|
| 147 | - } |
|
| 148 | - return $obj; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * Get self with holder. |
|
| 153 | - * |
|
| 154 | - * @param Holder $holder |
|
| 155 | - * @return self |
|
| 156 | - */ |
|
| 157 | - public function withHolder(Holder $holder) |
|
| 158 | - { |
|
| 159 | - $obj = clone $this; |
|
| 160 | - $obj->_holder = $holder; |
|
| 161 | - return $obj; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * Get self with issuer. |
|
| 166 | - * |
|
| 167 | - * @param AttCertIssuer $issuer |
|
| 168 | - * @return self |
|
| 169 | - */ |
|
| 170 | - public function withIssuer(AttCertIssuer $issuer) |
|
| 171 | - { |
|
| 172 | - $obj = clone $this; |
|
| 173 | - $obj->_issuer = $issuer; |
|
| 174 | - return $obj; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * Get self with signature algorithm identifier. |
|
| 179 | - * |
|
| 180 | - * @param SignatureAlgorithmIdentifier $algo |
|
| 181 | - * @return self |
|
| 182 | - */ |
|
| 183 | - public function withSignature(SignatureAlgorithmIdentifier $algo) |
|
| 184 | - { |
|
| 185 | - $obj = clone $this; |
|
| 186 | - $obj->_signature = $algo; |
|
| 187 | - return $obj; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * Get self with serial number. |
|
| 192 | - * |
|
| 193 | - * @param int|string $serial |
|
| 194 | - * @return self |
|
| 195 | - */ |
|
| 196 | - public function withSerialNumber($serial) |
|
| 197 | - { |
|
| 198 | - $obj = clone $this; |
|
| 199 | - $obj->_serialNumber = $serial; |
|
| 200 | - return $obj; |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * Get self with random positive serial number. |
|
| 205 | - * |
|
| 206 | - * @param int $size Number of random bytes |
|
| 207 | - * @return self |
|
| 208 | - */ |
|
| 209 | - public function withRandomSerialNumber(int $size = 16) |
|
| 210 | - { |
|
| 211 | - // ensure that first byte is always non-zero and having first bit unset |
|
| 212 | - $num = gmp_init(mt_rand(1, 0x7f), 10); |
|
| 213 | - for ($i = 1; $i < $size; ++$i) { |
|
| 214 | - $num <<= 8; |
|
| 215 | - $num += mt_rand(0, 0xff); |
|
| 216 | - } |
|
| 217 | - return $this->withSerialNumber(gmp_strval($num, 10)); |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - /** |
|
| 221 | - * Get self with validity period. |
|
| 222 | - * |
|
| 223 | - * @param AttCertValidityPeriod $validity |
|
| 224 | - * @return self |
|
| 225 | - */ |
|
| 226 | - public function withValidity(AttCertValidityPeriod $validity) |
|
| 227 | - { |
|
| 228 | - $obj = clone $this; |
|
| 229 | - $obj->_attrCertValidityPeriod = $validity; |
|
| 230 | - return $obj; |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * Get self with attributes. |
|
| 235 | - * |
|
| 236 | - * @param Attributes $attribs |
|
| 237 | - * @return self |
|
| 238 | - */ |
|
| 239 | - public function withAttributes(Attributes $attribs) |
|
| 240 | - { |
|
| 241 | - $obj = clone $this; |
|
| 242 | - $obj->_attributes = $attribs; |
|
| 243 | - return $obj; |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - /** |
|
| 247 | - * Get self with issuer unique identifier. |
|
| 248 | - * |
|
| 249 | - * @param UniqueIdentifier $uid |
|
| 250 | - * @return self |
|
| 251 | - */ |
|
| 252 | - public function withIssuerUniqueID(UniqueIdentifier $uid) |
|
| 253 | - { |
|
| 254 | - $obj = clone $this; |
|
| 255 | - $obj->_issuerUniqueID = $uid; |
|
| 256 | - return $obj; |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * Get self with extensions. |
|
| 261 | - * |
|
| 262 | - * @param Extensions $extensions |
|
| 263 | - * @return self |
|
| 264 | - */ |
|
| 265 | - public function withExtensions(Extensions $extensions) |
|
| 266 | - { |
|
| 267 | - $obj = clone $this; |
|
| 268 | - $obj->_extensions = $extensions; |
|
| 269 | - return $obj; |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - /** |
|
| 273 | - * Get self with extensions added. |
|
| 274 | - * |
|
| 275 | - * @param Extension ...$exts One or more Extension objects |
|
| 276 | - * @return self |
|
| 277 | - */ |
|
| 278 | - public function withAdditionalExtensions(Extension ...$exts) |
|
| 279 | - { |
|
| 280 | - $obj = clone $this; |
|
| 281 | - $obj->_extensions = $obj->_extensions->withExtensions(...$exts); |
|
| 282 | - return $obj; |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - /** |
|
| 286 | - * Get version. |
|
| 287 | - * |
|
| 288 | - * @return int |
|
| 289 | - */ |
|
| 290 | - public function version(): int |
|
| 291 | - { |
|
| 292 | - return $this->_version; |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - /** |
|
| 296 | - * Get AC holder. |
|
| 297 | - * |
|
| 298 | - * @return Holder |
|
| 299 | - */ |
|
| 300 | - public function holder(): Holder |
|
| 301 | - { |
|
| 302 | - return $this->_holder; |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * Get AC issuer. |
|
| 307 | - * |
|
| 308 | - * @return AttCertIssuer |
|
| 309 | - */ |
|
| 310 | - public function issuer(): AttCertIssuer |
|
| 311 | - { |
|
| 312 | - return $this->_issuer; |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - /** |
|
| 316 | - * Check whether signature is set. |
|
| 317 | - * |
|
| 318 | - * @return bool |
|
| 319 | - */ |
|
| 320 | - public function hasSignature(): bool |
|
| 321 | - { |
|
| 322 | - return isset($this->_signature); |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - /** |
|
| 326 | - * Get signature algorithm identifier. |
|
| 327 | - * |
|
| 328 | - * @return SignatureAlgorithmIdentifier |
|
| 329 | - */ |
|
| 330 | - public function signature(): SignatureAlgorithmIdentifier |
|
| 331 | - { |
|
| 332 | - if (!$this->hasSignature()) { |
|
| 333 | - throw new \LogicException("signature not set."); |
|
| 334 | - } |
|
| 335 | - return $this->_signature; |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - /** |
|
| 339 | - * Check whether serial number is present. |
|
| 340 | - * |
|
| 341 | - * @return bool |
|
| 342 | - */ |
|
| 343 | - public function hasSerialNumber(): bool |
|
| 344 | - { |
|
| 345 | - return isset($this->_serialNumber); |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - /** |
|
| 349 | - * Get AC serial number. |
|
| 350 | - * |
|
| 351 | - * @return int|string |
|
| 352 | - */ |
|
| 353 | - public function serialNumber() |
|
| 354 | - { |
|
| 355 | - if (!$this->hasSerialNumber()) { |
|
| 356 | - throw new \LogicException("serialNumber not set."); |
|
| 357 | - } |
|
| 358 | - return $this->_serialNumber; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - /** |
|
| 362 | - * Get validity period. |
|
| 363 | - * |
|
| 364 | - * @return AttCertValidityPeriod |
|
| 365 | - */ |
|
| 366 | - public function validityPeriod(): AttCertValidityPeriod |
|
| 367 | - { |
|
| 368 | - return $this->_attrCertValidityPeriod; |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - /** |
|
| 372 | - * Get attributes. |
|
| 373 | - * |
|
| 374 | - * @return Attributes |
|
| 375 | - */ |
|
| 376 | - public function attributes(): Attributes |
|
| 377 | - { |
|
| 378 | - return $this->_attributes; |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - /** |
|
| 382 | - * Check whether issuer unique identifier is present. |
|
| 383 | - * |
|
| 384 | - * @return bool |
|
| 385 | - */ |
|
| 386 | - public function hasIssuerUniqueID(): bool |
|
| 387 | - { |
|
| 388 | - return isset($this->_issuerUniqueID); |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - /** |
|
| 392 | - * Get issuer unique identifier. |
|
| 393 | - * |
|
| 394 | - * @return UniqueIdentifier |
|
| 395 | - */ |
|
| 396 | - public function issuerUniqueID(): UniqueIdentifier |
|
| 397 | - { |
|
| 398 | - if (!$this->hasIssuerUniqueID()) { |
|
| 399 | - throw new \LogicException("issuerUniqueID not set."); |
|
| 400 | - } |
|
| 401 | - return $this->_issuerUniqueID; |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - /** |
|
| 405 | - * Get extensions. |
|
| 406 | - * |
|
| 407 | - * @return Extensions |
|
| 408 | - */ |
|
| 409 | - public function extensions(): Extensions |
|
| 410 | - { |
|
| 411 | - return $this->_extensions; |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - /** |
|
| 415 | - * Get ASN.1 structure. |
|
| 416 | - * |
|
| 417 | - * @return Sequence |
|
| 418 | - */ |
|
| 419 | - public function toASN1(): Sequence |
|
| 420 | - { |
|
| 421 | - $elements = array(new Integer($this->_version), $this->_holder->toASN1(), |
|
| 422 | - $this->_issuer->toASN1(), $this->signature()->toASN1(), |
|
| 423 | - new Integer($this->serialNumber()), |
|
| 424 | - $this->_attrCertValidityPeriod->toASN1(), |
|
| 425 | - $this->_attributes->toASN1()); |
|
| 426 | - if (isset($this->_issuerUniqueID)) { |
|
| 427 | - $elements[] = $this->_issuerUniqueID->toASN1(); |
|
| 428 | - } |
|
| 429 | - if (count($this->_extensions)) { |
|
| 430 | - $elements[] = $this->_extensions->toASN1(); |
|
| 431 | - } |
|
| 432 | - return new Sequence(...$elements); |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - /** |
|
| 436 | - * Create signed attribute certificate. |
|
| 437 | - * |
|
| 438 | - * @param SignatureAlgorithmIdentifier $algo Signature algorithm |
|
| 439 | - * @param PrivateKeyInfo $privkey_info Private key |
|
| 440 | - * @param Crypto|null $crypto Crypto engine, use default if not set |
|
| 441 | - * @return AttributeCertificate |
|
| 442 | - */ |
|
| 443 | - public function sign(SignatureAlgorithmIdentifier $algo, |
|
| 444 | - PrivateKeyInfo $privkey_info, Crypto $crypto = null): AttributeCertificate |
|
| 445 | - { |
|
| 446 | - $crypto = $crypto ?: Crypto::getDefault(); |
|
| 447 | - $aci = clone $this; |
|
| 448 | - if (!isset($aci->_serialNumber)) { |
|
| 449 | - $aci->_serialNumber = 0; |
|
| 450 | - } |
|
| 451 | - $aci->_signature = $algo; |
|
| 452 | - $data = $aci->toASN1()->toDER(); |
|
| 453 | - $signature = $crypto->sign($data, $privkey_info, $algo); |
|
| 454 | - return new AttributeCertificate($aci, $algo, $signature); |
|
| 455 | - } |
|
| 25 | + const VERSION_2 = 1; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * AC version. |
|
| 29 | + * |
|
| 30 | + * @var int $_version |
|
| 31 | + */ |
|
| 32 | + protected $_version; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * AC holder. |
|
| 36 | + * |
|
| 37 | + * @var Holder $_holder |
|
| 38 | + */ |
|
| 39 | + protected $_holder; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * AC issuer. |
|
| 43 | + * |
|
| 44 | + * @var AttCertIssuer $_issuer |
|
| 45 | + */ |
|
| 46 | + protected $_issuer; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * Signature algorithm identifier. |
|
| 50 | + * |
|
| 51 | + * @var SignatureAlgorithmIdentifier $_signature |
|
| 52 | + */ |
|
| 53 | + protected $_signature; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * AC serial number. |
|
| 57 | + * |
|
| 58 | + * @var int|string $_serialNumber |
|
| 59 | + */ |
|
| 60 | + protected $_serialNumber; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Validity period. |
|
| 64 | + * |
|
| 65 | + * @var AttCertValidityPeriod $_attrCertValidityPeriod |
|
| 66 | + */ |
|
| 67 | + protected $_attrCertValidityPeriod; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Attributes. |
|
| 71 | + * |
|
| 72 | + * @var Attributes $_attributes |
|
| 73 | + */ |
|
| 74 | + protected $_attributes; |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Issuer unique identifier. |
|
| 78 | + * |
|
| 79 | + * @var UniqueIdentifier|null $_issuerUniqueID |
|
| 80 | + */ |
|
| 81 | + protected $_issuerUniqueID; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Extensions. |
|
| 85 | + * |
|
| 86 | + * @var Extensions $_extensions |
|
| 87 | + */ |
|
| 88 | + protected $_extensions; |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * Constructor. |
|
| 92 | + * |
|
| 93 | + * @param Holder $holder AC holder |
|
| 94 | + * @param AttCertIssuer $issuer AC issuer |
|
| 95 | + * @param AttCertValidityPeriod $validity Validity |
|
| 96 | + * @param Attributes $attribs Attributes |
|
| 97 | + */ |
|
| 98 | + public function __construct(Holder $holder, AttCertIssuer $issuer, |
|
| 99 | + AttCertValidityPeriod $validity, Attributes $attribs) |
|
| 100 | + { |
|
| 101 | + $this->_version = self::VERSION_2; |
|
| 102 | + $this->_holder = $holder; |
|
| 103 | + $this->_issuer = $issuer; |
|
| 104 | + $this->_attrCertValidityPeriod = $validity; |
|
| 105 | + $this->_attributes = $attribs; |
|
| 106 | + $this->_extensions = new Extensions(); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Initialize from ASN.1. |
|
| 111 | + * |
|
| 112 | + * @param Sequence $seq |
|
| 113 | + * @throws \UnexpectedValueException |
|
| 114 | + * @return self |
|
| 115 | + */ |
|
| 116 | + public static function fromASN1(Sequence $seq) |
|
| 117 | + { |
|
| 118 | + $version = $seq->at(0) |
|
| 119 | + ->asInteger() |
|
| 120 | + ->number(); |
|
| 121 | + if ($version != self::VERSION_2) { |
|
| 122 | + throw new \UnexpectedValueException("Version must be 2."); |
|
| 123 | + } |
|
| 124 | + $holder = Holder::fromASN1($seq->at(1)->asSequence()); |
|
| 125 | + $issuer = AttCertIssuer::fromASN1($seq->at(2)); |
|
| 126 | + $signature = AlgorithmIdentifier::fromASN1($seq->at(3)->asSequence()); |
|
| 127 | + if (!$signature instanceof SignatureAlgorithmIdentifier) { |
|
| 128 | + throw new \UnexpectedValueException( |
|
| 129 | + "Unsupported signature algorithm " . $signature->oid() . "."); |
|
| 130 | + } |
|
| 131 | + $serial = $seq->at(4) |
|
| 132 | + ->asInteger() |
|
| 133 | + ->number(); |
|
| 134 | + $validity = AttCertValidityPeriod::fromASN1($seq->at(5)->asSequence()); |
|
| 135 | + $attribs = Attributes::fromASN1($seq->at(6)->asSequence()); |
|
| 136 | + $obj = new self($holder, $issuer, $validity, $attribs); |
|
| 137 | + $obj->_signature = $signature; |
|
| 138 | + $obj->_serialNumber = $serial; |
|
| 139 | + $idx = 7; |
|
| 140 | + if ($seq->has($idx, Element::TYPE_BIT_STRING)) { |
|
| 141 | + $obj->_issuerUniqueID = UniqueIdentifier::fromASN1( |
|
| 142 | + $seq->at($idx++)->asBitString()); |
|
| 143 | + } |
|
| 144 | + if ($seq->has($idx, Element::TYPE_SEQUENCE)) { |
|
| 145 | + $obj->_extensions = Extensions::fromASN1( |
|
| 146 | + $seq->at($idx++)->asSequence()); |
|
| 147 | + } |
|
| 148 | + return $obj; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * Get self with holder. |
|
| 153 | + * |
|
| 154 | + * @param Holder $holder |
|
| 155 | + * @return self |
|
| 156 | + */ |
|
| 157 | + public function withHolder(Holder $holder) |
|
| 158 | + { |
|
| 159 | + $obj = clone $this; |
|
| 160 | + $obj->_holder = $holder; |
|
| 161 | + return $obj; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * Get self with issuer. |
|
| 166 | + * |
|
| 167 | + * @param AttCertIssuer $issuer |
|
| 168 | + * @return self |
|
| 169 | + */ |
|
| 170 | + public function withIssuer(AttCertIssuer $issuer) |
|
| 171 | + { |
|
| 172 | + $obj = clone $this; |
|
| 173 | + $obj->_issuer = $issuer; |
|
| 174 | + return $obj; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * Get self with signature algorithm identifier. |
|
| 179 | + * |
|
| 180 | + * @param SignatureAlgorithmIdentifier $algo |
|
| 181 | + * @return self |
|
| 182 | + */ |
|
| 183 | + public function withSignature(SignatureAlgorithmIdentifier $algo) |
|
| 184 | + { |
|
| 185 | + $obj = clone $this; |
|
| 186 | + $obj->_signature = $algo; |
|
| 187 | + return $obj; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * Get self with serial number. |
|
| 192 | + * |
|
| 193 | + * @param int|string $serial |
|
| 194 | + * @return self |
|
| 195 | + */ |
|
| 196 | + public function withSerialNumber($serial) |
|
| 197 | + { |
|
| 198 | + $obj = clone $this; |
|
| 199 | + $obj->_serialNumber = $serial; |
|
| 200 | + return $obj; |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * Get self with random positive serial number. |
|
| 205 | + * |
|
| 206 | + * @param int $size Number of random bytes |
|
| 207 | + * @return self |
|
| 208 | + */ |
|
| 209 | + public function withRandomSerialNumber(int $size = 16) |
|
| 210 | + { |
|
| 211 | + // ensure that first byte is always non-zero and having first bit unset |
|
| 212 | + $num = gmp_init(mt_rand(1, 0x7f), 10); |
|
| 213 | + for ($i = 1; $i < $size; ++$i) { |
|
| 214 | + $num <<= 8; |
|
| 215 | + $num += mt_rand(0, 0xff); |
|
| 216 | + } |
|
| 217 | + return $this->withSerialNumber(gmp_strval($num, 10)); |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * Get self with validity period. |
|
| 222 | + * |
|
| 223 | + * @param AttCertValidityPeriod $validity |
|
| 224 | + * @return self |
|
| 225 | + */ |
|
| 226 | + public function withValidity(AttCertValidityPeriod $validity) |
|
| 227 | + { |
|
| 228 | + $obj = clone $this; |
|
| 229 | + $obj->_attrCertValidityPeriod = $validity; |
|
| 230 | + return $obj; |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * Get self with attributes. |
|
| 235 | + * |
|
| 236 | + * @param Attributes $attribs |
|
| 237 | + * @return self |
|
| 238 | + */ |
|
| 239 | + public function withAttributes(Attributes $attribs) |
|
| 240 | + { |
|
| 241 | + $obj = clone $this; |
|
| 242 | + $obj->_attributes = $attribs; |
|
| 243 | + return $obj; |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + /** |
|
| 247 | + * Get self with issuer unique identifier. |
|
| 248 | + * |
|
| 249 | + * @param UniqueIdentifier $uid |
|
| 250 | + * @return self |
|
| 251 | + */ |
|
| 252 | + public function withIssuerUniqueID(UniqueIdentifier $uid) |
|
| 253 | + { |
|
| 254 | + $obj = clone $this; |
|
| 255 | + $obj->_issuerUniqueID = $uid; |
|
| 256 | + return $obj; |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * Get self with extensions. |
|
| 261 | + * |
|
| 262 | + * @param Extensions $extensions |
|
| 263 | + * @return self |
|
| 264 | + */ |
|
| 265 | + public function withExtensions(Extensions $extensions) |
|
| 266 | + { |
|
| 267 | + $obj = clone $this; |
|
| 268 | + $obj->_extensions = $extensions; |
|
| 269 | + return $obj; |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + /** |
|
| 273 | + * Get self with extensions added. |
|
| 274 | + * |
|
| 275 | + * @param Extension ...$exts One or more Extension objects |
|
| 276 | + * @return self |
|
| 277 | + */ |
|
| 278 | + public function withAdditionalExtensions(Extension ...$exts) |
|
| 279 | + { |
|
| 280 | + $obj = clone $this; |
|
| 281 | + $obj->_extensions = $obj->_extensions->withExtensions(...$exts); |
|
| 282 | + return $obj; |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + /** |
|
| 286 | + * Get version. |
|
| 287 | + * |
|
| 288 | + * @return int |
|
| 289 | + */ |
|
| 290 | + public function version(): int |
|
| 291 | + { |
|
| 292 | + return $this->_version; |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + /** |
|
| 296 | + * Get AC holder. |
|
| 297 | + * |
|
| 298 | + * @return Holder |
|
| 299 | + */ |
|
| 300 | + public function holder(): Holder |
|
| 301 | + { |
|
| 302 | + return $this->_holder; |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * Get AC issuer. |
|
| 307 | + * |
|
| 308 | + * @return AttCertIssuer |
|
| 309 | + */ |
|
| 310 | + public function issuer(): AttCertIssuer |
|
| 311 | + { |
|
| 312 | + return $this->_issuer; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * Check whether signature is set. |
|
| 317 | + * |
|
| 318 | + * @return bool |
|
| 319 | + */ |
|
| 320 | + public function hasSignature(): bool |
|
| 321 | + { |
|
| 322 | + return isset($this->_signature); |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + /** |
|
| 326 | + * Get signature algorithm identifier. |
|
| 327 | + * |
|
| 328 | + * @return SignatureAlgorithmIdentifier |
|
| 329 | + */ |
|
| 330 | + public function signature(): SignatureAlgorithmIdentifier |
|
| 331 | + { |
|
| 332 | + if (!$this->hasSignature()) { |
|
| 333 | + throw new \LogicException("signature not set."); |
|
| 334 | + } |
|
| 335 | + return $this->_signature; |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + /** |
|
| 339 | + * Check whether serial number is present. |
|
| 340 | + * |
|
| 341 | + * @return bool |
|
| 342 | + */ |
|
| 343 | + public function hasSerialNumber(): bool |
|
| 344 | + { |
|
| 345 | + return isset($this->_serialNumber); |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + /** |
|
| 349 | + * Get AC serial number. |
|
| 350 | + * |
|
| 351 | + * @return int|string |
|
| 352 | + */ |
|
| 353 | + public function serialNumber() |
|
| 354 | + { |
|
| 355 | + if (!$this->hasSerialNumber()) { |
|
| 356 | + throw new \LogicException("serialNumber not set."); |
|
| 357 | + } |
|
| 358 | + return $this->_serialNumber; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + /** |
|
| 362 | + * Get validity period. |
|
| 363 | + * |
|
| 364 | + * @return AttCertValidityPeriod |
|
| 365 | + */ |
|
| 366 | + public function validityPeriod(): AttCertValidityPeriod |
|
| 367 | + { |
|
| 368 | + return $this->_attrCertValidityPeriod; |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * Get attributes. |
|
| 373 | + * |
|
| 374 | + * @return Attributes |
|
| 375 | + */ |
|
| 376 | + public function attributes(): Attributes |
|
| 377 | + { |
|
| 378 | + return $this->_attributes; |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + /** |
|
| 382 | + * Check whether issuer unique identifier is present. |
|
| 383 | + * |
|
| 384 | + * @return bool |
|
| 385 | + */ |
|
| 386 | + public function hasIssuerUniqueID(): bool |
|
| 387 | + { |
|
| 388 | + return isset($this->_issuerUniqueID); |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + /** |
|
| 392 | + * Get issuer unique identifier. |
|
| 393 | + * |
|
| 394 | + * @return UniqueIdentifier |
|
| 395 | + */ |
|
| 396 | + public function issuerUniqueID(): UniqueIdentifier |
|
| 397 | + { |
|
| 398 | + if (!$this->hasIssuerUniqueID()) { |
|
| 399 | + throw new \LogicException("issuerUniqueID not set."); |
|
| 400 | + } |
|
| 401 | + return $this->_issuerUniqueID; |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + /** |
|
| 405 | + * Get extensions. |
|
| 406 | + * |
|
| 407 | + * @return Extensions |
|
| 408 | + */ |
|
| 409 | + public function extensions(): Extensions |
|
| 410 | + { |
|
| 411 | + return $this->_extensions; |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + /** |
|
| 415 | + * Get ASN.1 structure. |
|
| 416 | + * |
|
| 417 | + * @return Sequence |
|
| 418 | + */ |
|
| 419 | + public function toASN1(): Sequence |
|
| 420 | + { |
|
| 421 | + $elements = array(new Integer($this->_version), $this->_holder->toASN1(), |
|
| 422 | + $this->_issuer->toASN1(), $this->signature()->toASN1(), |
|
| 423 | + new Integer($this->serialNumber()), |
|
| 424 | + $this->_attrCertValidityPeriod->toASN1(), |
|
| 425 | + $this->_attributes->toASN1()); |
|
| 426 | + if (isset($this->_issuerUniqueID)) { |
|
| 427 | + $elements[] = $this->_issuerUniqueID->toASN1(); |
|
| 428 | + } |
|
| 429 | + if (count($this->_extensions)) { |
|
| 430 | + $elements[] = $this->_extensions->toASN1(); |
|
| 431 | + } |
|
| 432 | + return new Sequence(...$elements); |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + /** |
|
| 436 | + * Create signed attribute certificate. |
|
| 437 | + * |
|
| 438 | + * @param SignatureAlgorithmIdentifier $algo Signature algorithm |
|
| 439 | + * @param PrivateKeyInfo $privkey_info Private key |
|
| 440 | + * @param Crypto|null $crypto Crypto engine, use default if not set |
|
| 441 | + * @return AttributeCertificate |
|
| 442 | + */ |
|
| 443 | + public function sign(SignatureAlgorithmIdentifier $algo, |
|
| 444 | + PrivateKeyInfo $privkey_info, Crypto $crypto = null): AttributeCertificate |
|
| 445 | + { |
|
| 446 | + $crypto = $crypto ?: Crypto::getDefault(); |
|
| 447 | + $aci = clone $this; |
|
| 448 | + if (!isset($aci->_serialNumber)) { |
|
| 449 | + $aci->_serialNumber = 0; |
|
| 450 | + } |
|
| 451 | + $aci->_signature = $algo; |
|
| 452 | + $data = $aci->toASN1()->toDER(); |
|
| 453 | + $signature = $crypto->sign($data, $privkey_info, $algo); |
|
| 454 | + return new AttributeCertificate($aci, $algo, $signature); |
|
| 455 | + } |
|
| 456 | 456 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types=1); |
|
| 3 | +declare(strict_types = 1); |
|
| 4 | 4 | |
| 5 | 5 | namespace X509\AttributeCertificate; |
| 6 | 6 | |
@@ -19,172 +19,172 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class IssuerSerial |
| 21 | 21 | { |
| 22 | - /** |
|
| 23 | - * Issuer name. |
|
| 24 | - * |
|
| 25 | - * @var GeneralNames $_issuer |
|
| 26 | - */ |
|
| 27 | - protected $_issuer; |
|
| 22 | + /** |
|
| 23 | + * Issuer name. |
|
| 24 | + * |
|
| 25 | + * @var GeneralNames $_issuer |
|
| 26 | + */ |
|
| 27 | + protected $_issuer; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Serial number. |
|
| 31 | - * |
|
| 32 | - * @var string|int $_serial |
|
| 33 | - */ |
|
| 34 | - protected $_serial; |
|
| 29 | + /** |
|
| 30 | + * Serial number. |
|
| 31 | + * |
|
| 32 | + * @var string|int $_serial |
|
| 33 | + */ |
|
| 34 | + protected $_serial; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Issuer unique ID. |
|
| 38 | - * |
|
| 39 | - * @var UniqueIdentifier|null $_issuerUID |
|
| 40 | - */ |
|
| 41 | - protected $_issuerUID; |
|
| 36 | + /** |
|
| 37 | + * Issuer unique ID. |
|
| 38 | + * |
|
| 39 | + * @var UniqueIdentifier|null $_issuerUID |
|
| 40 | + */ |
|
| 41 | + protected $_issuerUID; |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Constructor. |
|
| 45 | - * |
|
| 46 | - * @param GeneralNames $issuer |
|
| 47 | - * @param string|int $serial |
|
| 48 | - * @param UniqueIdentifier|null $uid |
|
| 49 | - */ |
|
| 50 | - public function __construct(GeneralNames $issuer, $serial, |
|
| 51 | - UniqueIdentifier $uid = null) |
|
| 52 | - { |
|
| 53 | - $this->_issuer = $issuer; |
|
| 54 | - $this->_serial = $serial; |
|
| 55 | - $this->_issuerUID = $uid; |
|
| 56 | - } |
|
| 43 | + /** |
|
| 44 | + * Constructor. |
|
| 45 | + * |
|
| 46 | + * @param GeneralNames $issuer |
|
| 47 | + * @param string|int $serial |
|
| 48 | + * @param UniqueIdentifier|null $uid |
|
| 49 | + */ |
|
| 50 | + public function __construct(GeneralNames $issuer, $serial, |
|
| 51 | + UniqueIdentifier $uid = null) |
|
| 52 | + { |
|
| 53 | + $this->_issuer = $issuer; |
|
| 54 | + $this->_serial = $serial; |
|
| 55 | + $this->_issuerUID = $uid; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * Initialize from ASN.1. |
|
| 60 | - * |
|
| 61 | - * @param Sequence $seq |
|
| 62 | - * @return self |
|
| 63 | - */ |
|
| 64 | - public static function fromASN1(Sequence $seq) |
|
| 65 | - { |
|
| 66 | - $issuer = GeneralNames::fromASN1($seq->at(0)->asSequence()); |
|
| 67 | - $serial = $seq->at(1) |
|
| 68 | - ->asInteger() |
|
| 69 | - ->number(); |
|
| 70 | - $uid = null; |
|
| 71 | - if ($seq->has(2, Element::TYPE_BIT_STRING)) { |
|
| 72 | - $uid = UniqueIdentifier::fromASN1($seq->at(2)->asBitString()); |
|
| 73 | - } |
|
| 74 | - return new self($issuer, $serial, $uid); |
|
| 75 | - } |
|
| 58 | + /** |
|
| 59 | + * Initialize from ASN.1. |
|
| 60 | + * |
|
| 61 | + * @param Sequence $seq |
|
| 62 | + * @return self |
|
| 63 | + */ |
|
| 64 | + public static function fromASN1(Sequence $seq) |
|
| 65 | + { |
|
| 66 | + $issuer = GeneralNames::fromASN1($seq->at(0)->asSequence()); |
|
| 67 | + $serial = $seq->at(1) |
|
| 68 | + ->asInteger() |
|
| 69 | + ->number(); |
|
| 70 | + $uid = null; |
|
| 71 | + if ($seq->has(2, Element::TYPE_BIT_STRING)) { |
|
| 72 | + $uid = UniqueIdentifier::fromASN1($seq->at(2)->asBitString()); |
|
| 73 | + } |
|
| 74 | + return new self($issuer, $serial, $uid); |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * Initialize from a public key certificate. |
|
| 79 | - * |
|
| 80 | - * @param Certificate $cert |
|
| 81 | - * @return self |
|
| 82 | - */ |
|
| 83 | - public static function fromPKC(Certificate $cert) |
|
| 84 | - { |
|
| 85 | - $tbsCert = $cert->tbsCertificate(); |
|
| 86 | - $issuer = new GeneralNames(new DirectoryName($tbsCert->issuer())); |
|
| 87 | - $serial = $tbsCert->serialNumber(); |
|
| 88 | - $uid = $tbsCert->hasIssuerUniqueID() ? $tbsCert->issuerUniqueID() : null; |
|
| 89 | - return new self($issuer, $serial, $uid); |
|
| 90 | - } |
|
| 77 | + /** |
|
| 78 | + * Initialize from a public key certificate. |
|
| 79 | + * |
|
| 80 | + * @param Certificate $cert |
|
| 81 | + * @return self |
|
| 82 | + */ |
|
| 83 | + public static function fromPKC(Certificate $cert) |
|
| 84 | + { |
|
| 85 | + $tbsCert = $cert->tbsCertificate(); |
|
| 86 | + $issuer = new GeneralNames(new DirectoryName($tbsCert->issuer())); |
|
| 87 | + $serial = $tbsCert->serialNumber(); |
|
| 88 | + $uid = $tbsCert->hasIssuerUniqueID() ? $tbsCert->issuerUniqueID() : null; |
|
| 89 | + return new self($issuer, $serial, $uid); |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * Get issuer name. |
|
| 94 | - * |
|
| 95 | - * @return GeneralNames |
|
| 96 | - */ |
|
| 97 | - public function issuer(): GeneralNames |
|
| 98 | - { |
|
| 99 | - return $this->_issuer; |
|
| 100 | - } |
|
| 92 | + /** |
|
| 93 | + * Get issuer name. |
|
| 94 | + * |
|
| 95 | + * @return GeneralNames |
|
| 96 | + */ |
|
| 97 | + public function issuer(): GeneralNames |
|
| 98 | + { |
|
| 99 | + return $this->_issuer; |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - /** |
|
| 103 | - * Get serial number. |
|
| 104 | - * |
|
| 105 | - * @return int|string |
|
| 106 | - */ |
|
| 107 | - public function serial() |
|
| 108 | - { |
|
| 109 | - return $this->_serial; |
|
| 110 | - } |
|
| 102 | + /** |
|
| 103 | + * Get serial number. |
|
| 104 | + * |
|
| 105 | + * @return int|string |
|
| 106 | + */ |
|
| 107 | + public function serial() |
|
| 108 | + { |
|
| 109 | + return $this->_serial; |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - /** |
|
| 113 | - * Check whether issuer unique identifier is present. |
|
| 114 | - * |
|
| 115 | - * @return bool |
|
| 116 | - */ |
|
| 117 | - public function hasIssuerUID(): bool |
|
| 118 | - { |
|
| 119 | - return isset($this->_issuerUID); |
|
| 120 | - } |
|
| 112 | + /** |
|
| 113 | + * Check whether issuer unique identifier is present. |
|
| 114 | + * |
|
| 115 | + * @return bool |
|
| 116 | + */ |
|
| 117 | + public function hasIssuerUID(): bool |
|
| 118 | + { |
|
| 119 | + return isset($this->_issuerUID); |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * Get issuer unique identifier. |
|
| 124 | - * |
|
| 125 | - * @throws \LogicException |
|
| 126 | - * @return UniqueIdentifier |
|
| 127 | - */ |
|
| 128 | - public function issuerUID(): UniqueIdentifier |
|
| 129 | - { |
|
| 130 | - if (!$this->hasIssuerUID()) { |
|
| 131 | - throw new \LogicException("issuerUID not set."); |
|
| 132 | - } |
|
| 133 | - return $this->_issuerUID; |
|
| 134 | - } |
|
| 122 | + /** |
|
| 123 | + * Get issuer unique identifier. |
|
| 124 | + * |
|
| 125 | + * @throws \LogicException |
|
| 126 | + * @return UniqueIdentifier |
|
| 127 | + */ |
|
| 128 | + public function issuerUID(): UniqueIdentifier |
|
| 129 | + { |
|
| 130 | + if (!$this->hasIssuerUID()) { |
|
| 131 | + throw new \LogicException("issuerUID not set."); |
|
| 132 | + } |
|
| 133 | + return $this->_issuerUID; |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - /** |
|
| 137 | - * Generate ASN.1 structure. |
|
| 138 | - * |
|
| 139 | - * @return Sequence |
|
| 140 | - */ |
|
| 141 | - public function toASN1(): Sequence |
|
| 142 | - { |
|
| 143 | - $elements = array($this->_issuer->toASN1(), new Integer($this->_serial)); |
|
| 144 | - if (isset($this->_issuerUID)) { |
|
| 145 | - $elements[] = $this->_issuerUID->toASN1(); |
|
| 146 | - } |
|
| 147 | - return new Sequence(...$elements); |
|
| 148 | - } |
|
| 136 | + /** |
|
| 137 | + * Generate ASN.1 structure. |
|
| 138 | + * |
|
| 139 | + * @return Sequence |
|
| 140 | + */ |
|
| 141 | + public function toASN1(): Sequence |
|
| 142 | + { |
|
| 143 | + $elements = array($this->_issuer->toASN1(), new Integer($this->_serial)); |
|
| 144 | + if (isset($this->_issuerUID)) { |
|
| 145 | + $elements[] = $this->_issuerUID->toASN1(); |
|
| 146 | + } |
|
| 147 | + return new Sequence(...$elements); |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - /** |
|
| 151 | - * Check whether this IssuerSerial identifies given certificate. |
|
| 152 | - * |
|
| 153 | - * @param Certificate $cert |
|
| 154 | - * @return boolean |
|
| 155 | - */ |
|
| 156 | - public function identifiesPKC(Certificate $cert): bool |
|
| 157 | - { |
|
| 158 | - $tbs = $cert->tbsCertificate(); |
|
| 159 | - if (!$tbs->issuer()->equals($this->_issuer->firstDN())) { |
|
| 160 | - return false; |
|
| 161 | - } |
|
| 162 | - if (strval($tbs->serialNumber()) != strval($this->_serial)) { |
|
| 163 | - return false; |
|
| 164 | - } |
|
| 165 | - if ($this->_issuerUID && !$this->_checkUniqueID($cert)) { |
|
| 166 | - return false; |
|
| 167 | - } |
|
| 168 | - return true; |
|
| 169 | - } |
|
| 150 | + /** |
|
| 151 | + * Check whether this IssuerSerial identifies given certificate. |
|
| 152 | + * |
|
| 153 | + * @param Certificate $cert |
|
| 154 | + * @return boolean |
|
| 155 | + */ |
|
| 156 | + public function identifiesPKC(Certificate $cert): bool |
|
| 157 | + { |
|
| 158 | + $tbs = $cert->tbsCertificate(); |
|
| 159 | + if (!$tbs->issuer()->equals($this->_issuer->firstDN())) { |
|
| 160 | + return false; |
|
| 161 | + } |
|
| 162 | + if (strval($tbs->serialNumber()) != strval($this->_serial)) { |
|
| 163 | + return false; |
|
| 164 | + } |
|
| 165 | + if ($this->_issuerUID && !$this->_checkUniqueID($cert)) { |
|
| 166 | + return false; |
|
| 167 | + } |
|
| 168 | + return true; |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | - /** |
|
| 172 | - * Check whether issuerUID matches given certificate. |
|
| 173 | - * |
|
| 174 | - * @param Certificate $cert |
|
| 175 | - * @return boolean |
|
| 176 | - */ |
|
| 177 | - private function _checkUniqueID(Certificate $cert): bool |
|
| 178 | - { |
|
| 179 | - if (!$cert->tbsCertificate()->hasIssuerUniqueID()) { |
|
| 180 | - return false; |
|
| 181 | - } |
|
| 182 | - $uid = $cert->tbsCertificate() |
|
| 183 | - ->issuerUniqueID() |
|
| 184 | - ->string(); |
|
| 185 | - if ($this->_issuerUID->string() != $uid) { |
|
| 186 | - return false; |
|
| 187 | - } |
|
| 188 | - return true; |
|
| 189 | - } |
|
| 171 | + /** |
|
| 172 | + * Check whether issuerUID matches given certificate. |
|
| 173 | + * |
|
| 174 | + * @param Certificate $cert |
|
| 175 | + * @return boolean |
|
| 176 | + */ |
|
| 177 | + private function _checkUniqueID(Certificate $cert): bool |
|
| 178 | + { |
|
| 179 | + if (!$cert->tbsCertificate()->hasIssuerUniqueID()) { |
|
| 180 | + return false; |
|
| 181 | + } |
|
| 182 | + $uid = $cert->tbsCertificate() |
|
| 183 | + ->issuerUniqueID() |
|
| 184 | + ->string(); |
|
| 185 | + if ($this->_issuerUID->string() != $uid) { |
|
| 186 | + return false; |
|
| 187 | + } |
|
| 188 | + return true; |
|
| 189 | + } |
|
| 190 | 190 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types=1); |
|
| 3 | +declare(strict_types = 1); |
|
| 4 | 4 | |
| 5 | 5 | namespace X509\AttributeCertificate; |
| 6 | 6 | |
@@ -15,94 +15,94 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class AttCertValidityPeriod |
| 17 | 17 | { |
| 18 | - use DateTimeHelper; |
|
| 18 | + use DateTimeHelper; |
|
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Not before time. |
|
| 22 | - * |
|
| 23 | - * @var \DateTimeImmutable |
|
| 24 | - */ |
|
| 25 | - protected $_notBeforeTime; |
|
| 20 | + /** |
|
| 21 | + * Not before time. |
|
| 22 | + * |
|
| 23 | + * @var \DateTimeImmutable |
|
| 24 | + */ |
|
| 25 | + protected $_notBeforeTime; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Not after time. |
|
| 29 | - * |
|
| 30 | - * @var \DateTimeImmutable |
|
| 31 | - */ |
|
| 32 | - protected $_notAfterTime; |
|
| 27 | + /** |
|
| 28 | + * Not after time. |
|
| 29 | + * |
|
| 30 | + * @var \DateTimeImmutable |
|
| 31 | + */ |
|
| 32 | + protected $_notAfterTime; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Constructor. |
|
| 36 | - * |
|
| 37 | - * @param \DateTimeImmutable $nb |
|
| 38 | - * @param \DateTimeImmutable $na |
|
| 39 | - */ |
|
| 40 | - public function __construct(\DateTimeImmutable $nb, \DateTimeImmutable $na) |
|
| 41 | - { |
|
| 42 | - $this->_notBeforeTime = $nb; |
|
| 43 | - $this->_notAfterTime = $na; |
|
| 44 | - } |
|
| 34 | + /** |
|
| 35 | + * Constructor. |
|
| 36 | + * |
|
| 37 | + * @param \DateTimeImmutable $nb |
|
| 38 | + * @param \DateTimeImmutable $na |
|
| 39 | + */ |
|
| 40 | + public function __construct(\DateTimeImmutable $nb, \DateTimeImmutable $na) |
|
| 41 | + { |
|
| 42 | + $this->_notBeforeTime = $nb; |
|
| 43 | + $this->_notAfterTime = $na; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Initialize from ASN.1. |
|
| 48 | - * |
|
| 49 | - * @param Sequence $seq |
|
| 50 | - * @return self |
|
| 51 | - */ |
|
| 52 | - public static function fromASN1(Sequence $seq) |
|
| 53 | - { |
|
| 54 | - $nb = $seq->at(0) |
|
| 55 | - ->asGeneralizedTime() |
|
| 56 | - ->dateTime(); |
|
| 57 | - $na = $seq->at(1) |
|
| 58 | - ->asGeneralizedTime() |
|
| 59 | - ->dateTime(); |
|
| 60 | - return new self($nb, $na); |
|
| 61 | - } |
|
| 46 | + /** |
|
| 47 | + * Initialize from ASN.1. |
|
| 48 | + * |
|
| 49 | + * @param Sequence $seq |
|
| 50 | + * @return self |
|
| 51 | + */ |
|
| 52 | + public static function fromASN1(Sequence $seq) |
|
| 53 | + { |
|
| 54 | + $nb = $seq->at(0) |
|
| 55 | + ->asGeneralizedTime() |
|
| 56 | + ->dateTime(); |
|
| 57 | + $na = $seq->at(1) |
|
| 58 | + ->asGeneralizedTime() |
|
| 59 | + ->dateTime(); |
|
| 60 | + return new self($nb, $na); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * Initialize from date strings. |
|
| 65 | - * |
|
| 66 | - * @param string|null $nb_date Not before date |
|
| 67 | - * @param string|null $na_date Not after date |
|
| 68 | - * @param string|null $tz Timezone string |
|
| 69 | - * @return self |
|
| 70 | - */ |
|
| 71 | - public static function fromStrings($nb_date, $na_date, $tz = null) |
|
| 72 | - { |
|
| 73 | - $nb = self::_createDateTime($nb_date, $tz); |
|
| 74 | - $na = self::_createDateTime($na_date, $tz); |
|
| 75 | - return new self($nb, $na); |
|
| 76 | - } |
|
| 63 | + /** |
|
| 64 | + * Initialize from date strings. |
|
| 65 | + * |
|
| 66 | + * @param string|null $nb_date Not before date |
|
| 67 | + * @param string|null $na_date Not after date |
|
| 68 | + * @param string|null $tz Timezone string |
|
| 69 | + * @return self |
|
| 70 | + */ |
|
| 71 | + public static function fromStrings($nb_date, $na_date, $tz = null) |
|
| 72 | + { |
|
| 73 | + $nb = self::_createDateTime($nb_date, $tz); |
|
| 74 | + $na = self::_createDateTime($na_date, $tz); |
|
| 75 | + return new self($nb, $na); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Get not before time. |
|
| 80 | - * |
|
| 81 | - * @return \DateTimeImmutable |
|
| 82 | - */ |
|
| 83 | - public function notBeforeTime(): \DateTimeImmutable |
|
| 84 | - { |
|
| 85 | - return $this->_notBeforeTime; |
|
| 86 | - } |
|
| 78 | + /** |
|
| 79 | + * Get not before time. |
|
| 80 | + * |
|
| 81 | + * @return \DateTimeImmutable |
|
| 82 | + */ |
|
| 83 | + public function notBeforeTime(): \DateTimeImmutable |
|
| 84 | + { |
|
| 85 | + return $this->_notBeforeTime; |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * Get not after time. |
|
| 90 | - * |
|
| 91 | - * @return \DateTimeImmutable |
|
| 92 | - */ |
|
| 93 | - public function notAfterTime(): \DateTimeImmutable |
|
| 94 | - { |
|
| 95 | - return $this->_notAfterTime; |
|
| 96 | - } |
|
| 88 | + /** |
|
| 89 | + * Get not after time. |
|
| 90 | + * |
|
| 91 | + * @return \DateTimeImmutable |
|
| 92 | + */ |
|
| 93 | + public function notAfterTime(): \DateTimeImmutable |
|
| 94 | + { |
|
| 95 | + return $this->_notAfterTime; |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * Generate ASN.1 structure. |
|
| 100 | - * |
|
| 101 | - * @return Sequence |
|
| 102 | - */ |
|
| 103 | - public function toASN1(): Sequence |
|
| 104 | - { |
|
| 105 | - return new Sequence(new GeneralizedTime($this->_notBeforeTime), |
|
| 106 | - new GeneralizedTime($this->_notAfterTime)); |
|
| 107 | - } |
|
| 98 | + /** |
|
| 99 | + * Generate ASN.1 structure. |
|
| 100 | + * |
|
| 101 | + * @return Sequence |
|
| 102 | + */ |
|
| 103 | + public function toASN1(): Sequence |
|
| 104 | + { |
|
| 105 | + return new Sequence(new GeneralizedTime($this->_notBeforeTime), |
|
| 106 | + new GeneralizedTime($this->_notAfterTime)); |
|
| 107 | + } |
|
| 108 | 108 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types=1); |
|
| 3 | +declare(strict_types = 1); |
|
| 4 | 4 | |
| 5 | 5 | namespace X509\AttributeCertificate; |
| 6 | 6 | |