@@ -13,17 +13,17 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class AccessIdentityAttributeValue extends SvceAuthInfo |
| 15 | 15 | { |
| 16 | - const OID = '1.3.6.1.5.5.7.10.2'; |
|
| 16 | + const OID = '1.3.6.1.5.5.7.10.2'; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Constructor. |
|
| 20 | - * |
|
| 21 | - * @param GeneralName $service |
|
| 22 | - * @param GeneralName $ident |
|
| 23 | - */ |
|
| 24 | - public function __construct(GeneralName $service, GeneralName $ident) |
|
| 25 | - { |
|
| 26 | - parent::__construct($service, $ident, null); |
|
| 27 | - $this->_oid = self::OID; |
|
| 28 | - } |
|
| 18 | + /** |
|
| 19 | + * Constructor. |
|
| 20 | + * |
|
| 21 | + * @param GeneralName $service |
|
| 22 | + * @param GeneralName $ident |
|
| 23 | + */ |
|
| 24 | + public function __construct(GeneralName $service, GeneralName $ident) |
|
| 25 | + { |
|
| 26 | + parent::__construct($service, $ident, null); |
|
| 27 | + $this->_oid = self::OID; |
|
| 28 | + } |
|
| 29 | 29 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types = 1); |
|
| 3 | +declare(strict_types=1); |
|
| 4 | 4 | |
| 5 | 5 | namespace Sop\X509\AttributeCertificate\Attribute; |
| 6 | 6 | |
@@ -21,145 +21,145 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | abstract class SvceAuthInfo extends AttributeValue |
| 23 | 23 | { |
| 24 | - /** |
|
| 25 | - * Service. |
|
| 26 | - * |
|
| 27 | - * @var GeneralName |
|
| 28 | - */ |
|
| 29 | - protected $_service; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Ident. |
|
| 33 | - * |
|
| 34 | - * @var GeneralName |
|
| 35 | - */ |
|
| 36 | - protected $_ident; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Auth info. |
|
| 40 | - * |
|
| 41 | - * @var null|string |
|
| 42 | - */ |
|
| 43 | - protected $_authInfo; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * Constructor. |
|
| 47 | - * |
|
| 48 | - * @param GeneralName $service |
|
| 49 | - * @param GeneralName $ident |
|
| 50 | - * @param null|string $auth_info |
|
| 51 | - */ |
|
| 52 | - public function __construct(GeneralName $service, GeneralName $ident, |
|
| 53 | - ?string $auth_info = null) |
|
| 54 | - { |
|
| 55 | - $this->_service = $service; |
|
| 56 | - $this->_ident = $ident; |
|
| 57 | - $this->_authInfo = $auth_info; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * {@inheritdoc} |
|
| 62 | - * |
|
| 63 | - * @return self |
|
| 64 | - */ |
|
| 65 | - public static function fromASN1(UnspecifiedType $el): AttributeValue |
|
| 66 | - { |
|
| 67 | - $seq = $el->asSequence(); |
|
| 68 | - $service = GeneralName::fromASN1($seq->at(0)->asTagged()); |
|
| 69 | - $ident = GeneralName::fromASN1($seq->at(1)->asTagged()); |
|
| 70 | - $auth_info = null; |
|
| 71 | - if ($seq->has(2, Element::TYPE_OCTET_STRING)) { |
|
| 72 | - $auth_info = $seq->at(2)->asString()->string(); |
|
| 73 | - } |
|
| 74 | - return new static($service, $ident, $auth_info); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Get service name. |
|
| 79 | - * |
|
| 80 | - * @return GeneralName |
|
| 81 | - */ |
|
| 82 | - public function service(): GeneralName |
|
| 83 | - { |
|
| 84 | - return $this->_service; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Get ident. |
|
| 89 | - * |
|
| 90 | - * @return GeneralName |
|
| 91 | - */ |
|
| 92 | - public function ident(): GeneralName |
|
| 93 | - { |
|
| 94 | - return $this->_ident; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * Check whether authentication info is present. |
|
| 99 | - * |
|
| 100 | - * @return bool |
|
| 101 | - */ |
|
| 102 | - public function hasAuthInfo(): bool |
|
| 103 | - { |
|
| 104 | - return isset($this->_authInfo); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Get authentication info. |
|
| 109 | - * |
|
| 110 | - * @throws \LogicException If not set |
|
| 111 | - * |
|
| 112 | - * @return string |
|
| 113 | - */ |
|
| 114 | - public function authInfo(): string |
|
| 115 | - { |
|
| 116 | - if (!$this->hasAuthInfo()) { |
|
| 117 | - throw new \LogicException('authInfo not set.'); |
|
| 118 | - } |
|
| 119 | - return $this->_authInfo; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * {@inheritdoc} |
|
| 124 | - */ |
|
| 125 | - public function toASN1(): Element |
|
| 126 | - { |
|
| 127 | - $elements = [$this->_service->toASN1(), $this->_ident->toASN1()]; |
|
| 128 | - if (isset($this->_authInfo)) { |
|
| 129 | - $elements[] = new OctetString($this->_authInfo); |
|
| 130 | - } |
|
| 131 | - return new Sequence(...$elements); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * {@inheritdoc} |
|
| 136 | - */ |
|
| 137 | - public function stringValue(): string |
|
| 138 | - { |
|
| 139 | - return '#' . bin2hex($this->toASN1()->toDER()); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * {@inheritdoc} |
|
| 144 | - */ |
|
| 145 | - public function equalityMatchingRule(): MatchingRule |
|
| 146 | - { |
|
| 147 | - return new BinaryMatch(); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * {@inheritdoc} |
|
| 152 | - */ |
|
| 153 | - public function rfc2253String(): string |
|
| 154 | - { |
|
| 155 | - return $this->stringValue(); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * {@inheritdoc} |
|
| 160 | - */ |
|
| 161 | - protected function _transcodedString(): string |
|
| 162 | - { |
|
| 163 | - return $this->stringValue(); |
|
| 164 | - } |
|
| 24 | + /** |
|
| 25 | + * Service. |
|
| 26 | + * |
|
| 27 | + * @var GeneralName |
|
| 28 | + */ |
|
| 29 | + protected $_service; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Ident. |
|
| 33 | + * |
|
| 34 | + * @var GeneralName |
|
| 35 | + */ |
|
| 36 | + protected $_ident; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Auth info. |
|
| 40 | + * |
|
| 41 | + * @var null|string |
|
| 42 | + */ |
|
| 43 | + protected $_authInfo; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * Constructor. |
|
| 47 | + * |
|
| 48 | + * @param GeneralName $service |
|
| 49 | + * @param GeneralName $ident |
|
| 50 | + * @param null|string $auth_info |
|
| 51 | + */ |
|
| 52 | + public function __construct(GeneralName $service, GeneralName $ident, |
|
| 53 | + ?string $auth_info = null) |
|
| 54 | + { |
|
| 55 | + $this->_service = $service; |
|
| 56 | + $this->_ident = $ident; |
|
| 57 | + $this->_authInfo = $auth_info; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * {@inheritdoc} |
|
| 62 | + * |
|
| 63 | + * @return self |
|
| 64 | + */ |
|
| 65 | + public static function fromASN1(UnspecifiedType $el): AttributeValue |
|
| 66 | + { |
|
| 67 | + $seq = $el->asSequence(); |
|
| 68 | + $service = GeneralName::fromASN1($seq->at(0)->asTagged()); |
|
| 69 | + $ident = GeneralName::fromASN1($seq->at(1)->asTagged()); |
|
| 70 | + $auth_info = null; |
|
| 71 | + if ($seq->has(2, Element::TYPE_OCTET_STRING)) { |
|
| 72 | + $auth_info = $seq->at(2)->asString()->string(); |
|
| 73 | + } |
|
| 74 | + return new static($service, $ident, $auth_info); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Get service name. |
|
| 79 | + * |
|
| 80 | + * @return GeneralName |
|
| 81 | + */ |
|
| 82 | + public function service(): GeneralName |
|
| 83 | + { |
|
| 84 | + return $this->_service; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Get ident. |
|
| 89 | + * |
|
| 90 | + * @return GeneralName |
|
| 91 | + */ |
|
| 92 | + public function ident(): GeneralName |
|
| 93 | + { |
|
| 94 | + return $this->_ident; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * Check whether authentication info is present. |
|
| 99 | + * |
|
| 100 | + * @return bool |
|
| 101 | + */ |
|
| 102 | + public function hasAuthInfo(): bool |
|
| 103 | + { |
|
| 104 | + return isset($this->_authInfo); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Get authentication info. |
|
| 109 | + * |
|
| 110 | + * @throws \LogicException If not set |
|
| 111 | + * |
|
| 112 | + * @return string |
|
| 113 | + */ |
|
| 114 | + public function authInfo(): string |
|
| 115 | + { |
|
| 116 | + if (!$this->hasAuthInfo()) { |
|
| 117 | + throw new \LogicException('authInfo not set.'); |
|
| 118 | + } |
|
| 119 | + return $this->_authInfo; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * {@inheritdoc} |
|
| 124 | + */ |
|
| 125 | + public function toASN1(): Element |
|
| 126 | + { |
|
| 127 | + $elements = [$this->_service->toASN1(), $this->_ident->toASN1()]; |
|
| 128 | + if (isset($this->_authInfo)) { |
|
| 129 | + $elements[] = new OctetString($this->_authInfo); |
|
| 130 | + } |
|
| 131 | + return new Sequence(...$elements); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * {@inheritdoc} |
|
| 136 | + */ |
|
| 137 | + public function stringValue(): string |
|
| 138 | + { |
|
| 139 | + return '#' . bin2hex($this->toASN1()->toDER()); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * {@inheritdoc} |
|
| 144 | + */ |
|
| 145 | + public function equalityMatchingRule(): MatchingRule |
|
| 146 | + { |
|
| 147 | + return new BinaryMatch(); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * {@inheritdoc} |
|
| 152 | + */ |
|
| 153 | + public function rfc2253String(): string |
|
| 154 | + { |
|
| 155 | + return $this->stringValue(); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * {@inheritdoc} |
|
| 160 | + */ |
|
| 161 | + protected function _transcodedString(): string |
|
| 162 | + { |
|
| 163 | + return $this->stringValue(); |
|
| 164 | + } |
|
| 165 | 165 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types = 1); |
|
| 3 | +declare(strict_types=1); |
|
| 4 | 4 | |
| 5 | 5 | namespace Sop\X509\AttributeCertificate\Attribute; |
| 6 | 6 | |
@@ -24,146 +24,146 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | class RoleAttributeValue extends AttributeValue |
| 26 | 26 | { |
| 27 | - /** |
|
| 28 | - * Issuing authority. |
|
| 29 | - * |
|
| 30 | - * @var null|GeneralNames |
|
| 31 | - */ |
|
| 32 | - protected $_roleAuthority; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Role name. |
|
| 36 | - * |
|
| 37 | - * @var GeneralName |
|
| 38 | - */ |
|
| 39 | - protected $_roleName; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * Constructor. |
|
| 43 | - * |
|
| 44 | - * @param GeneralName $name Role name |
|
| 45 | - * @param null|GeneralNames $authority Issuing authority |
|
| 46 | - */ |
|
| 47 | - public function __construct(GeneralName $name, |
|
| 48 | - ?GeneralNames $authority = null) |
|
| 49 | - { |
|
| 50 | - $this->_roleAuthority = $authority; |
|
| 51 | - $this->_roleName = $name; |
|
| 52 | - $this->_oid = AttributeType::OID_ROLE; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Initialize from a role string. |
|
| 57 | - * |
|
| 58 | - * @param string $role_name Role name in URI format |
|
| 59 | - * @param null|GeneralNames $authority Issuing authority |
|
| 60 | - * |
|
| 61 | - * @return self |
|
| 62 | - */ |
|
| 63 | - public static function fromString(string $role_name, |
|
| 64 | - ?GeneralNames $authority = null): self |
|
| 65 | - { |
|
| 66 | - return new self(new UniformResourceIdentifier($role_name), $authority); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * {@inheritdoc} |
|
| 71 | - * |
|
| 72 | - * @return self |
|
| 73 | - */ |
|
| 74 | - public static function fromASN1(UnspecifiedType $el): AttributeValue |
|
| 75 | - { |
|
| 76 | - $seq = $el->asSequence(); |
|
| 77 | - $authority = null; |
|
| 78 | - if ($seq->hasTagged(0)) { |
|
| 79 | - $authority = GeneralNames::fromASN1( |
|
| 80 | - $seq->getTagged(0)->asImplicit(Element::TYPE_SEQUENCE) |
|
| 81 | - ->asSequence()); |
|
| 82 | - } |
|
| 83 | - $name = GeneralName::fromASN1($seq->getTagged(1) |
|
| 84 | - ->asExplicit()->asTagged()); |
|
| 85 | - return new self($name, $authority); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Check whether issuing authority is present. |
|
| 90 | - * |
|
| 91 | - * @return bool |
|
| 92 | - */ |
|
| 93 | - public function hasRoleAuthority(): bool |
|
| 94 | - { |
|
| 95 | - return isset($this->_roleAuthority); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * Get issuing authority. |
|
| 100 | - * |
|
| 101 | - * @throws \LogicException If not set |
|
| 102 | - * |
|
| 103 | - * @return GeneralNames |
|
| 104 | - */ |
|
| 105 | - public function roleAuthority(): GeneralNames |
|
| 106 | - { |
|
| 107 | - if (!$this->hasRoleAuthority()) { |
|
| 108 | - throw new \LogicException('roleAuthority not set.'); |
|
| 109 | - } |
|
| 110 | - return $this->_roleAuthority; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Get role name. |
|
| 115 | - * |
|
| 116 | - * @return GeneralName |
|
| 117 | - */ |
|
| 118 | - public function roleName(): GeneralName |
|
| 119 | - { |
|
| 120 | - return $this->_roleName; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * {@inheritdoc} |
|
| 125 | - */ |
|
| 126 | - public function toASN1(): Element |
|
| 127 | - { |
|
| 128 | - $elements = []; |
|
| 129 | - if (isset($this->_roleAuthority)) { |
|
| 130 | - $elements[] = new ImplicitlyTaggedType( |
|
| 131 | - 0, $this->_roleAuthority->toASN1()); |
|
| 132 | - } |
|
| 133 | - $elements[] = new ExplicitlyTaggedType( |
|
| 134 | - 1, $this->_roleName->toASN1()); |
|
| 135 | - return new Sequence(...$elements); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * {@inheritdoc} |
|
| 140 | - */ |
|
| 141 | - public function stringValue(): string |
|
| 142 | - { |
|
| 143 | - return '#' . bin2hex($this->toASN1()->toDER()); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * {@inheritdoc} |
|
| 148 | - */ |
|
| 149 | - public function equalityMatchingRule(): MatchingRule |
|
| 150 | - { |
|
| 151 | - return new BinaryMatch(); |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * {@inheritdoc} |
|
| 156 | - */ |
|
| 157 | - public function rfc2253String(): string |
|
| 158 | - { |
|
| 159 | - return $this->stringValue(); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * {@inheritdoc} |
|
| 164 | - */ |
|
| 165 | - protected function _transcodedString(): string |
|
| 166 | - { |
|
| 167 | - return $this->stringValue(); |
|
| 168 | - } |
|
| 27 | + /** |
|
| 28 | + * Issuing authority. |
|
| 29 | + * |
|
| 30 | + * @var null|GeneralNames |
|
| 31 | + */ |
|
| 32 | + protected $_roleAuthority; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Role name. |
|
| 36 | + * |
|
| 37 | + * @var GeneralName |
|
| 38 | + */ |
|
| 39 | + protected $_roleName; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * Constructor. |
|
| 43 | + * |
|
| 44 | + * @param GeneralName $name Role name |
|
| 45 | + * @param null|GeneralNames $authority Issuing authority |
|
| 46 | + */ |
|
| 47 | + public function __construct(GeneralName $name, |
|
| 48 | + ?GeneralNames $authority = null) |
|
| 49 | + { |
|
| 50 | + $this->_roleAuthority = $authority; |
|
| 51 | + $this->_roleName = $name; |
|
| 52 | + $this->_oid = AttributeType::OID_ROLE; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Initialize from a role string. |
|
| 57 | + * |
|
| 58 | + * @param string $role_name Role name in URI format |
|
| 59 | + * @param null|GeneralNames $authority Issuing authority |
|
| 60 | + * |
|
| 61 | + * @return self |
|
| 62 | + */ |
|
| 63 | + public static function fromString(string $role_name, |
|
| 64 | + ?GeneralNames $authority = null): self |
|
| 65 | + { |
|
| 66 | + return new self(new UniformResourceIdentifier($role_name), $authority); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * {@inheritdoc} |
|
| 71 | + * |
|
| 72 | + * @return self |
|
| 73 | + */ |
|
| 74 | + public static function fromASN1(UnspecifiedType $el): AttributeValue |
|
| 75 | + { |
|
| 76 | + $seq = $el->asSequence(); |
|
| 77 | + $authority = null; |
|
| 78 | + if ($seq->hasTagged(0)) { |
|
| 79 | + $authority = GeneralNames::fromASN1( |
|
| 80 | + $seq->getTagged(0)->asImplicit(Element::TYPE_SEQUENCE) |
|
| 81 | + ->asSequence()); |
|
| 82 | + } |
|
| 83 | + $name = GeneralName::fromASN1($seq->getTagged(1) |
|
| 84 | + ->asExplicit()->asTagged()); |
|
| 85 | + return new self($name, $authority); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Check whether issuing authority is present. |
|
| 90 | + * |
|
| 91 | + * @return bool |
|
| 92 | + */ |
|
| 93 | + public function hasRoleAuthority(): bool |
|
| 94 | + { |
|
| 95 | + return isset($this->_roleAuthority); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * Get issuing authority. |
|
| 100 | + * |
|
| 101 | + * @throws \LogicException If not set |
|
| 102 | + * |
|
| 103 | + * @return GeneralNames |
|
| 104 | + */ |
|
| 105 | + public function roleAuthority(): GeneralNames |
|
| 106 | + { |
|
| 107 | + if (!$this->hasRoleAuthority()) { |
|
| 108 | + throw new \LogicException('roleAuthority not set.'); |
|
| 109 | + } |
|
| 110 | + return $this->_roleAuthority; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Get role name. |
|
| 115 | + * |
|
| 116 | + * @return GeneralName |
|
| 117 | + */ |
|
| 118 | + public function roleName(): GeneralName |
|
| 119 | + { |
|
| 120 | + return $this->_roleName; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * {@inheritdoc} |
|
| 125 | + */ |
|
| 126 | + public function toASN1(): Element |
|
| 127 | + { |
|
| 128 | + $elements = []; |
|
| 129 | + if (isset($this->_roleAuthority)) { |
|
| 130 | + $elements[] = new ImplicitlyTaggedType( |
|
| 131 | + 0, $this->_roleAuthority->toASN1()); |
|
| 132 | + } |
|
| 133 | + $elements[] = new ExplicitlyTaggedType( |
|
| 134 | + 1, $this->_roleName->toASN1()); |
|
| 135 | + return new Sequence(...$elements); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * {@inheritdoc} |
|
| 140 | + */ |
|
| 141 | + public function stringValue(): string |
|
| 142 | + { |
|
| 143 | + return '#' . bin2hex($this->toASN1()->toDER()); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * {@inheritdoc} |
|
| 148 | + */ |
|
| 149 | + public function equalityMatchingRule(): MatchingRule |
|
| 150 | + { |
|
| 151 | + return new BinaryMatch(); |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * {@inheritdoc} |
|
| 156 | + */ |
|
| 157 | + public function rfc2253String(): string |
|
| 158 | + { |
|
| 159 | + return $this->stringValue(); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * {@inheritdoc} |
|
| 164 | + */ |
|
| 165 | + protected function _transcodedString(): string |
|
| 166 | + { |
|
| 167 | + return $this->stringValue(); |
|
| 168 | + } |
|
| 169 | 169 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types = 1); |
|
| 3 | +declare(strict_types=1); |
|
| 4 | 4 | |
| 5 | 5 | namespace Sop\X509\AttributeCertificate\Attribute; |
| 6 | 6 | |
@@ -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 Sop\X509\AttributeCertificate\Attribute; |
| 6 | 6 | |
@@ -17,166 +17,166 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class IetfAttrValue |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * Element type tag. |
|
| 22 | - * |
|
| 23 | - * @var int |
|
| 24 | - */ |
|
| 25 | - protected $_type; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * Value. |
|
| 29 | - * |
|
| 30 | - * @var string |
|
| 31 | - */ |
|
| 32 | - protected $_value; |
|
| 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 | - } |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @return string |
|
| 48 | - */ |
|
| 49 | - public function __toString(): string |
|
| 50 | - { |
|
| 51 | - return $this->_value; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Initialize from ASN.1. |
|
| 56 | - * |
|
| 57 | - * @param UnspecifiedType $el |
|
| 58 | - * |
|
| 59 | - * @throws \UnexpectedValueException |
|
| 60 | - * |
|
| 61 | - * @return self |
|
| 62 | - */ |
|
| 63 | - public static function fromASN1(UnspecifiedType $el): self |
|
| 64 | - { |
|
| 65 | - switch ($el->tag()) { |
|
| 66 | - case Element::TYPE_OCTET_STRING: |
|
| 67 | - case Element::TYPE_UTF8_STRING: |
|
| 68 | - return new self($el->asString()->string(), $el->tag()); |
|
| 69 | - case Element::TYPE_OBJECT_IDENTIFIER: |
|
| 70 | - return new self($el->asObjectIdentifier()->oid(), $el->tag()); |
|
| 71 | - } |
|
| 72 | - throw new \UnexpectedValueException( |
|
| 73 | - 'Type ' . Element::tagToName($el->tag()) . ' not supported.'); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Initialize from octet string. |
|
| 78 | - * |
|
| 79 | - * @param string $octets |
|
| 80 | - * |
|
| 81 | - * @return self |
|
| 82 | - */ |
|
| 83 | - public static function fromOctets(string $octets): self |
|
| 84 | - { |
|
| 85 | - return new self($octets, Element::TYPE_OCTET_STRING); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Initialize from UTF-8 string. |
|
| 90 | - * |
|
| 91 | - * @param string $str |
|
| 92 | - * |
|
| 93 | - * @return self |
|
| 94 | - */ |
|
| 95 | - public static function fromString(string $str): self |
|
| 96 | - { |
|
| 97 | - return new self($str, Element::TYPE_UTF8_STRING); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Initialize from OID. |
|
| 102 | - * |
|
| 103 | - * @param string $oid |
|
| 104 | - * |
|
| 105 | - * @return self |
|
| 106 | - */ |
|
| 107 | - public static function fromOID(string $oid): self |
|
| 108 | - { |
|
| 109 | - return new self($oid, Element::TYPE_OBJECT_IDENTIFIER); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Get type tag. |
|
| 114 | - * |
|
| 115 | - * @return int |
|
| 116 | - */ |
|
| 117 | - public function type(): int |
|
| 118 | - { |
|
| 119 | - return $this->_type; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Whether value type is octets. |
|
| 124 | - * |
|
| 125 | - * @return bool |
|
| 126 | - */ |
|
| 127 | - public function isOctets(): bool |
|
| 128 | - { |
|
| 129 | - return Element::TYPE_OCTET_STRING === $this->_type; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * Whether value type is OID. |
|
| 134 | - * |
|
| 135 | - * @return bool |
|
| 136 | - */ |
|
| 137 | - public function isOID(): bool |
|
| 138 | - { |
|
| 139 | - return Element::TYPE_OBJECT_IDENTIFIER === $this->_type; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * Whether value type is string. |
|
| 144 | - * |
|
| 145 | - * @return bool |
|
| 146 | - */ |
|
| 147 | - public function isString(): bool |
|
| 148 | - { |
|
| 149 | - return Element::TYPE_UTF8_STRING === $this->_type; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * Get value. |
|
| 154 | - * |
|
| 155 | - * @return string |
|
| 156 | - */ |
|
| 157 | - public function value(): string |
|
| 158 | - { |
|
| 159 | - return $this->_value; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Generate ASN.1 structure. |
|
| 164 | - * |
|
| 165 | - * @throws \LogicException |
|
| 166 | - * |
|
| 167 | - * @return Element |
|
| 168 | - */ |
|
| 169 | - public function toASN1(): Element |
|
| 170 | - { |
|
| 171 | - switch ($this->_type) { |
|
| 172 | - case Element::TYPE_OCTET_STRING: |
|
| 173 | - return new OctetString($this->_value); |
|
| 174 | - case Element::TYPE_UTF8_STRING: |
|
| 175 | - return new UTF8String($this->_value); |
|
| 176 | - case Element::TYPE_OBJECT_IDENTIFIER: |
|
| 177 | - return new ObjectIdentifier($this->_value); |
|
| 178 | - } |
|
| 179 | - throw new \LogicException( |
|
| 180 | - 'Type ' . Element::tagToName($this->_type) . ' not supported.'); |
|
| 181 | - } |
|
| 20 | + /** |
|
| 21 | + * Element type tag. |
|
| 22 | + * |
|
| 23 | + * @var int |
|
| 24 | + */ |
|
| 25 | + protected $_type; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * Value. |
|
| 29 | + * |
|
| 30 | + * @var string |
|
| 31 | + */ |
|
| 32 | + protected $_value; |
|
| 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 | + } |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @return string |
|
| 48 | + */ |
|
| 49 | + public function __toString(): string |
|
| 50 | + { |
|
| 51 | + return $this->_value; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Initialize from ASN.1. |
|
| 56 | + * |
|
| 57 | + * @param UnspecifiedType $el |
|
| 58 | + * |
|
| 59 | + * @throws \UnexpectedValueException |
|
| 60 | + * |
|
| 61 | + * @return self |
|
| 62 | + */ |
|
| 63 | + public static function fromASN1(UnspecifiedType $el): self |
|
| 64 | + { |
|
| 65 | + switch ($el->tag()) { |
|
| 66 | + case Element::TYPE_OCTET_STRING: |
|
| 67 | + case Element::TYPE_UTF8_STRING: |
|
| 68 | + return new self($el->asString()->string(), $el->tag()); |
|
| 69 | + case Element::TYPE_OBJECT_IDENTIFIER: |
|
| 70 | + return new self($el->asObjectIdentifier()->oid(), $el->tag()); |
|
| 71 | + } |
|
| 72 | + throw new \UnexpectedValueException( |
|
| 73 | + 'Type ' . Element::tagToName($el->tag()) . ' not supported.'); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Initialize from octet string. |
|
| 78 | + * |
|
| 79 | + * @param string $octets |
|
| 80 | + * |
|
| 81 | + * @return self |
|
| 82 | + */ |
|
| 83 | + public static function fromOctets(string $octets): self |
|
| 84 | + { |
|
| 85 | + return new self($octets, Element::TYPE_OCTET_STRING); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Initialize from UTF-8 string. |
|
| 90 | + * |
|
| 91 | + * @param string $str |
|
| 92 | + * |
|
| 93 | + * @return self |
|
| 94 | + */ |
|
| 95 | + public static function fromString(string $str): self |
|
| 96 | + { |
|
| 97 | + return new self($str, Element::TYPE_UTF8_STRING); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Initialize from OID. |
|
| 102 | + * |
|
| 103 | + * @param string $oid |
|
| 104 | + * |
|
| 105 | + * @return self |
|
| 106 | + */ |
|
| 107 | + public static function fromOID(string $oid): self |
|
| 108 | + { |
|
| 109 | + return new self($oid, Element::TYPE_OBJECT_IDENTIFIER); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Get type tag. |
|
| 114 | + * |
|
| 115 | + * @return int |
|
| 116 | + */ |
|
| 117 | + public function type(): int |
|
| 118 | + { |
|
| 119 | + return $this->_type; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Whether value type is octets. |
|
| 124 | + * |
|
| 125 | + * @return bool |
|
| 126 | + */ |
|
| 127 | + public function isOctets(): bool |
|
| 128 | + { |
|
| 129 | + return Element::TYPE_OCTET_STRING === $this->_type; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * Whether value type is OID. |
|
| 134 | + * |
|
| 135 | + * @return bool |
|
| 136 | + */ |
|
| 137 | + public function isOID(): bool |
|
| 138 | + { |
|
| 139 | + return Element::TYPE_OBJECT_IDENTIFIER === $this->_type; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Whether value type is string. |
|
| 144 | + * |
|
| 145 | + * @return bool |
|
| 146 | + */ |
|
| 147 | + public function isString(): bool |
|
| 148 | + { |
|
| 149 | + return Element::TYPE_UTF8_STRING === $this->_type; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * Get value. |
|
| 154 | + * |
|
| 155 | + * @return string |
|
| 156 | + */ |
|
| 157 | + public function value(): string |
|
| 158 | + { |
|
| 159 | + return $this->_value; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Generate ASN.1 structure. |
|
| 164 | + * |
|
| 165 | + * @throws \LogicException |
|
| 166 | + * |
|
| 167 | + * @return Element |
|
| 168 | + */ |
|
| 169 | + public function toASN1(): Element |
|
| 170 | + { |
|
| 171 | + switch ($this->_type) { |
|
| 172 | + case Element::TYPE_OCTET_STRING: |
|
| 173 | + return new OctetString($this->_value); |
|
| 174 | + case Element::TYPE_UTF8_STRING: |
|
| 175 | + return new UTF8String($this->_value); |
|
| 176 | + case Element::TYPE_OBJECT_IDENTIFIER: |
|
| 177 | + return new ObjectIdentifier($this->_value); |
|
| 178 | + } |
|
| 179 | + throw new \LogicException( |
|
| 180 | + 'Type ' . Element::tagToName($this->_type) . ' not supported.'); |
|
| 181 | + } |
|
| 182 | 182 | } |
@@ -63,11 +63,11 @@ discard block |
||
| 63 | 63 | public static function fromASN1(UnspecifiedType $el): self |
| 64 | 64 | { |
| 65 | 65 | switch ($el->tag()) { |
| 66 | - case Element::TYPE_OCTET_STRING: |
|
| 67 | - case Element::TYPE_UTF8_STRING: |
|
| 68 | - return new self($el->asString()->string(), $el->tag()); |
|
| 69 | - case Element::TYPE_OBJECT_IDENTIFIER: |
|
| 70 | - return new self($el->asObjectIdentifier()->oid(), $el->tag()); |
|
| 66 | + case Element::TYPE_OCTET_STRING: |
|
| 67 | + case Element::TYPE_UTF8_STRING: |
|
| 68 | + return new self($el->asString()->string(), $el->tag()); |
|
| 69 | + case Element::TYPE_OBJECT_IDENTIFIER: |
|
| 70 | + return new self($el->asObjectIdentifier()->oid(), $el->tag()); |
|
| 71 | 71 | } |
| 72 | 72 | throw new \UnexpectedValueException( |
| 73 | 73 | 'Type ' . Element::tagToName($el->tag()) . ' not supported.'); |
@@ -169,12 +169,12 @@ discard block |
||
| 169 | 169 | public function toASN1(): Element |
| 170 | 170 | { |
| 171 | 171 | switch ($this->_type) { |
| 172 | - case Element::TYPE_OCTET_STRING: |
|
| 173 | - return new OctetString($this->_value); |
|
| 174 | - case Element::TYPE_UTF8_STRING: |
|
| 175 | - return new UTF8String($this->_value); |
|
| 176 | - case Element::TYPE_OBJECT_IDENTIFIER: |
|
| 177 | - return new ObjectIdentifier($this->_value); |
|
| 172 | + case Element::TYPE_OCTET_STRING: |
|
| 173 | + return new OctetString($this->_value); |
|
| 174 | + case Element::TYPE_UTF8_STRING: |
|
| 175 | + return new UTF8String($this->_value); |
|
| 176 | + case Element::TYPE_OBJECT_IDENTIFIER: |
|
| 177 | + return new ObjectIdentifier($this->_value); |
|
| 178 | 178 | } |
| 179 | 179 | throw new \LogicException( |
| 180 | 180 | '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 Sop\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 null|string $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 null|string $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 Sop\X509\AttributeCertificate\Attribute; |
| 6 | 6 | |
@@ -21,191 +21,191 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | abstract class IetfAttrSyntax extends AttributeValue implements \Countable, \IteratorAggregate |
| 23 | 23 | { |
| 24 | - /** |
|
| 25 | - * Policy authority. |
|
| 26 | - * |
|
| 27 | - * @var null|GeneralNames |
|
| 28 | - */ |
|
| 29 | - protected $_policyAuthority; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Values. |
|
| 33 | - * |
|
| 34 | - * @var IetfAttrValue[] |
|
| 35 | - */ |
|
| 36 | - protected $_values; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Constructor. |
|
| 40 | - * |
|
| 41 | - * @param IetfAttrValue ...$values |
|
| 42 | - */ |
|
| 43 | - public function __construct(IetfAttrValue ...$values) |
|
| 44 | - { |
|
| 45 | - $this->_policyAuthority = null; |
|
| 46 | - $this->_values = $values; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * {@inheritdoc} |
|
| 51 | - * |
|
| 52 | - * @return self |
|
| 53 | - */ |
|
| 54 | - public static function fromASN1(UnspecifiedType $el): AttributeValue |
|
| 55 | - { |
|
| 56 | - $seq = $el->asSequence(); |
|
| 57 | - $authority = null; |
|
| 58 | - $idx = 0; |
|
| 59 | - if ($seq->hasTagged(0)) { |
|
| 60 | - $authority = GeneralNames::fromASN1( |
|
| 61 | - $seq->getTagged(0)->asImplicit(Element::TYPE_SEQUENCE) |
|
| 62 | - ->asSequence()); |
|
| 63 | - ++$idx; |
|
| 64 | - } |
|
| 65 | - $values = array_map( |
|
| 66 | - function (UnspecifiedType $el) { |
|
| 67 | - return IetfAttrValue::fromASN1($el); |
|
| 68 | - }, $seq->at($idx)->asSequence()->elements()); |
|
| 69 | - $obj = new static(...$values); |
|
| 70 | - $obj->_policyAuthority = $authority; |
|
| 71 | - return $obj; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Get self with policy authority. |
|
| 76 | - * |
|
| 77 | - * @param GeneralNames $names |
|
| 78 | - * |
|
| 79 | - * @return self |
|
| 80 | - */ |
|
| 81 | - public function withPolicyAuthority(GeneralNames $names): self |
|
| 82 | - { |
|
| 83 | - $obj = clone $this; |
|
| 84 | - $obj->_policyAuthority = $names; |
|
| 85 | - return $obj; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Check whether policy authority is present. |
|
| 90 | - * |
|
| 91 | - * @return bool |
|
| 92 | - */ |
|
| 93 | - public function hasPolicyAuthority(): bool |
|
| 94 | - { |
|
| 95 | - return isset($this->_policyAuthority); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * Get policy authority. |
|
| 100 | - * |
|
| 101 | - * @throws \LogicException If not set |
|
| 102 | - * |
|
| 103 | - * @return GeneralNames |
|
| 104 | - */ |
|
| 105 | - public function policyAuthority(): GeneralNames |
|
| 106 | - { |
|
| 107 | - if (!$this->hasPolicyAuthority()) { |
|
| 108 | - throw new \LogicException('policyAuthority not set.'); |
|
| 109 | - } |
|
| 110 | - return $this->_policyAuthority; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Get values. |
|
| 115 | - * |
|
| 116 | - * @return IetfAttrValue[] |
|
| 117 | - */ |
|
| 118 | - public function values(): array |
|
| 119 | - { |
|
| 120 | - return $this->_values; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Get first value. |
|
| 125 | - * |
|
| 126 | - * @throws \LogicException If not set |
|
| 127 | - * |
|
| 128 | - * @return IetfAttrValue |
|
| 129 | - */ |
|
| 130 | - public function first(): IetfAttrValue |
|
| 131 | - { |
|
| 132 | - if (!count($this->_values)) { |
|
| 133 | - throw new \LogicException('No values.'); |
|
| 134 | - } |
|
| 135 | - return $this->_values[0]; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * {@inheritdoc} |
|
| 140 | - */ |
|
| 141 | - public function toASN1(): Element |
|
| 142 | - { |
|
| 143 | - $elements = []; |
|
| 144 | - if (isset($this->_policyAuthority)) { |
|
| 145 | - $elements[] = new ImplicitlyTaggedType( |
|
| 146 | - 0, $this->_policyAuthority->toASN1()); |
|
| 147 | - } |
|
| 148 | - $values = array_map( |
|
| 149 | - function (IetfAttrValue $val) { |
|
| 150 | - return $val->toASN1(); |
|
| 151 | - }, $this->_values); |
|
| 152 | - $elements[] = new Sequence(...$values); |
|
| 153 | - return new Sequence(...$elements); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * {@inheritdoc} |
|
| 158 | - */ |
|
| 159 | - public function stringValue(): string |
|
| 160 | - { |
|
| 161 | - return '#' . bin2hex($this->toASN1()->toDER()); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * {@inheritdoc} |
|
| 166 | - */ |
|
| 167 | - public function equalityMatchingRule(): MatchingRule |
|
| 168 | - { |
|
| 169 | - return new BinaryMatch(); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * {@inheritdoc} |
|
| 174 | - */ |
|
| 175 | - public function rfc2253String(): string |
|
| 176 | - { |
|
| 177 | - return $this->stringValue(); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * Get number of values. |
|
| 182 | - * |
|
| 183 | - * @see \Countable::count() |
|
| 184 | - * |
|
| 185 | - * @return int |
|
| 186 | - */ |
|
| 187 | - public function count(): int |
|
| 188 | - { |
|
| 189 | - return count($this->_values); |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * Get iterator for values. |
|
| 194 | - * |
|
| 195 | - * @see \IteratorAggregate::getIterator() |
|
| 196 | - * |
|
| 197 | - * @return \ArrayIterator |
|
| 198 | - */ |
|
| 199 | - public function getIterator(): \ArrayIterator |
|
| 200 | - { |
|
| 201 | - return new \ArrayIterator($this->_values); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * {@inheritdoc} |
|
| 206 | - */ |
|
| 207 | - protected function _transcodedString(): string |
|
| 208 | - { |
|
| 209 | - return $this->stringValue(); |
|
| 210 | - } |
|
| 24 | + /** |
|
| 25 | + * Policy authority. |
|
| 26 | + * |
|
| 27 | + * @var null|GeneralNames |
|
| 28 | + */ |
|
| 29 | + protected $_policyAuthority; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Values. |
|
| 33 | + * |
|
| 34 | + * @var IetfAttrValue[] |
|
| 35 | + */ |
|
| 36 | + protected $_values; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Constructor. |
|
| 40 | + * |
|
| 41 | + * @param IetfAttrValue ...$values |
|
| 42 | + */ |
|
| 43 | + public function __construct(IetfAttrValue ...$values) |
|
| 44 | + { |
|
| 45 | + $this->_policyAuthority = null; |
|
| 46 | + $this->_values = $values; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * {@inheritdoc} |
|
| 51 | + * |
|
| 52 | + * @return self |
|
| 53 | + */ |
|
| 54 | + public static function fromASN1(UnspecifiedType $el): AttributeValue |
|
| 55 | + { |
|
| 56 | + $seq = $el->asSequence(); |
|
| 57 | + $authority = null; |
|
| 58 | + $idx = 0; |
|
| 59 | + if ($seq->hasTagged(0)) { |
|
| 60 | + $authority = GeneralNames::fromASN1( |
|
| 61 | + $seq->getTagged(0)->asImplicit(Element::TYPE_SEQUENCE) |
|
| 62 | + ->asSequence()); |
|
| 63 | + ++$idx; |
|
| 64 | + } |
|
| 65 | + $values = array_map( |
|
| 66 | + function (UnspecifiedType $el) { |
|
| 67 | + return IetfAttrValue::fromASN1($el); |
|
| 68 | + }, $seq->at($idx)->asSequence()->elements()); |
|
| 69 | + $obj = new static(...$values); |
|
| 70 | + $obj->_policyAuthority = $authority; |
|
| 71 | + return $obj; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Get self with policy authority. |
|
| 76 | + * |
|
| 77 | + * @param GeneralNames $names |
|
| 78 | + * |
|
| 79 | + * @return self |
|
| 80 | + */ |
|
| 81 | + public function withPolicyAuthority(GeneralNames $names): self |
|
| 82 | + { |
|
| 83 | + $obj = clone $this; |
|
| 84 | + $obj->_policyAuthority = $names; |
|
| 85 | + return $obj; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Check whether policy authority is present. |
|
| 90 | + * |
|
| 91 | + * @return bool |
|
| 92 | + */ |
|
| 93 | + public function hasPolicyAuthority(): bool |
|
| 94 | + { |
|
| 95 | + return isset($this->_policyAuthority); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * Get policy authority. |
|
| 100 | + * |
|
| 101 | + * @throws \LogicException If not set |
|
| 102 | + * |
|
| 103 | + * @return GeneralNames |
|
| 104 | + */ |
|
| 105 | + public function policyAuthority(): GeneralNames |
|
| 106 | + { |
|
| 107 | + if (!$this->hasPolicyAuthority()) { |
|
| 108 | + throw new \LogicException('policyAuthority not set.'); |
|
| 109 | + } |
|
| 110 | + return $this->_policyAuthority; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Get values. |
|
| 115 | + * |
|
| 116 | + * @return IetfAttrValue[] |
|
| 117 | + */ |
|
| 118 | + public function values(): array |
|
| 119 | + { |
|
| 120 | + return $this->_values; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Get first value. |
|
| 125 | + * |
|
| 126 | + * @throws \LogicException If not set |
|
| 127 | + * |
|
| 128 | + * @return IetfAttrValue |
|
| 129 | + */ |
|
| 130 | + public function first(): IetfAttrValue |
|
| 131 | + { |
|
| 132 | + if (!count($this->_values)) { |
|
| 133 | + throw new \LogicException('No values.'); |
|
| 134 | + } |
|
| 135 | + return $this->_values[0]; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * {@inheritdoc} |
|
| 140 | + */ |
|
| 141 | + public function toASN1(): Element |
|
| 142 | + { |
|
| 143 | + $elements = []; |
|
| 144 | + if (isset($this->_policyAuthority)) { |
|
| 145 | + $elements[] = new ImplicitlyTaggedType( |
|
| 146 | + 0, $this->_policyAuthority->toASN1()); |
|
| 147 | + } |
|
| 148 | + $values = array_map( |
|
| 149 | + function (IetfAttrValue $val) { |
|
| 150 | + return $val->toASN1(); |
|
| 151 | + }, $this->_values); |
|
| 152 | + $elements[] = new Sequence(...$values); |
|
| 153 | + return new Sequence(...$elements); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * {@inheritdoc} |
|
| 158 | + */ |
|
| 159 | + public function stringValue(): string |
|
| 160 | + { |
|
| 161 | + return '#' . bin2hex($this->toASN1()->toDER()); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * {@inheritdoc} |
|
| 166 | + */ |
|
| 167 | + public function equalityMatchingRule(): MatchingRule |
|
| 168 | + { |
|
| 169 | + return new BinaryMatch(); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * {@inheritdoc} |
|
| 174 | + */ |
|
| 175 | + public function rfc2253String(): string |
|
| 176 | + { |
|
| 177 | + return $this->stringValue(); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * Get number of values. |
|
| 182 | + * |
|
| 183 | + * @see \Countable::count() |
|
| 184 | + * |
|
| 185 | + * @return int |
|
| 186 | + */ |
|
| 187 | + public function count(): int |
|
| 188 | + { |
|
| 189 | + return count($this->_values); |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * Get iterator for values. |
|
| 194 | + * |
|
| 195 | + * @see \IteratorAggregate::getIterator() |
|
| 196 | + * |
|
| 197 | + * @return \ArrayIterator |
|
| 198 | + */ |
|
| 199 | + public function getIterator(): \ArrayIterator |
|
| 200 | + { |
|
| 201 | + return new \ArrayIterator($this->_values); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * {@inheritdoc} |
|
| 206 | + */ |
|
| 207 | + protected function _transcodedString(): string |
|
| 208 | + { |
|
| 209 | + return $this->stringValue(); |
|
| 210 | + } |
|
| 211 | 211 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types = 1); |
|
| 3 | +declare(strict_types=1); |
|
| 4 | 4 | |
| 5 | 5 | namespace Sop\X509\AttributeCertificate\Attribute; |
| 6 | 6 | |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | ++$idx; |
| 64 | 64 | } |
| 65 | 65 | $values = array_map( |
| 66 | - function (UnspecifiedType $el) { |
|
| 66 | + function(UnspecifiedType $el) { |
|
| 67 | 67 | return IetfAttrValue::fromASN1($el); |
| 68 | 68 | }, $seq->at($idx)->asSequence()->elements()); |
| 69 | 69 | $obj = new static(...$values); |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | 0, $this->_policyAuthority->toASN1()); |
| 147 | 147 | } |
| 148 | 148 | $values = array_map( |
| 149 | - function (IetfAttrValue $val) { |
|
| 149 | + function(IetfAttrValue $val) { |
|
| 150 | 150 | return $val->toASN1(); |
| 151 | 151 | }, $this->_values); |
| 152 | 152 | $elements[] = new Sequence(...$values); |
@@ -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 Sop\X509\AttributeCertificate\Attribute; |
| 6 | 6 | |
@@ -26,200 +26,200 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | class Attributes implements \Countable, \IteratorAggregate |
| 28 | 28 | { |
| 29 | - use AttributeContainer; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Mapping from OID to attribute value class name. |
|
| 33 | - * |
|
| 34 | - * @internal |
|
| 35 | - * |
|
| 36 | - * @var array |
|
| 37 | - */ |
|
| 38 | - const MAP_OID_TO_CLASS = [ |
|
| 39 | - AccessIdentityAttributeValue::OID => AccessIdentityAttributeValue::class, |
|
| 40 | - AuthenticationInfoAttributeValue::OID => AuthenticationInfoAttributeValue::class, |
|
| 41 | - ChargingIdentityAttributeValue::OID => ChargingIdentityAttributeValue::class, |
|
| 42 | - GroupAttributeValue::OID => GroupAttributeValue::class, |
|
| 43 | - AttributeType::OID_ROLE => RoleAttributeValue::class, |
|
| 44 | - ]; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * Constructor. |
|
| 48 | - * |
|
| 49 | - * @param Attribute ...$attribs |
|
| 50 | - */ |
|
| 51 | - public function __construct(Attribute ...$attribs) |
|
| 52 | - { |
|
| 53 | - $this->_attributes = $attribs; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Initialize from attribute values. |
|
| 58 | - * |
|
| 59 | - * @param AttributeValue ...$values |
|
| 60 | - * |
|
| 61 | - * @return self |
|
| 62 | - */ |
|
| 63 | - public static function fromAttributeValues(AttributeValue ...$values): self |
|
| 64 | - { |
|
| 65 | - $attribs = array_map( |
|
| 66 | - function (AttributeValue $value) { |
|
| 67 | - return $value->toAttribute(); |
|
| 68 | - }, $values); |
|
| 69 | - return new self(...$attribs); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Initialize from ASN.1. |
|
| 74 | - * |
|
| 75 | - * @param Sequence $seq |
|
| 76 | - * |
|
| 77 | - * @return self |
|
| 78 | - */ |
|
| 79 | - public static function fromASN1(Sequence $seq): self |
|
| 80 | - { |
|
| 81 | - $attribs = array_map( |
|
| 82 | - function (UnspecifiedType $el) { |
|
| 83 | - return Attribute::fromASN1($el->asSequence()); |
|
| 84 | - }, $seq->elements()); |
|
| 85 | - // cast attributes |
|
| 86 | - $attribs = array_map( |
|
| 87 | - function (Attribute $attr) { |
|
| 88 | - $oid = $attr->oid(); |
|
| 89 | - if (array_key_exists($oid, self::MAP_OID_TO_CLASS)) { |
|
| 90 | - $cls = self::MAP_OID_TO_CLASS[$oid]; |
|
| 91 | - $attr = $attr->castValues($cls); |
|
| 92 | - } |
|
| 93 | - return $attr; |
|
| 94 | - }, $attribs); |
|
| 95 | - return new self(...$attribs); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * Check whether 'Access Identity' attribute is present. |
|
| 100 | - * |
|
| 101 | - * @return bool |
|
| 102 | - */ |
|
| 103 | - public function hasAccessIdentity(): bool |
|
| 104 | - { |
|
| 105 | - return $this->has(AccessIdentityAttributeValue::OID); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * Get the first 'Access Identity' attribute value. |
|
| 110 | - * |
|
| 111 | - * @return AccessIdentityAttributeValue |
|
| 112 | - */ |
|
| 113 | - public function accessIdentity(): AccessIdentityAttributeValue |
|
| 114 | - { |
|
| 115 | - return $this->firstOf(AccessIdentityAttributeValue::OID)->first(); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Check whether 'Service Authentication Information' attribute is present. |
|
| 120 | - * |
|
| 121 | - * @return bool |
|
| 122 | - */ |
|
| 123 | - public function hasAuthenticationInformation(): bool |
|
| 124 | - { |
|
| 125 | - return $this->has(AuthenticationInfoAttributeValue::OID); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * Get the first 'Service Authentication Information' attribute value. |
|
| 130 | - * |
|
| 131 | - * @return AuthenticationInfoAttributeValue |
|
| 132 | - */ |
|
| 133 | - public function authenticationInformation(): AuthenticationInfoAttributeValue |
|
| 134 | - { |
|
| 135 | - return $this->firstOf(AuthenticationInfoAttributeValue::OID)->first(); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * Check whether 'Charging Identity' attribute is present. |
|
| 140 | - * |
|
| 141 | - * @return bool |
|
| 142 | - */ |
|
| 143 | - public function hasChargingIdentity(): bool |
|
| 144 | - { |
|
| 145 | - return $this->has(ChargingIdentityAttributeValue::OID); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * Get the first 'Charging Identity' attribute value. |
|
| 150 | - * |
|
| 151 | - * @return ChargingIdentityAttributeValue |
|
| 152 | - */ |
|
| 153 | - public function chargingIdentity(): ChargingIdentityAttributeValue |
|
| 154 | - { |
|
| 155 | - return $this->firstOf(ChargingIdentityAttributeValue::OID)->first(); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * Check whether 'Group' attribute is present. |
|
| 160 | - * |
|
| 161 | - * @return bool |
|
| 162 | - */ |
|
| 163 | - public function hasGroup(): bool |
|
| 164 | - { |
|
| 165 | - return $this->has(GroupAttributeValue::OID); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * Get the first 'Group' attribute value. |
|
| 170 | - * |
|
| 171 | - * @return GroupAttributeValue |
|
| 172 | - */ |
|
| 173 | - public function group(): GroupAttributeValue |
|
| 174 | - { |
|
| 175 | - return $this->firstOf(GroupAttributeValue::OID)->first(); |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * Check whether 'Role' attribute is present. |
|
| 180 | - * |
|
| 181 | - * @return bool |
|
| 182 | - */ |
|
| 183 | - public function hasRole(): bool |
|
| 184 | - { |
|
| 185 | - return $this->has(AttributeType::OID_ROLE); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * Get the first 'Role' attribute value. |
|
| 190 | - * |
|
| 191 | - * @return RoleAttributeValue |
|
| 192 | - */ |
|
| 193 | - public function role(): RoleAttributeValue |
|
| 194 | - { |
|
| 195 | - return $this->firstOf(AttributeType::OID_ROLE)->first(); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - /** |
|
| 199 | - * Get all 'Role' attribute values. |
|
| 200 | - * |
|
| 201 | - * @return RoleAttributeValue[] |
|
| 202 | - */ |
|
| 203 | - public function roles(): array |
|
| 204 | - { |
|
| 205 | - return array_merge([], |
|
| 206 | - ...array_map( |
|
| 207 | - function (Attribute $attr) { |
|
| 208 | - return $attr->values(); |
|
| 209 | - }, $this->allOf(AttributeType::OID_ROLE))); |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * Generate ASN.1 structure. |
|
| 214 | - * |
|
| 215 | - * @return Sequence |
|
| 216 | - */ |
|
| 217 | - public function toASN1(): Sequence |
|
| 218 | - { |
|
| 219 | - $elements = array_map( |
|
| 220 | - function (Attribute $attr) { |
|
| 221 | - return $attr->toASN1(); |
|
| 222 | - }, array_values($this->_attributes)); |
|
| 223 | - return new Sequence(...$elements); |
|
| 224 | - } |
|
| 29 | + use AttributeContainer; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Mapping from OID to attribute value class name. |
|
| 33 | + * |
|
| 34 | + * @internal |
|
| 35 | + * |
|
| 36 | + * @var array |
|
| 37 | + */ |
|
| 38 | + const MAP_OID_TO_CLASS = [ |
|
| 39 | + AccessIdentityAttributeValue::OID => AccessIdentityAttributeValue::class, |
|
| 40 | + AuthenticationInfoAttributeValue::OID => AuthenticationInfoAttributeValue::class, |
|
| 41 | + ChargingIdentityAttributeValue::OID => ChargingIdentityAttributeValue::class, |
|
| 42 | + GroupAttributeValue::OID => GroupAttributeValue::class, |
|
| 43 | + AttributeType::OID_ROLE => RoleAttributeValue::class, |
|
| 44 | + ]; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * Constructor. |
|
| 48 | + * |
|
| 49 | + * @param Attribute ...$attribs |
|
| 50 | + */ |
|
| 51 | + public function __construct(Attribute ...$attribs) |
|
| 52 | + { |
|
| 53 | + $this->_attributes = $attribs; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Initialize from attribute values. |
|
| 58 | + * |
|
| 59 | + * @param AttributeValue ...$values |
|
| 60 | + * |
|
| 61 | + * @return self |
|
| 62 | + */ |
|
| 63 | + public static function fromAttributeValues(AttributeValue ...$values): self |
|
| 64 | + { |
|
| 65 | + $attribs = array_map( |
|
| 66 | + function (AttributeValue $value) { |
|
| 67 | + return $value->toAttribute(); |
|
| 68 | + }, $values); |
|
| 69 | + return new self(...$attribs); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Initialize from ASN.1. |
|
| 74 | + * |
|
| 75 | + * @param Sequence $seq |
|
| 76 | + * |
|
| 77 | + * @return self |
|
| 78 | + */ |
|
| 79 | + public static function fromASN1(Sequence $seq): self |
|
| 80 | + { |
|
| 81 | + $attribs = array_map( |
|
| 82 | + function (UnspecifiedType $el) { |
|
| 83 | + return Attribute::fromASN1($el->asSequence()); |
|
| 84 | + }, $seq->elements()); |
|
| 85 | + // cast attributes |
|
| 86 | + $attribs = array_map( |
|
| 87 | + function (Attribute $attr) { |
|
| 88 | + $oid = $attr->oid(); |
|
| 89 | + if (array_key_exists($oid, self::MAP_OID_TO_CLASS)) { |
|
| 90 | + $cls = self::MAP_OID_TO_CLASS[$oid]; |
|
| 91 | + $attr = $attr->castValues($cls); |
|
| 92 | + } |
|
| 93 | + return $attr; |
|
| 94 | + }, $attribs); |
|
| 95 | + return new self(...$attribs); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * Check whether 'Access Identity' attribute is present. |
|
| 100 | + * |
|
| 101 | + * @return bool |
|
| 102 | + */ |
|
| 103 | + public function hasAccessIdentity(): bool |
|
| 104 | + { |
|
| 105 | + return $this->has(AccessIdentityAttributeValue::OID); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * Get the first 'Access Identity' attribute value. |
|
| 110 | + * |
|
| 111 | + * @return AccessIdentityAttributeValue |
|
| 112 | + */ |
|
| 113 | + public function accessIdentity(): AccessIdentityAttributeValue |
|
| 114 | + { |
|
| 115 | + return $this->firstOf(AccessIdentityAttributeValue::OID)->first(); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Check whether 'Service Authentication Information' attribute is present. |
|
| 120 | + * |
|
| 121 | + * @return bool |
|
| 122 | + */ |
|
| 123 | + public function hasAuthenticationInformation(): bool |
|
| 124 | + { |
|
| 125 | + return $this->has(AuthenticationInfoAttributeValue::OID); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * Get the first 'Service Authentication Information' attribute value. |
|
| 130 | + * |
|
| 131 | + * @return AuthenticationInfoAttributeValue |
|
| 132 | + */ |
|
| 133 | + public function authenticationInformation(): AuthenticationInfoAttributeValue |
|
| 134 | + { |
|
| 135 | + return $this->firstOf(AuthenticationInfoAttributeValue::OID)->first(); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * Check whether 'Charging Identity' attribute is present. |
|
| 140 | + * |
|
| 141 | + * @return bool |
|
| 142 | + */ |
|
| 143 | + public function hasChargingIdentity(): bool |
|
| 144 | + { |
|
| 145 | + return $this->has(ChargingIdentityAttributeValue::OID); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * Get the first 'Charging Identity' attribute value. |
|
| 150 | + * |
|
| 151 | + * @return ChargingIdentityAttributeValue |
|
| 152 | + */ |
|
| 153 | + public function chargingIdentity(): ChargingIdentityAttributeValue |
|
| 154 | + { |
|
| 155 | + return $this->firstOf(ChargingIdentityAttributeValue::OID)->first(); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * Check whether 'Group' attribute is present. |
|
| 160 | + * |
|
| 161 | + * @return bool |
|
| 162 | + */ |
|
| 163 | + public function hasGroup(): bool |
|
| 164 | + { |
|
| 165 | + return $this->has(GroupAttributeValue::OID); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * Get the first 'Group' attribute value. |
|
| 170 | + * |
|
| 171 | + * @return GroupAttributeValue |
|
| 172 | + */ |
|
| 173 | + public function group(): GroupAttributeValue |
|
| 174 | + { |
|
| 175 | + return $this->firstOf(GroupAttributeValue::OID)->first(); |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * Check whether 'Role' attribute is present. |
|
| 180 | + * |
|
| 181 | + * @return bool |
|
| 182 | + */ |
|
| 183 | + public function hasRole(): bool |
|
| 184 | + { |
|
| 185 | + return $this->has(AttributeType::OID_ROLE); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * Get the first 'Role' attribute value. |
|
| 190 | + * |
|
| 191 | + * @return RoleAttributeValue |
|
| 192 | + */ |
|
| 193 | + public function role(): RoleAttributeValue |
|
| 194 | + { |
|
| 195 | + return $this->firstOf(AttributeType::OID_ROLE)->first(); |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * Get all 'Role' attribute values. |
|
| 200 | + * |
|
| 201 | + * @return RoleAttributeValue[] |
|
| 202 | + */ |
|
| 203 | + public function roles(): array |
|
| 204 | + { |
|
| 205 | + return array_merge([], |
|
| 206 | + ...array_map( |
|
| 207 | + function (Attribute $attr) { |
|
| 208 | + return $attr->values(); |
|
| 209 | + }, $this->allOf(AttributeType::OID_ROLE))); |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * Generate ASN.1 structure. |
|
| 214 | + * |
|
| 215 | + * @return Sequence |
|
| 216 | + */ |
|
| 217 | + public function toASN1(): Sequence |
|
| 218 | + { |
|
| 219 | + $elements = array_map( |
|
| 220 | + function (Attribute $attr) { |
|
| 221 | + return $attr->toASN1(); |
|
| 222 | + }, array_values($this->_attributes)); |
|
| 223 | + return new Sequence(...$elements); |
|
| 224 | + } |
|
| 225 | 225 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types = 1); |
|
| 3 | +declare(strict_types=1); |
|
| 4 | 4 | |
| 5 | 5 | namespace Sop\X509\AttributeCertificate; |
| 6 | 6 | |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | public static function fromAttributeValues(AttributeValue ...$values): self |
| 64 | 64 | { |
| 65 | 65 | $attribs = array_map( |
| 66 | - function (AttributeValue $value) { |
|
| 66 | + function(AttributeValue $value) { |
|
| 67 | 67 | return $value->toAttribute(); |
| 68 | 68 | }, $values); |
| 69 | 69 | return new self(...$attribs); |
@@ -79,12 +79,12 @@ discard block |
||
| 79 | 79 | public static function fromASN1(Sequence $seq): self |
| 80 | 80 | { |
| 81 | 81 | $attribs = array_map( |
| 82 | - function (UnspecifiedType $el) { |
|
| 82 | + function(UnspecifiedType $el) { |
|
| 83 | 83 | return Attribute::fromASN1($el->asSequence()); |
| 84 | 84 | }, $seq->elements()); |
| 85 | 85 | // cast attributes |
| 86 | 86 | $attribs = array_map( |
| 87 | - function (Attribute $attr) { |
|
| 87 | + function(Attribute $attr) { |
|
| 88 | 88 | $oid = $attr->oid(); |
| 89 | 89 | if (array_key_exists($oid, self::MAP_OID_TO_CLASS)) { |
| 90 | 90 | $cls = self::MAP_OID_TO_CLASS[$oid]; |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | { |
| 205 | 205 | return array_merge([], |
| 206 | 206 | ...array_map( |
| 207 | - function (Attribute $attr) { |
|
| 207 | + function(Attribute $attr) { |
|
| 208 | 208 | return $attr->values(); |
| 209 | 209 | }, $this->allOf(AttributeType::OID_ROLE))); |
| 210 | 210 | } |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | public function toASN1(): Sequence |
| 218 | 218 | { |
| 219 | 219 | $elements = array_map( |
| 220 | - function (Attribute $attr) { |
|
| 220 | + function(Attribute $attr) { |
|
| 221 | 221 | return $attr->toASN1(); |
| 222 | 222 | }, array_values($this->_attributes)); |
| 223 | 223 | return new Sequence(...$elements); |