@@ -13,72 +13,72 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class UniqueIdentifier |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * Identifier. |
|
| 18 | - * |
|
| 19 | - * @var BitString $_uid |
|
| 20 | - */ |
|
| 21 | - protected $_uid; |
|
| 16 | + /** |
|
| 17 | + * Identifier. |
|
| 18 | + * |
|
| 19 | + * @var BitString $_uid |
|
| 20 | + */ |
|
| 21 | + protected $_uid; |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Constructor. |
|
| 25 | - * |
|
| 26 | - * @param BitString $bs |
|
| 27 | - */ |
|
| 28 | - public function __construct(BitString $bs) |
|
| 29 | - { |
|
| 30 | - $this->_uid = $bs; |
|
| 31 | - } |
|
| 23 | + /** |
|
| 24 | + * Constructor. |
|
| 25 | + * |
|
| 26 | + * @param BitString $bs |
|
| 27 | + */ |
|
| 28 | + public function __construct(BitString $bs) |
|
| 29 | + { |
|
| 30 | + $this->_uid = $bs; |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Initialize from ASN.1. |
|
| 35 | - * |
|
| 36 | - * @param BitString $bs |
|
| 37 | - * @return self |
|
| 38 | - */ |
|
| 39 | - public static function fromASN1(BitString $bs): UniqueIdentifier |
|
| 40 | - { |
|
| 41 | - return new self($bs); |
|
| 42 | - } |
|
| 33 | + /** |
|
| 34 | + * Initialize from ASN.1. |
|
| 35 | + * |
|
| 36 | + * @param BitString $bs |
|
| 37 | + * @return self |
|
| 38 | + */ |
|
| 39 | + public static function fromASN1(BitString $bs): UniqueIdentifier |
|
| 40 | + { |
|
| 41 | + return new self($bs); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Initialize from string. |
|
| 46 | - * |
|
| 47 | - * @param string $str |
|
| 48 | - * @return self |
|
| 49 | - */ |
|
| 50 | - public static function fromString(string $str): UniqueIdentifier |
|
| 51 | - { |
|
| 52 | - return new self(new BitString($str)); |
|
| 53 | - } |
|
| 44 | + /** |
|
| 45 | + * Initialize from string. |
|
| 46 | + * |
|
| 47 | + * @param string $str |
|
| 48 | + * @return self |
|
| 49 | + */ |
|
| 50 | + public static function fromString(string $str): UniqueIdentifier |
|
| 51 | + { |
|
| 52 | + return new self(new BitString($str)); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Get unique identifier as a string. |
|
| 57 | - * |
|
| 58 | - * @return string |
|
| 59 | - */ |
|
| 60 | - public function string(): string |
|
| 61 | - { |
|
| 62 | - return $this->_uid->string(); |
|
| 63 | - } |
|
| 55 | + /** |
|
| 56 | + * Get unique identifier as a string. |
|
| 57 | + * |
|
| 58 | + * @return string |
|
| 59 | + */ |
|
| 60 | + public function string(): string |
|
| 61 | + { |
|
| 62 | + return $this->_uid->string(); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * Get unique identifier as a bit string. |
|
| 67 | - * |
|
| 68 | - * @return BitString |
|
| 69 | - */ |
|
| 70 | - public function bitString(): BitString |
|
| 71 | - { |
|
| 72 | - return $this->_uid; |
|
| 73 | - } |
|
| 65 | + /** |
|
| 66 | + * Get unique identifier as a bit string. |
|
| 67 | + * |
|
| 68 | + * @return BitString |
|
| 69 | + */ |
|
| 70 | + public function bitString(): BitString |
|
| 71 | + { |
|
| 72 | + return $this->_uid; |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * Get ASN.1 element. |
|
| 77 | - * |
|
| 78 | - * @return BitString |
|
| 79 | - */ |
|
| 80 | - public function toASN1(): BitString |
|
| 81 | - { |
|
| 82 | - return $this->_uid; |
|
| 83 | - } |
|
| 75 | + /** |
|
| 76 | + * Get ASN.1 element. |
|
| 77 | + * |
|
| 78 | + * @return BitString |
|
| 79 | + */ |
|
| 80 | + public function toASN1(): BitString |
|
| 81 | + { |
|
| 82 | + return $this->_uid; |
|
| 83 | + } |
|
| 84 | 84 | } |
@@ -12,208 +12,208 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class CertificateBundle implements \Countable, \IteratorAggregate |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * Certificates. |
|
| 17 | - * |
|
| 18 | - * @var Certificate[] $_certs |
|
| 19 | - */ |
|
| 20 | - protected $_certs; |
|
| 15 | + /** |
|
| 16 | + * Certificates. |
|
| 17 | + * |
|
| 18 | + * @var Certificate[] $_certs |
|
| 19 | + */ |
|
| 20 | + protected $_certs; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Mapping from public key id to array of certificates. |
|
| 24 | - * |
|
| 25 | - * @var null|(Certificate[])[] |
|
| 26 | - */ |
|
| 27 | - private $_keyIdMap; |
|
| 22 | + /** |
|
| 23 | + * Mapping from public key id to array of certificates. |
|
| 24 | + * |
|
| 25 | + * @var null|(Certificate[])[] |
|
| 26 | + */ |
|
| 27 | + private $_keyIdMap; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Constructor. |
|
| 31 | - * |
|
| 32 | - * @param Certificate ...$certs Certificate objects |
|
| 33 | - */ |
|
| 34 | - public function __construct(Certificate ...$certs) |
|
| 35 | - { |
|
| 36 | - $this->_certs = $certs; |
|
| 37 | - } |
|
| 29 | + /** |
|
| 30 | + * Constructor. |
|
| 31 | + * |
|
| 32 | + * @param Certificate ...$certs Certificate objects |
|
| 33 | + */ |
|
| 34 | + public function __construct(Certificate ...$certs) |
|
| 35 | + { |
|
| 36 | + $this->_certs = $certs; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Reset internal cached variables on clone. |
|
| 41 | - */ |
|
| 42 | - public function __clone() |
|
| 43 | - { |
|
| 44 | - $this->_keyIdMap = null; |
|
| 45 | - } |
|
| 39 | + /** |
|
| 40 | + * Reset internal cached variables on clone. |
|
| 41 | + */ |
|
| 42 | + public function __clone() |
|
| 43 | + { |
|
| 44 | + $this->_keyIdMap = null; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Initialize from PEMs. |
|
| 49 | - * |
|
| 50 | - * @param PEM ...$pems PEM objects |
|
| 51 | - * @return self |
|
| 52 | - */ |
|
| 53 | - public static function fromPEMs(PEM ...$pems): self |
|
| 54 | - { |
|
| 55 | - $certs = array_map( |
|
| 56 | - function ($pem) { |
|
| 57 | - return Certificate::fromPEM($pem); |
|
| 58 | - }, $pems); |
|
| 59 | - return new self(...$certs); |
|
| 60 | - } |
|
| 47 | + /** |
|
| 48 | + * Initialize from PEMs. |
|
| 49 | + * |
|
| 50 | + * @param PEM ...$pems PEM objects |
|
| 51 | + * @return self |
|
| 52 | + */ |
|
| 53 | + public static function fromPEMs(PEM ...$pems): self |
|
| 54 | + { |
|
| 55 | + $certs = array_map( |
|
| 56 | + function ($pem) { |
|
| 57 | + return Certificate::fromPEM($pem); |
|
| 58 | + }, $pems); |
|
| 59 | + return new self(...$certs); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Initialize from PEM bundle. |
|
| 64 | - * |
|
| 65 | - * @param PEMBundle $pem_bundle |
|
| 66 | - * @return self |
|
| 67 | - */ |
|
| 68 | - public static function fromPEMBundle(PEMBundle $pem_bundle): self |
|
| 69 | - { |
|
| 70 | - return self::fromPEMs(...$pem_bundle->all()); |
|
| 71 | - } |
|
| 62 | + /** |
|
| 63 | + * Initialize from PEM bundle. |
|
| 64 | + * |
|
| 65 | + * @param PEMBundle $pem_bundle |
|
| 66 | + * @return self |
|
| 67 | + */ |
|
| 68 | + public static function fromPEMBundle(PEMBundle $pem_bundle): self |
|
| 69 | + { |
|
| 70 | + return self::fromPEMs(...$pem_bundle->all()); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * Get self with certificates added. |
|
| 75 | - * |
|
| 76 | - * @param Certificate ...$cert |
|
| 77 | - * @return self |
|
| 78 | - */ |
|
| 79 | - public function withCertificates(Certificate ...$cert): self |
|
| 80 | - { |
|
| 81 | - $obj = clone $this; |
|
| 82 | - $obj->_certs = array_merge($obj->_certs, $cert); |
|
| 83 | - return $obj; |
|
| 84 | - } |
|
| 73 | + /** |
|
| 74 | + * Get self with certificates added. |
|
| 75 | + * |
|
| 76 | + * @param Certificate ...$cert |
|
| 77 | + * @return self |
|
| 78 | + */ |
|
| 79 | + public function withCertificates(Certificate ...$cert): self |
|
| 80 | + { |
|
| 81 | + $obj = clone $this; |
|
| 82 | + $obj->_certs = array_merge($obj->_certs, $cert); |
|
| 83 | + return $obj; |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * Get self with certificates from PEMBundle added. |
|
| 88 | - * |
|
| 89 | - * @param PEMBundle $pem_bundle |
|
| 90 | - * @return self |
|
| 91 | - */ |
|
| 92 | - public function withPEMBundle(PEMBundle $pem_bundle): self |
|
| 93 | - { |
|
| 94 | - $certs = $this->_certs; |
|
| 95 | - foreach ($pem_bundle as $pem) { |
|
| 96 | - $certs[] = Certificate::fromPEM($pem); |
|
| 97 | - } |
|
| 98 | - return new self(...$certs); |
|
| 99 | - } |
|
| 86 | + /** |
|
| 87 | + * Get self with certificates from PEMBundle added. |
|
| 88 | + * |
|
| 89 | + * @param PEMBundle $pem_bundle |
|
| 90 | + * @return self |
|
| 91 | + */ |
|
| 92 | + public function withPEMBundle(PEMBundle $pem_bundle): self |
|
| 93 | + { |
|
| 94 | + $certs = $this->_certs; |
|
| 95 | + foreach ($pem_bundle as $pem) { |
|
| 96 | + $certs[] = Certificate::fromPEM($pem); |
|
| 97 | + } |
|
| 98 | + return new self(...$certs); |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * Get self with single certificate from PEM added. |
|
| 103 | - * |
|
| 104 | - * @param PEM $pem |
|
| 105 | - * @return self |
|
| 106 | - */ |
|
| 107 | - public function withPEM(PEM $pem): self |
|
| 108 | - { |
|
| 109 | - $certs = $this->_certs; |
|
| 110 | - $certs[] = Certificate::fromPEM($pem); |
|
| 111 | - return new self(...$certs); |
|
| 112 | - } |
|
| 101 | + /** |
|
| 102 | + * Get self with single certificate from PEM added. |
|
| 103 | + * |
|
| 104 | + * @param PEM $pem |
|
| 105 | + * @return self |
|
| 106 | + */ |
|
| 107 | + public function withPEM(PEM $pem): self |
|
| 108 | + { |
|
| 109 | + $certs = $this->_certs; |
|
| 110 | + $certs[] = Certificate::fromPEM($pem); |
|
| 111 | + return new self(...$certs); |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - /** |
|
| 115 | - * Check whether bundle contains a given certificate. |
|
| 116 | - * |
|
| 117 | - * @param Certificate $cert |
|
| 118 | - * @return bool |
|
| 119 | - */ |
|
| 120 | - public function contains(Certificate $cert): bool |
|
| 121 | - { |
|
| 122 | - $id = self::_getCertKeyId($cert); |
|
| 123 | - $map = $this->_getKeyIdMap(); |
|
| 124 | - if (!isset($map[$id])) { |
|
| 125 | - return false; |
|
| 126 | - } |
|
| 127 | - foreach ($map[$id] as $c) { |
|
| 128 | - /** @var Certificate $c */ |
|
| 129 | - if ($cert->equals($c)) { |
|
| 130 | - return true; |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - return false; |
|
| 134 | - } |
|
| 114 | + /** |
|
| 115 | + * Check whether bundle contains a given certificate. |
|
| 116 | + * |
|
| 117 | + * @param Certificate $cert |
|
| 118 | + * @return bool |
|
| 119 | + */ |
|
| 120 | + public function contains(Certificate $cert): bool |
|
| 121 | + { |
|
| 122 | + $id = self::_getCertKeyId($cert); |
|
| 123 | + $map = $this->_getKeyIdMap(); |
|
| 124 | + if (!isset($map[$id])) { |
|
| 125 | + return false; |
|
| 126 | + } |
|
| 127 | + foreach ($map[$id] as $c) { |
|
| 128 | + /** @var Certificate $c */ |
|
| 129 | + if ($cert->equals($c)) { |
|
| 130 | + return true; |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + return false; |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - /** |
|
| 137 | - * Get all certificates that have given subject key identifier. |
|
| 138 | - * |
|
| 139 | - * @param string $id |
|
| 140 | - * @return Certificate[] |
|
| 141 | - */ |
|
| 142 | - public function allBySubjectKeyIdentifier(string $id): array |
|
| 143 | - { |
|
| 144 | - $map = $this->_getKeyIdMap(); |
|
| 145 | - if (!isset($map[$id])) { |
|
| 146 | - return array(); |
|
| 147 | - } |
|
| 148 | - return $map[$id]; |
|
| 149 | - } |
|
| 136 | + /** |
|
| 137 | + * Get all certificates that have given subject key identifier. |
|
| 138 | + * |
|
| 139 | + * @param string $id |
|
| 140 | + * @return Certificate[] |
|
| 141 | + */ |
|
| 142 | + public function allBySubjectKeyIdentifier(string $id): array |
|
| 143 | + { |
|
| 144 | + $map = $this->_getKeyIdMap(); |
|
| 145 | + if (!isset($map[$id])) { |
|
| 146 | + return array(); |
|
| 147 | + } |
|
| 148 | + return $map[$id]; |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - /** |
|
| 152 | - * Get all certificates in a bundle. |
|
| 153 | - * |
|
| 154 | - * @return Certificate[] |
|
| 155 | - */ |
|
| 156 | - public function all(): array |
|
| 157 | - { |
|
| 158 | - return $this->_certs; |
|
| 159 | - } |
|
| 151 | + /** |
|
| 152 | + * Get all certificates in a bundle. |
|
| 153 | + * |
|
| 154 | + * @return Certificate[] |
|
| 155 | + */ |
|
| 156 | + public function all(): array |
|
| 157 | + { |
|
| 158 | + return $this->_certs; |
|
| 159 | + } |
|
| 160 | 160 | |
| 161 | - /** |
|
| 162 | - * Get certificate mapping by public key id. |
|
| 163 | - * |
|
| 164 | - * @return (Certificate[])[] |
|
| 165 | - */ |
|
| 166 | - private function _getKeyIdMap(): array |
|
| 167 | - { |
|
| 168 | - // lazily build mapping |
|
| 169 | - if (!isset($this->_keyIdMap)) { |
|
| 170 | - $this->_keyIdMap = array(); |
|
| 171 | - foreach ($this->_certs as $cert) { |
|
| 172 | - $id = self::_getCertKeyId($cert); |
|
| 173 | - if (!isset($this->_keyIdMap[$id])) { |
|
| 174 | - $this->_keyIdMap[$id] = array(); |
|
| 175 | - } |
|
| 176 | - array_push($this->_keyIdMap[$id], $cert); |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - return $this->_keyIdMap; |
|
| 180 | - } |
|
| 161 | + /** |
|
| 162 | + * Get certificate mapping by public key id. |
|
| 163 | + * |
|
| 164 | + * @return (Certificate[])[] |
|
| 165 | + */ |
|
| 166 | + private function _getKeyIdMap(): array |
|
| 167 | + { |
|
| 168 | + // lazily build mapping |
|
| 169 | + if (!isset($this->_keyIdMap)) { |
|
| 170 | + $this->_keyIdMap = array(); |
|
| 171 | + foreach ($this->_certs as $cert) { |
|
| 172 | + $id = self::_getCertKeyId($cert); |
|
| 173 | + if (!isset($this->_keyIdMap[$id])) { |
|
| 174 | + $this->_keyIdMap[$id] = array(); |
|
| 175 | + } |
|
| 176 | + array_push($this->_keyIdMap[$id], $cert); |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + return $this->_keyIdMap; |
|
| 180 | + } |
|
| 181 | 181 | |
| 182 | - /** |
|
| 183 | - * Get public key id for the certificate. |
|
| 184 | - * |
|
| 185 | - * @param Certificate $cert |
|
| 186 | - * @return string |
|
| 187 | - */ |
|
| 188 | - private static function _getCertKeyId(Certificate $cert): string |
|
| 189 | - { |
|
| 190 | - $exts = $cert->tbsCertificate()->extensions(); |
|
| 191 | - if ($exts->hasSubjectKeyIdentifier()) { |
|
| 192 | - return $exts->subjectKeyIdentifier()->keyIdentifier(); |
|
| 193 | - } |
|
| 194 | - return $cert->tbsCertificate() |
|
| 195 | - ->subjectPublicKeyInfo() |
|
| 196 | - ->keyIdentifier(); |
|
| 197 | - } |
|
| 182 | + /** |
|
| 183 | + * Get public key id for the certificate. |
|
| 184 | + * |
|
| 185 | + * @param Certificate $cert |
|
| 186 | + * @return string |
|
| 187 | + */ |
|
| 188 | + private static function _getCertKeyId(Certificate $cert): string |
|
| 189 | + { |
|
| 190 | + $exts = $cert->tbsCertificate()->extensions(); |
|
| 191 | + if ($exts->hasSubjectKeyIdentifier()) { |
|
| 192 | + return $exts->subjectKeyIdentifier()->keyIdentifier(); |
|
| 193 | + } |
|
| 194 | + return $cert->tbsCertificate() |
|
| 195 | + ->subjectPublicKeyInfo() |
|
| 196 | + ->keyIdentifier(); |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | - /** |
|
| 200 | - * |
|
| 201 | - * @see \Countable::count() |
|
| 202 | - * @return int |
|
| 203 | - */ |
|
| 204 | - public function count(): int |
|
| 205 | - { |
|
| 206 | - return count($this->_certs); |
|
| 207 | - } |
|
| 199 | + /** |
|
| 200 | + * |
|
| 201 | + * @see \Countable::count() |
|
| 202 | + * @return int |
|
| 203 | + */ |
|
| 204 | + public function count(): int |
|
| 205 | + { |
|
| 206 | + return count($this->_certs); |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | - /** |
|
| 210 | - * Get iterator for certificates. |
|
| 211 | - * |
|
| 212 | - * @see \IteratorAggregate::getIterator() |
|
| 213 | - * @return \ArrayIterator |
|
| 214 | - */ |
|
| 215 | - public function getIterator(): \ArrayIterator |
|
| 216 | - { |
|
| 217 | - return new \ArrayIterator($this->_certs); |
|
| 218 | - } |
|
| 209 | + /** |
|
| 210 | + * Get iterator for certificates. |
|
| 211 | + * |
|
| 212 | + * @see \IteratorAggregate::getIterator() |
|
| 213 | + * @return \ArrayIterator |
|
| 214 | + */ |
|
| 215 | + public function getIterator(): \ArrayIterator |
|
| 216 | + { |
|
| 217 | + return new \ArrayIterator($this->_certs); |
|
| 218 | + } |
|
| 219 | 219 | } |
@@ -18,414 +18,414 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class Extensions implements \Countable, \IteratorAggregate |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * Extensions. |
|
| 23 | - * |
|
| 24 | - * @var Extension\Extension[] $_extensions |
|
| 25 | - */ |
|
| 26 | - protected $_extensions; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * Constructor. |
|
| 30 | - * |
|
| 31 | - * @param Ext\Extension ...$extensions Extension objects |
|
| 32 | - */ |
|
| 33 | - public function __construct(Ext\Extension ...$extensions) |
|
| 34 | - { |
|
| 35 | - $this->_extensions = array(); |
|
| 36 | - foreach ($extensions as $ext) { |
|
| 37 | - $this->_extensions[$ext->oid()] = $ext; |
|
| 38 | - } |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * Initialize from ASN.1. |
|
| 43 | - * |
|
| 44 | - * @param Sequence $seq |
|
| 45 | - * @return self |
|
| 46 | - */ |
|
| 47 | - public static function fromASN1(Sequence $seq): self |
|
| 48 | - { |
|
| 49 | - $extensions = array_map( |
|
| 50 | - function (UnspecifiedType $el) { |
|
| 51 | - return Ext\Extension::fromASN1($el->asSequence()); |
|
| 52 | - }, $seq->elements()); |
|
| 53 | - return new self(...$extensions); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Generate ASN.1 structure. |
|
| 58 | - * |
|
| 59 | - * @return Sequence |
|
| 60 | - */ |
|
| 61 | - public function toASN1(): Sequence |
|
| 62 | - { |
|
| 63 | - $elements = array_values( |
|
| 64 | - array_map( |
|
| 65 | - function ($ext) { |
|
| 66 | - return $ext->toASN1(); |
|
| 67 | - }, $this->_extensions)); |
|
| 68 | - return new Sequence(...$elements); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Get self with extensions added. |
|
| 73 | - * |
|
| 74 | - * @param Ext\Extension ...$exts One or more extensions to add |
|
| 75 | - * @return self |
|
| 76 | - */ |
|
| 77 | - public function withExtensions(Ext\Extension ...$exts): self |
|
| 78 | - { |
|
| 79 | - $obj = clone $this; |
|
| 80 | - foreach ($exts as $ext) { |
|
| 81 | - $obj->_extensions[$ext->oid()] = $ext; |
|
| 82 | - } |
|
| 83 | - return $obj; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Check whether extension is present. |
|
| 88 | - * |
|
| 89 | - * @param string $oid Extensions OID |
|
| 90 | - * @return bool |
|
| 91 | - */ |
|
| 92 | - public function has(string $oid): bool |
|
| 93 | - { |
|
| 94 | - return isset($this->_extensions[$oid]); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * Get extension by OID. |
|
| 99 | - * |
|
| 100 | - * @param string $oid |
|
| 101 | - * @throws \LogicException If extension is not present |
|
| 102 | - * @return Extension\Extension |
|
| 103 | - */ |
|
| 104 | - public function get(string $oid): Ext\Extension |
|
| 105 | - { |
|
| 106 | - if (!$this->has($oid)) { |
|
| 107 | - throw new \LogicException("No extension by OID $oid."); |
|
| 108 | - } |
|
| 109 | - return $this->_extensions[$oid]; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Check whether 'Authority Key Identifier' extension is present. |
|
| 114 | - * |
|
| 115 | - * @return bool |
|
| 116 | - */ |
|
| 117 | - public function hasAuthorityKeyIdentifier(): bool |
|
| 118 | - { |
|
| 119 | - return $this->has(Ext\Extension::OID_AUTHORITY_KEY_IDENTIFIER); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Get 'Authority Key Identifier' extension. |
|
| 124 | - * |
|
| 125 | - * @throws \LogicException If extension is not present |
|
| 126 | - * @return \X509\Certificate\Extension\AuthorityKeyIdentifierExtension |
|
| 127 | - */ |
|
| 128 | - public function authorityKeyIdentifier(): Ext\AuthorityKeyIdentifierExtension |
|
| 129 | - { |
|
| 130 | - /** @var Extension\AuthorityKeyIdentifierExtension $keyIdentifier */ |
|
| 131 | - $keyIdentifier = $this->get(Ext\Extension::OID_AUTHORITY_KEY_IDENTIFIER); |
|
| 132 | - return $keyIdentifier; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Check whether 'Subject Key Identifier' extension is present. |
|
| 137 | - * |
|
| 138 | - * @return bool |
|
| 139 | - */ |
|
| 140 | - public function hasSubjectKeyIdentifier(): bool |
|
| 141 | - { |
|
| 142 | - return $this->has(Ext\Extension::OID_SUBJECT_KEY_IDENTIFIER); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * Get 'Subject Key Identifier' extension. |
|
| 147 | - * |
|
| 148 | - * @throws \LogicException If extension is not present |
|
| 149 | - * @return \X509\Certificate\Extension\SubjectKeyIdentifierExtension |
|
| 150 | - */ |
|
| 151 | - public function subjectKeyIdentifier(): Ext\SubjectKeyIdentifierExtension |
|
| 152 | - { |
|
| 153 | - /** @var Extension\SubjectKeyIdentifierExtension $subjectKeyIdentifier */ |
|
| 154 | - $subjectKeyIdentifier = $this->get( |
|
| 155 | - Ext\Extension::OID_SUBJECT_KEY_IDENTIFIER); |
|
| 156 | - return $subjectKeyIdentifier; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * Check whether 'Key Usage' extension is present. |
|
| 161 | - * |
|
| 162 | - * @return bool |
|
| 163 | - */ |
|
| 164 | - public function hasKeyUsage(): bool |
|
| 165 | - { |
|
| 166 | - return $this->has(Ext\Extension::OID_KEY_USAGE); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * Get 'Key Usage' extension. |
|
| 171 | - * |
|
| 172 | - * @throws \LogicException If extension is not present |
|
| 173 | - * @return \X509\Certificate\Extension\KeyUsageExtension |
|
| 174 | - */ |
|
| 175 | - public function keyUsage(): Ext\KeyUsageExtension |
|
| 176 | - { |
|
| 177 | - /** @var Extension\KeyUsageExtension $keyUsage */ |
|
| 178 | - $keyUsage = $this->get(Ext\Extension::OID_KEY_USAGE); |
|
| 179 | - return $keyUsage; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * Check whether 'Certificate Policies' extension is present. |
|
| 184 | - * |
|
| 185 | - * @return bool |
|
| 186 | - */ |
|
| 187 | - public function hasCertificatePolicies(): bool |
|
| 188 | - { |
|
| 189 | - return $this->has(Ext\Extension::OID_CERTIFICATE_POLICIES); |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * Get 'Certificate Policies' extension. |
|
| 194 | - * |
|
| 195 | - * @throws \LogicException If extension is not present |
|
| 196 | - * @return \X509\Certificate\Extension\CertificatePoliciesExtension |
|
| 197 | - */ |
|
| 198 | - public function certificatePolicies(): Ext\CertificatePoliciesExtension |
|
| 199 | - { |
|
| 200 | - /** @var Extension\CertificatePoliciesExtension $certPolicies */ |
|
| 201 | - $certPolicies = $this->get(Ext\Extension::OID_CERTIFICATE_POLICIES); |
|
| 202 | - return $certPolicies; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * Check whether 'Policy Mappings' extension is present. |
|
| 207 | - * |
|
| 208 | - * @return bool |
|
| 209 | - */ |
|
| 210 | - public function hasPolicyMappings(): bool |
|
| 211 | - { |
|
| 212 | - return $this->has(Ext\Extension::OID_POLICY_MAPPINGS); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * Get 'Policy Mappings' extension. |
|
| 217 | - * |
|
| 218 | - * @throws \LogicException If extension is not present |
|
| 219 | - * @return \X509\Certificate\Extension\PolicyMappingsExtension |
|
| 220 | - */ |
|
| 221 | - public function policyMappings(): Ext\PolicyMappingsExtension |
|
| 222 | - { |
|
| 223 | - /** @var Extension\PolicyMappingsExtension $policyMappings */ |
|
| 224 | - $policyMappings = $this->get(Ext\Extension::OID_POLICY_MAPPINGS); |
|
| 225 | - return $policyMappings; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * Check whether 'Subject Alternative Name' extension is present. |
|
| 230 | - * |
|
| 231 | - * @return bool |
|
| 232 | - */ |
|
| 233 | - public function hasSubjectAlternativeName(): bool |
|
| 234 | - { |
|
| 235 | - return $this->has(Ext\Extension::OID_SUBJECT_ALT_NAME); |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * Get 'Subject Alternative Name' extension. |
|
| 240 | - * |
|
| 241 | - * @throws \LogicException If extension is not present |
|
| 242 | - * @return \X509\Certificate\Extension\SubjectAlternativeNameExtension |
|
| 243 | - */ |
|
| 244 | - public function subjectAlternativeName(): Ext\SubjectAlternativeNameExtension |
|
| 245 | - { |
|
| 246 | - /** @var Extension\SubjectAlternativeNameExtension $subjectAltName */ |
|
| 247 | - $subjectAltName = $this->get(Ext\Extension::OID_SUBJECT_ALT_NAME); |
|
| 248 | - return $subjectAltName; |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * Check whether 'Issuer Alternative Name' extension is present. |
|
| 253 | - * |
|
| 254 | - * @return bool |
|
| 255 | - */ |
|
| 256 | - public function hasIssuerAlternativeName(): bool |
|
| 257 | - { |
|
| 258 | - return $this->has(Ext\Extension::OID_ISSUER_ALT_NAME); |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * Get 'Issuer Alternative Name' extension. |
|
| 263 | - * |
|
| 264 | - * @return \X509\Certificate\Extension\IssuerAlternativeNameExtension |
|
| 265 | - */ |
|
| 266 | - public function issuerAlternativeName(): Ext\IssuerAlternativeNameExtension |
|
| 267 | - { |
|
| 268 | - /** @var Extension\IssuerAlternativeNameExtension $issuerAltName */ |
|
| 269 | - $issuerAltName = $this->get(Ext\Extension::OID_ISSUER_ALT_NAME); |
|
| 270 | - return $issuerAltName; |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - /** |
|
| 274 | - * Check whether 'Basic Constraints' extension is present. |
|
| 275 | - * |
|
| 276 | - * @return bool |
|
| 277 | - */ |
|
| 278 | - public function hasBasicConstraints(): bool |
|
| 279 | - { |
|
| 280 | - return $this->has(Ext\Extension::OID_BASIC_CONSTRAINTS); |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - /** |
|
| 284 | - * Get 'Basic Constraints' extension. |
|
| 285 | - * |
|
| 286 | - * @throws \LogicException If extension is not present |
|
| 287 | - * @return \X509\Certificate\Extension\BasicConstraintsExtension |
|
| 288 | - */ |
|
| 289 | - public function basicConstraints(): Ext\BasicConstraintsExtension |
|
| 290 | - { |
|
| 291 | - /** @var Extension\BasicConstraintsExtension $basicConstraints */ |
|
| 292 | - $basicConstraints = $this->get(Ext\Extension::OID_BASIC_CONSTRAINTS); |
|
| 293 | - return $basicConstraints; |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - /** |
|
| 297 | - * Check whether 'Name Constraints' extension is present. |
|
| 298 | - * |
|
| 299 | - * @return bool |
|
| 300 | - */ |
|
| 301 | - public function hasNameConstraints(): bool |
|
| 302 | - { |
|
| 303 | - return $this->has(Ext\Extension::OID_NAME_CONSTRAINTS); |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * Get 'Name Constraints' extension. |
|
| 308 | - * |
|
| 309 | - * @throws \LogicException If extension is not present |
|
| 310 | - * @return \X509\Certificate\Extension\NameConstraintsExtension |
|
| 311 | - */ |
|
| 312 | - public function nameConstraints(): Ext\NameConstraintsExtension |
|
| 313 | - { |
|
| 314 | - /** @var Extension\NameConstraintsExtension $nameConstraints */ |
|
| 315 | - $nameConstraints = $this->get(Ext\Extension::OID_NAME_CONSTRAINTS); |
|
| 316 | - return $nameConstraints; |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - /** |
|
| 320 | - * Check whether 'Policy Constraints' extension is present. |
|
| 321 | - * |
|
| 322 | - * @return bool |
|
| 323 | - */ |
|
| 324 | - public function hasPolicyConstraints(): bool |
|
| 325 | - { |
|
| 326 | - return $this->has(Ext\Extension::OID_POLICY_CONSTRAINTS); |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - /** |
|
| 330 | - * Get 'Policy Constraints' extension. |
|
| 331 | - * |
|
| 332 | - * @throws \LogicException If extension is not present |
|
| 333 | - * @return \X509\Certificate\Extension\PolicyConstraintsExtension |
|
| 334 | - */ |
|
| 335 | - public function policyConstraints(): Ext\PolicyConstraintsExtension |
|
| 336 | - { |
|
| 337 | - /** @var Extension\PolicyConstraintsExtension $policyConstraints */ |
|
| 338 | - $policyConstraints = $this->get(Ext\Extension::OID_POLICY_CONSTRAINTS); |
|
| 339 | - return $policyConstraints; |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - /** |
|
| 343 | - * Check whether 'Extended Key Usage' extension is present. |
|
| 344 | - * |
|
| 345 | - * @return bool |
|
| 346 | - */ |
|
| 347 | - public function hasExtendedKeyUsage(): bool |
|
| 348 | - { |
|
| 349 | - return $this->has(Ext\Extension::OID_EXT_KEY_USAGE); |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * Get 'Extended Key Usage' extension. |
|
| 354 | - * |
|
| 355 | - * @throws \LogicException If extension is not present |
|
| 356 | - * @return \X509\Certificate\Extension\ExtendedKeyUsageExtension |
|
| 357 | - */ |
|
| 358 | - public function extendedKeyUsage(): Ext\ExtendedKeyUsageExtension |
|
| 359 | - { |
|
| 360 | - /** @var Extension\ExtendedKeyUsageExtension $keyUsage */ |
|
| 361 | - $keyUsage = $this->get(Ext\Extension::OID_EXT_KEY_USAGE); |
|
| 362 | - return $keyUsage; |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - /** |
|
| 366 | - * Check whether 'CRL Distribution Points' extension is present. |
|
| 367 | - * |
|
| 368 | - * @return bool |
|
| 369 | - */ |
|
| 370 | - public function hasCRLDistributionPoints(): bool |
|
| 371 | - { |
|
| 372 | - return $this->has(Ext\Extension::OID_CRL_DISTRIBUTION_POINTS); |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - /** |
|
| 376 | - * Get 'CRL Distribution Points' extension. |
|
| 377 | - * |
|
| 378 | - * @throws \LogicException If extension is not present |
|
| 379 | - * @return \X509\Certificate\Extension\CRLDistributionPointsExtension |
|
| 380 | - */ |
|
| 381 | - public function crlDistributionPoints(): Ext\CRLDistributionPointsExtension |
|
| 382 | - { |
|
| 383 | - /** @var Extension\CRLDistributionPointsExtension $crlDist */ |
|
| 384 | - $crlDist = $this->get(Ext\Extension::OID_CRL_DISTRIBUTION_POINTS); |
|
| 385 | - return $crlDist; |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - /** |
|
| 389 | - * Check whether 'Inhibit anyPolicy' extension is present. |
|
| 390 | - * |
|
| 391 | - * @return bool |
|
| 392 | - */ |
|
| 393 | - public function hasInhibitAnyPolicy(): bool |
|
| 394 | - { |
|
| 395 | - return $this->has(Ext\Extension::OID_INHIBIT_ANY_POLICY); |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - /** |
|
| 399 | - * Get 'Inhibit anyPolicy' extension. |
|
| 400 | - * |
|
| 401 | - * @throws \LogicException If extension is not present |
|
| 402 | - * @return \X509\Certificate\Extension\InhibitAnyPolicyExtension |
|
| 403 | - */ |
|
| 404 | - public function inhibitAnyPolicy(): Ext\InhibitAnyPolicyExtension |
|
| 405 | - { |
|
| 406 | - /** @var Extension\InhibitAnyPolicyExtension $inhibitAny */ |
|
| 407 | - $inhibitAny = $this->get(Ext\Extension::OID_INHIBIT_ANY_POLICY); |
|
| 408 | - return $inhibitAny; |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - /** |
|
| 412 | - * |
|
| 413 | - * @see \Countable::count() |
|
| 414 | - * @return int |
|
| 415 | - */ |
|
| 416 | - public function count(): int |
|
| 417 | - { |
|
| 418 | - return count($this->_extensions); |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - /** |
|
| 422 | - * Get iterator for extensions. |
|
| 423 | - * |
|
| 424 | - * @see \IteratorAggregate::getIterator() |
|
| 425 | - * @return \Traversable |
|
| 426 | - */ |
|
| 427 | - public function getIterator(): \Traversable |
|
| 428 | - { |
|
| 429 | - return new \ArrayIterator($this->_extensions); |
|
| 430 | - } |
|
| 21 | + /** |
|
| 22 | + * Extensions. |
|
| 23 | + * |
|
| 24 | + * @var Extension\Extension[] $_extensions |
|
| 25 | + */ |
|
| 26 | + protected $_extensions; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * Constructor. |
|
| 30 | + * |
|
| 31 | + * @param Ext\Extension ...$extensions Extension objects |
|
| 32 | + */ |
|
| 33 | + public function __construct(Ext\Extension ...$extensions) |
|
| 34 | + { |
|
| 35 | + $this->_extensions = array(); |
|
| 36 | + foreach ($extensions as $ext) { |
|
| 37 | + $this->_extensions[$ext->oid()] = $ext; |
|
| 38 | + } |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * Initialize from ASN.1. |
|
| 43 | + * |
|
| 44 | + * @param Sequence $seq |
|
| 45 | + * @return self |
|
| 46 | + */ |
|
| 47 | + public static function fromASN1(Sequence $seq): self |
|
| 48 | + { |
|
| 49 | + $extensions = array_map( |
|
| 50 | + function (UnspecifiedType $el) { |
|
| 51 | + return Ext\Extension::fromASN1($el->asSequence()); |
|
| 52 | + }, $seq->elements()); |
|
| 53 | + return new self(...$extensions); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Generate ASN.1 structure. |
|
| 58 | + * |
|
| 59 | + * @return Sequence |
|
| 60 | + */ |
|
| 61 | + public function toASN1(): Sequence |
|
| 62 | + { |
|
| 63 | + $elements = array_values( |
|
| 64 | + array_map( |
|
| 65 | + function ($ext) { |
|
| 66 | + return $ext->toASN1(); |
|
| 67 | + }, $this->_extensions)); |
|
| 68 | + return new Sequence(...$elements); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Get self with extensions added. |
|
| 73 | + * |
|
| 74 | + * @param Ext\Extension ...$exts One or more extensions to add |
|
| 75 | + * @return self |
|
| 76 | + */ |
|
| 77 | + public function withExtensions(Ext\Extension ...$exts): self |
|
| 78 | + { |
|
| 79 | + $obj = clone $this; |
|
| 80 | + foreach ($exts as $ext) { |
|
| 81 | + $obj->_extensions[$ext->oid()] = $ext; |
|
| 82 | + } |
|
| 83 | + return $obj; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Check whether extension is present. |
|
| 88 | + * |
|
| 89 | + * @param string $oid Extensions OID |
|
| 90 | + * @return bool |
|
| 91 | + */ |
|
| 92 | + public function has(string $oid): bool |
|
| 93 | + { |
|
| 94 | + return isset($this->_extensions[$oid]); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * Get extension by OID. |
|
| 99 | + * |
|
| 100 | + * @param string $oid |
|
| 101 | + * @throws \LogicException If extension is not present |
|
| 102 | + * @return Extension\Extension |
|
| 103 | + */ |
|
| 104 | + public function get(string $oid): Ext\Extension |
|
| 105 | + { |
|
| 106 | + if (!$this->has($oid)) { |
|
| 107 | + throw new \LogicException("No extension by OID $oid."); |
|
| 108 | + } |
|
| 109 | + return $this->_extensions[$oid]; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Check whether 'Authority Key Identifier' extension is present. |
|
| 114 | + * |
|
| 115 | + * @return bool |
|
| 116 | + */ |
|
| 117 | + public function hasAuthorityKeyIdentifier(): bool |
|
| 118 | + { |
|
| 119 | + return $this->has(Ext\Extension::OID_AUTHORITY_KEY_IDENTIFIER); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Get 'Authority Key Identifier' extension. |
|
| 124 | + * |
|
| 125 | + * @throws \LogicException If extension is not present |
|
| 126 | + * @return \X509\Certificate\Extension\AuthorityKeyIdentifierExtension |
|
| 127 | + */ |
|
| 128 | + public function authorityKeyIdentifier(): Ext\AuthorityKeyIdentifierExtension |
|
| 129 | + { |
|
| 130 | + /** @var Extension\AuthorityKeyIdentifierExtension $keyIdentifier */ |
|
| 131 | + $keyIdentifier = $this->get(Ext\Extension::OID_AUTHORITY_KEY_IDENTIFIER); |
|
| 132 | + return $keyIdentifier; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Check whether 'Subject Key Identifier' extension is present. |
|
| 137 | + * |
|
| 138 | + * @return bool |
|
| 139 | + */ |
|
| 140 | + public function hasSubjectKeyIdentifier(): bool |
|
| 141 | + { |
|
| 142 | + return $this->has(Ext\Extension::OID_SUBJECT_KEY_IDENTIFIER); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * Get 'Subject Key Identifier' extension. |
|
| 147 | + * |
|
| 148 | + * @throws \LogicException If extension is not present |
|
| 149 | + * @return \X509\Certificate\Extension\SubjectKeyIdentifierExtension |
|
| 150 | + */ |
|
| 151 | + public function subjectKeyIdentifier(): Ext\SubjectKeyIdentifierExtension |
|
| 152 | + { |
|
| 153 | + /** @var Extension\SubjectKeyIdentifierExtension $subjectKeyIdentifier */ |
|
| 154 | + $subjectKeyIdentifier = $this->get( |
|
| 155 | + Ext\Extension::OID_SUBJECT_KEY_IDENTIFIER); |
|
| 156 | + return $subjectKeyIdentifier; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * Check whether 'Key Usage' extension is present. |
|
| 161 | + * |
|
| 162 | + * @return bool |
|
| 163 | + */ |
|
| 164 | + public function hasKeyUsage(): bool |
|
| 165 | + { |
|
| 166 | + return $this->has(Ext\Extension::OID_KEY_USAGE); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * Get 'Key Usage' extension. |
|
| 171 | + * |
|
| 172 | + * @throws \LogicException If extension is not present |
|
| 173 | + * @return \X509\Certificate\Extension\KeyUsageExtension |
|
| 174 | + */ |
|
| 175 | + public function keyUsage(): Ext\KeyUsageExtension |
|
| 176 | + { |
|
| 177 | + /** @var Extension\KeyUsageExtension $keyUsage */ |
|
| 178 | + $keyUsage = $this->get(Ext\Extension::OID_KEY_USAGE); |
|
| 179 | + return $keyUsage; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * Check whether 'Certificate Policies' extension is present. |
|
| 184 | + * |
|
| 185 | + * @return bool |
|
| 186 | + */ |
|
| 187 | + public function hasCertificatePolicies(): bool |
|
| 188 | + { |
|
| 189 | + return $this->has(Ext\Extension::OID_CERTIFICATE_POLICIES); |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * Get 'Certificate Policies' extension. |
|
| 194 | + * |
|
| 195 | + * @throws \LogicException If extension is not present |
|
| 196 | + * @return \X509\Certificate\Extension\CertificatePoliciesExtension |
|
| 197 | + */ |
|
| 198 | + public function certificatePolicies(): Ext\CertificatePoliciesExtension |
|
| 199 | + { |
|
| 200 | + /** @var Extension\CertificatePoliciesExtension $certPolicies */ |
|
| 201 | + $certPolicies = $this->get(Ext\Extension::OID_CERTIFICATE_POLICIES); |
|
| 202 | + return $certPolicies; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * Check whether 'Policy Mappings' extension is present. |
|
| 207 | + * |
|
| 208 | + * @return bool |
|
| 209 | + */ |
|
| 210 | + public function hasPolicyMappings(): bool |
|
| 211 | + { |
|
| 212 | + return $this->has(Ext\Extension::OID_POLICY_MAPPINGS); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * Get 'Policy Mappings' extension. |
|
| 217 | + * |
|
| 218 | + * @throws \LogicException If extension is not present |
|
| 219 | + * @return \X509\Certificate\Extension\PolicyMappingsExtension |
|
| 220 | + */ |
|
| 221 | + public function policyMappings(): Ext\PolicyMappingsExtension |
|
| 222 | + { |
|
| 223 | + /** @var Extension\PolicyMappingsExtension $policyMappings */ |
|
| 224 | + $policyMappings = $this->get(Ext\Extension::OID_POLICY_MAPPINGS); |
|
| 225 | + return $policyMappings; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * Check whether 'Subject Alternative Name' extension is present. |
|
| 230 | + * |
|
| 231 | + * @return bool |
|
| 232 | + */ |
|
| 233 | + public function hasSubjectAlternativeName(): bool |
|
| 234 | + { |
|
| 235 | + return $this->has(Ext\Extension::OID_SUBJECT_ALT_NAME); |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * Get 'Subject Alternative Name' extension. |
|
| 240 | + * |
|
| 241 | + * @throws \LogicException If extension is not present |
|
| 242 | + * @return \X509\Certificate\Extension\SubjectAlternativeNameExtension |
|
| 243 | + */ |
|
| 244 | + public function subjectAlternativeName(): Ext\SubjectAlternativeNameExtension |
|
| 245 | + { |
|
| 246 | + /** @var Extension\SubjectAlternativeNameExtension $subjectAltName */ |
|
| 247 | + $subjectAltName = $this->get(Ext\Extension::OID_SUBJECT_ALT_NAME); |
|
| 248 | + return $subjectAltName; |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * Check whether 'Issuer Alternative Name' extension is present. |
|
| 253 | + * |
|
| 254 | + * @return bool |
|
| 255 | + */ |
|
| 256 | + public function hasIssuerAlternativeName(): bool |
|
| 257 | + { |
|
| 258 | + return $this->has(Ext\Extension::OID_ISSUER_ALT_NAME); |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * Get 'Issuer Alternative Name' extension. |
|
| 263 | + * |
|
| 264 | + * @return \X509\Certificate\Extension\IssuerAlternativeNameExtension |
|
| 265 | + */ |
|
| 266 | + public function issuerAlternativeName(): Ext\IssuerAlternativeNameExtension |
|
| 267 | + { |
|
| 268 | + /** @var Extension\IssuerAlternativeNameExtension $issuerAltName */ |
|
| 269 | + $issuerAltName = $this->get(Ext\Extension::OID_ISSUER_ALT_NAME); |
|
| 270 | + return $issuerAltName; |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + /** |
|
| 274 | + * Check whether 'Basic Constraints' extension is present. |
|
| 275 | + * |
|
| 276 | + * @return bool |
|
| 277 | + */ |
|
| 278 | + public function hasBasicConstraints(): bool |
|
| 279 | + { |
|
| 280 | + return $this->has(Ext\Extension::OID_BASIC_CONSTRAINTS); |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + /** |
|
| 284 | + * Get 'Basic Constraints' extension. |
|
| 285 | + * |
|
| 286 | + * @throws \LogicException If extension is not present |
|
| 287 | + * @return \X509\Certificate\Extension\BasicConstraintsExtension |
|
| 288 | + */ |
|
| 289 | + public function basicConstraints(): Ext\BasicConstraintsExtension |
|
| 290 | + { |
|
| 291 | + /** @var Extension\BasicConstraintsExtension $basicConstraints */ |
|
| 292 | + $basicConstraints = $this->get(Ext\Extension::OID_BASIC_CONSTRAINTS); |
|
| 293 | + return $basicConstraints; |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + /** |
|
| 297 | + * Check whether 'Name Constraints' extension is present. |
|
| 298 | + * |
|
| 299 | + * @return bool |
|
| 300 | + */ |
|
| 301 | + public function hasNameConstraints(): bool |
|
| 302 | + { |
|
| 303 | + return $this->has(Ext\Extension::OID_NAME_CONSTRAINTS); |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * Get 'Name Constraints' extension. |
|
| 308 | + * |
|
| 309 | + * @throws \LogicException If extension is not present |
|
| 310 | + * @return \X509\Certificate\Extension\NameConstraintsExtension |
|
| 311 | + */ |
|
| 312 | + public function nameConstraints(): Ext\NameConstraintsExtension |
|
| 313 | + { |
|
| 314 | + /** @var Extension\NameConstraintsExtension $nameConstraints */ |
|
| 315 | + $nameConstraints = $this->get(Ext\Extension::OID_NAME_CONSTRAINTS); |
|
| 316 | + return $nameConstraints; |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + /** |
|
| 320 | + * Check whether 'Policy Constraints' extension is present. |
|
| 321 | + * |
|
| 322 | + * @return bool |
|
| 323 | + */ |
|
| 324 | + public function hasPolicyConstraints(): bool |
|
| 325 | + { |
|
| 326 | + return $this->has(Ext\Extension::OID_POLICY_CONSTRAINTS); |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + /** |
|
| 330 | + * Get 'Policy Constraints' extension. |
|
| 331 | + * |
|
| 332 | + * @throws \LogicException If extension is not present |
|
| 333 | + * @return \X509\Certificate\Extension\PolicyConstraintsExtension |
|
| 334 | + */ |
|
| 335 | + public function policyConstraints(): Ext\PolicyConstraintsExtension |
|
| 336 | + { |
|
| 337 | + /** @var Extension\PolicyConstraintsExtension $policyConstraints */ |
|
| 338 | + $policyConstraints = $this->get(Ext\Extension::OID_POLICY_CONSTRAINTS); |
|
| 339 | + return $policyConstraints; |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + /** |
|
| 343 | + * Check whether 'Extended Key Usage' extension is present. |
|
| 344 | + * |
|
| 345 | + * @return bool |
|
| 346 | + */ |
|
| 347 | + public function hasExtendedKeyUsage(): bool |
|
| 348 | + { |
|
| 349 | + return $this->has(Ext\Extension::OID_EXT_KEY_USAGE); |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * Get 'Extended Key Usage' extension. |
|
| 354 | + * |
|
| 355 | + * @throws \LogicException If extension is not present |
|
| 356 | + * @return \X509\Certificate\Extension\ExtendedKeyUsageExtension |
|
| 357 | + */ |
|
| 358 | + public function extendedKeyUsage(): Ext\ExtendedKeyUsageExtension |
|
| 359 | + { |
|
| 360 | + /** @var Extension\ExtendedKeyUsageExtension $keyUsage */ |
|
| 361 | + $keyUsage = $this->get(Ext\Extension::OID_EXT_KEY_USAGE); |
|
| 362 | + return $keyUsage; |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + /** |
|
| 366 | + * Check whether 'CRL Distribution Points' extension is present. |
|
| 367 | + * |
|
| 368 | + * @return bool |
|
| 369 | + */ |
|
| 370 | + public function hasCRLDistributionPoints(): bool |
|
| 371 | + { |
|
| 372 | + return $this->has(Ext\Extension::OID_CRL_DISTRIBUTION_POINTS); |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + /** |
|
| 376 | + * Get 'CRL Distribution Points' extension. |
|
| 377 | + * |
|
| 378 | + * @throws \LogicException If extension is not present |
|
| 379 | + * @return \X509\Certificate\Extension\CRLDistributionPointsExtension |
|
| 380 | + */ |
|
| 381 | + public function crlDistributionPoints(): Ext\CRLDistributionPointsExtension |
|
| 382 | + { |
|
| 383 | + /** @var Extension\CRLDistributionPointsExtension $crlDist */ |
|
| 384 | + $crlDist = $this->get(Ext\Extension::OID_CRL_DISTRIBUTION_POINTS); |
|
| 385 | + return $crlDist; |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + /** |
|
| 389 | + * Check whether 'Inhibit anyPolicy' extension is present. |
|
| 390 | + * |
|
| 391 | + * @return bool |
|
| 392 | + */ |
|
| 393 | + public function hasInhibitAnyPolicy(): bool |
|
| 394 | + { |
|
| 395 | + return $this->has(Ext\Extension::OID_INHIBIT_ANY_POLICY); |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + /** |
|
| 399 | + * Get 'Inhibit anyPolicy' extension. |
|
| 400 | + * |
|
| 401 | + * @throws \LogicException If extension is not present |
|
| 402 | + * @return \X509\Certificate\Extension\InhibitAnyPolicyExtension |
|
| 403 | + */ |
|
| 404 | + public function inhibitAnyPolicy(): Ext\InhibitAnyPolicyExtension |
|
| 405 | + { |
|
| 406 | + /** @var Extension\InhibitAnyPolicyExtension $inhibitAny */ |
|
| 407 | + $inhibitAny = $this->get(Ext\Extension::OID_INHIBIT_ANY_POLICY); |
|
| 408 | + return $inhibitAny; |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + /** |
|
| 412 | + * |
|
| 413 | + * @see \Countable::count() |
|
| 414 | + * @return int |
|
| 415 | + */ |
|
| 416 | + public function count(): int |
|
| 417 | + { |
|
| 418 | + return count($this->_extensions); |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + /** |
|
| 422 | + * Get iterator for extensions. |
|
| 423 | + * |
|
| 424 | + * @see \IteratorAggregate::getIterator() |
|
| 425 | + * @return \Traversable |
|
| 426 | + */ |
|
| 427 | + public function getIterator(): \Traversable |
|
| 428 | + { |
|
| 429 | + return new \ArrayIterator($this->_extensions); |
|
| 430 | + } |
|
| 431 | 431 | } |
@@ -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 = array( |
|
| 39 | - /* @formatter:off */ |
|
| 40 | - AccessIdentityAttributeValue::OID => AccessIdentityAttributeValue::class, |
|
| 41 | - AuthenticationInfoAttributeValue::OID => AuthenticationInfoAttributeValue::class, |
|
| 42 | - ChargingIdentityAttributeValue::OID => ChargingIdentityAttributeValue::class, |
|
| 43 | - GroupAttributeValue::OID => GroupAttributeValue::class, |
|
| 44 | - AttributeType::OID_ROLE => RoleAttributeValue::class |
|
| 45 | - /* @formatter:on */ |
|
| 46 | - ); |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * Constructor. |
|
| 50 | - * |
|
| 51 | - * @param Attribute ...$attribs |
|
| 52 | - */ |
|
| 53 | - public function __construct(Attribute ...$attribs) |
|
| 54 | - { |
|
| 55 | - $this->_attributes = $attribs; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Initialize from attribute values. |
|
| 60 | - * |
|
| 61 | - * @param AttributeValue ...$values |
|
| 62 | - * @return self |
|
| 63 | - */ |
|
| 64 | - public static function fromAttributeValues(AttributeValue ...$values): self |
|
| 65 | - { |
|
| 66 | - $attribs = array_map( |
|
| 67 | - function (AttributeValue $value) { |
|
| 68 | - return $value->toAttribute(); |
|
| 69 | - }, $values); |
|
| 70 | - return new self(...$attribs); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * Initialize from ASN.1. |
|
| 75 | - * |
|
| 76 | - * @param Sequence $seq |
|
| 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(array(), |
|
| 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 = array( |
|
| 39 | + /* @formatter:off */ |
|
| 40 | + AccessIdentityAttributeValue::OID => AccessIdentityAttributeValue::class, |
|
| 41 | + AuthenticationInfoAttributeValue::OID => AuthenticationInfoAttributeValue::class, |
|
| 42 | + ChargingIdentityAttributeValue::OID => ChargingIdentityAttributeValue::class, |
|
| 43 | + GroupAttributeValue::OID => GroupAttributeValue::class, |
|
| 44 | + AttributeType::OID_ROLE => RoleAttributeValue::class |
|
| 45 | + /* @formatter:on */ |
|
| 46 | + ); |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * Constructor. |
|
| 50 | + * |
|
| 51 | + * @param Attribute ...$attribs |
|
| 52 | + */ |
|
| 53 | + public function __construct(Attribute ...$attribs) |
|
| 54 | + { |
|
| 55 | + $this->_attributes = $attribs; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Initialize from attribute values. |
|
| 60 | + * |
|
| 61 | + * @param AttributeValue ...$values |
|
| 62 | + * @return self |
|
| 63 | + */ |
|
| 64 | + public static function fromAttributeValues(AttributeValue ...$values): self |
|
| 65 | + { |
|
| 66 | + $attribs = array_map( |
|
| 67 | + function (AttributeValue $value) { |
|
| 68 | + return $value->toAttribute(); |
|
| 69 | + }, $values); |
|
| 70 | + return new self(...$attribs); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * Initialize from ASN.1. |
|
| 75 | + * |
|
| 76 | + * @param Sequence $seq |
|
| 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(array(), |
|
| 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 | } |