@@ -18,172 +18,172 @@ |
||
18 | 18 | */ |
19 | 19 | class CertificationRequest |
20 | 20 | { |
21 | - /** |
|
22 | - * Certification request info. |
|
23 | - * |
|
24 | - * @var CertificationRequestInfo $_certificationRequestInfo |
|
25 | - */ |
|
26 | - protected $_certificationRequestInfo; |
|
21 | + /** |
|
22 | + * Certification request info. |
|
23 | + * |
|
24 | + * @var CertificationRequestInfo $_certificationRequestInfo |
|
25 | + */ |
|
26 | + protected $_certificationRequestInfo; |
|
27 | 27 | |
28 | - /** |
|
29 | - * Signature algorithm. |
|
30 | - * |
|
31 | - * @var SignatureAlgorithmIdentifier $_signatureAlgorithm |
|
32 | - */ |
|
33 | - protected $_signatureAlgorithm; |
|
28 | + /** |
|
29 | + * Signature algorithm. |
|
30 | + * |
|
31 | + * @var SignatureAlgorithmIdentifier $_signatureAlgorithm |
|
32 | + */ |
|
33 | + protected $_signatureAlgorithm; |
|
34 | 34 | |
35 | - /** |
|
36 | - * Signature. |
|
37 | - * |
|
38 | - * @var Signature $_signature |
|
39 | - */ |
|
40 | - protected $_signature; |
|
35 | + /** |
|
36 | + * Signature. |
|
37 | + * |
|
38 | + * @var Signature $_signature |
|
39 | + */ |
|
40 | + protected $_signature; |
|
41 | 41 | |
42 | - /** |
|
43 | - * Constructor. |
|
44 | - * |
|
45 | - * @param CertificationRequestInfo $info |
|
46 | - * @param SignatureAlgorithmIdentifier $algo |
|
47 | - * @param Signature $signature |
|
48 | - */ |
|
49 | - public function __construct(CertificationRequestInfo $info, |
|
50 | - SignatureAlgorithmIdentifier $algo, Signature $signature) |
|
51 | - { |
|
52 | - $this->_certificationRequestInfo = $info; |
|
53 | - $this->_signatureAlgorithm = $algo; |
|
54 | - $this->_signature = $signature; |
|
55 | - } |
|
42 | + /** |
|
43 | + * Constructor. |
|
44 | + * |
|
45 | + * @param CertificationRequestInfo $info |
|
46 | + * @param SignatureAlgorithmIdentifier $algo |
|
47 | + * @param Signature $signature |
|
48 | + */ |
|
49 | + public function __construct(CertificationRequestInfo $info, |
|
50 | + SignatureAlgorithmIdentifier $algo, Signature $signature) |
|
51 | + { |
|
52 | + $this->_certificationRequestInfo = $info; |
|
53 | + $this->_signatureAlgorithm = $algo; |
|
54 | + $this->_signature = $signature; |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Initialize from ASN.1. |
|
59 | - * |
|
60 | - * @param Sequence $seq |
|
61 | - * @return self |
|
62 | - */ |
|
63 | - public static function fromASN1(Sequence $seq): self |
|
64 | - { |
|
65 | - $info = CertificationRequestInfo::fromASN1($seq->at(0)->asSequence()); |
|
66 | - $algo = AlgorithmIdentifier::fromASN1($seq->at(1)->asSequence()); |
|
67 | - if (!$algo instanceof SignatureAlgorithmIdentifier) { |
|
68 | - throw new \UnexpectedValueException( |
|
69 | - "Unsupported signature algorithm " . $algo->oid() . "."); |
|
70 | - } |
|
71 | - $signature = Signature::fromSignatureData( |
|
72 | - $seq->at(2) |
|
73 | - ->asBitString() |
|
74 | - ->string(), $algo); |
|
75 | - return new self($info, $algo, $signature); |
|
76 | - } |
|
57 | + /** |
|
58 | + * Initialize from ASN.1. |
|
59 | + * |
|
60 | + * @param Sequence $seq |
|
61 | + * @return self |
|
62 | + */ |
|
63 | + public static function fromASN1(Sequence $seq): self |
|
64 | + { |
|
65 | + $info = CertificationRequestInfo::fromASN1($seq->at(0)->asSequence()); |
|
66 | + $algo = AlgorithmIdentifier::fromASN1($seq->at(1)->asSequence()); |
|
67 | + if (!$algo instanceof SignatureAlgorithmIdentifier) { |
|
68 | + throw new \UnexpectedValueException( |
|
69 | + "Unsupported signature algorithm " . $algo->oid() . "."); |
|
70 | + } |
|
71 | + $signature = Signature::fromSignatureData( |
|
72 | + $seq->at(2) |
|
73 | + ->asBitString() |
|
74 | + ->string(), $algo); |
|
75 | + return new self($info, $algo, $signature); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * Initialize from DER. |
|
80 | - * |
|
81 | - * @param string $data |
|
82 | - * @return self |
|
83 | - */ |
|
84 | - public static function fromDER(string $data): self |
|
85 | - { |
|
86 | - return self::fromASN1(Sequence::fromDER($data)); |
|
87 | - } |
|
78 | + /** |
|
79 | + * Initialize from DER. |
|
80 | + * |
|
81 | + * @param string $data |
|
82 | + * @return self |
|
83 | + */ |
|
84 | + public static function fromDER(string $data): self |
|
85 | + { |
|
86 | + return self::fromASN1(Sequence::fromDER($data)); |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * Initialize from PEM. |
|
91 | - * |
|
92 | - * @param PEM $pem |
|
93 | - * @throws \UnexpectedValueException |
|
94 | - * @return self |
|
95 | - */ |
|
96 | - public static function fromPEM(PEM $pem): self |
|
97 | - { |
|
98 | - if ($pem->type() !== PEM::TYPE_CERTIFICATE_REQUEST) { |
|
99 | - throw new \UnexpectedValueException("Invalid PEM type."); |
|
100 | - } |
|
101 | - return self::fromDER($pem->data()); |
|
102 | - } |
|
89 | + /** |
|
90 | + * Initialize from PEM. |
|
91 | + * |
|
92 | + * @param PEM $pem |
|
93 | + * @throws \UnexpectedValueException |
|
94 | + * @return self |
|
95 | + */ |
|
96 | + public static function fromPEM(PEM $pem): self |
|
97 | + { |
|
98 | + if ($pem->type() !== PEM::TYPE_CERTIFICATE_REQUEST) { |
|
99 | + throw new \UnexpectedValueException("Invalid PEM type."); |
|
100 | + } |
|
101 | + return self::fromDER($pem->data()); |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * Get certification request info. |
|
106 | - * |
|
107 | - * @return CertificationRequestInfo |
|
108 | - */ |
|
109 | - public function certificationRequestInfo(): CertificationRequestInfo |
|
110 | - { |
|
111 | - return $this->_certificationRequestInfo; |
|
112 | - } |
|
104 | + /** |
|
105 | + * Get certification request info. |
|
106 | + * |
|
107 | + * @return CertificationRequestInfo |
|
108 | + */ |
|
109 | + public function certificationRequestInfo(): CertificationRequestInfo |
|
110 | + { |
|
111 | + return $this->_certificationRequestInfo; |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * Get signature algorithm. |
|
116 | - * |
|
117 | - * @return SignatureAlgorithmIdentifier |
|
118 | - */ |
|
119 | - public function signatureAlgorithm(): SignatureAlgorithmIdentifier |
|
120 | - { |
|
121 | - return $this->_signatureAlgorithm; |
|
122 | - } |
|
114 | + /** |
|
115 | + * Get signature algorithm. |
|
116 | + * |
|
117 | + * @return SignatureAlgorithmIdentifier |
|
118 | + */ |
|
119 | + public function signatureAlgorithm(): SignatureAlgorithmIdentifier |
|
120 | + { |
|
121 | + return $this->_signatureAlgorithm; |
|
122 | + } |
|
123 | 123 | |
124 | - /** |
|
125 | - * Get signature. |
|
126 | - * |
|
127 | - * @return Signature |
|
128 | - */ |
|
129 | - public function signature(): Signature |
|
130 | - { |
|
131 | - return $this->_signature; |
|
132 | - } |
|
124 | + /** |
|
125 | + * Get signature. |
|
126 | + * |
|
127 | + * @return Signature |
|
128 | + */ |
|
129 | + public function signature(): Signature |
|
130 | + { |
|
131 | + return $this->_signature; |
|
132 | + } |
|
133 | 133 | |
134 | - /** |
|
135 | - * Generate ASN.1 structure. |
|
136 | - * |
|
137 | - * @return Sequence |
|
138 | - */ |
|
139 | - public function toASN1(): Sequence |
|
140 | - { |
|
141 | - return new Sequence($this->_certificationRequestInfo->toASN1(), |
|
142 | - $this->_signatureAlgorithm->toASN1(), $this->_signature->bitString()); |
|
143 | - } |
|
134 | + /** |
|
135 | + * Generate ASN.1 structure. |
|
136 | + * |
|
137 | + * @return Sequence |
|
138 | + */ |
|
139 | + public function toASN1(): Sequence |
|
140 | + { |
|
141 | + return new Sequence($this->_certificationRequestInfo->toASN1(), |
|
142 | + $this->_signatureAlgorithm->toASN1(), $this->_signature->bitString()); |
|
143 | + } |
|
144 | 144 | |
145 | - /** |
|
146 | - * Get certification request as a DER. |
|
147 | - * |
|
148 | - * @return string |
|
149 | - */ |
|
150 | - public function toDER(): string |
|
151 | - { |
|
152 | - return $this->toASN1()->toDER(); |
|
153 | - } |
|
145 | + /** |
|
146 | + * Get certification request as a DER. |
|
147 | + * |
|
148 | + * @return string |
|
149 | + */ |
|
150 | + public function toDER(): string |
|
151 | + { |
|
152 | + return $this->toASN1()->toDER(); |
|
153 | + } |
|
154 | 154 | |
155 | - /** |
|
156 | - * Get certification request as a PEM. |
|
157 | - * |
|
158 | - * @return PEM |
|
159 | - */ |
|
160 | - public function toPEM(): PEM |
|
161 | - { |
|
162 | - return new PEM(PEM::TYPE_CERTIFICATE_REQUEST, $this->toDER()); |
|
163 | - } |
|
155 | + /** |
|
156 | + * Get certification request as a PEM. |
|
157 | + * |
|
158 | + * @return PEM |
|
159 | + */ |
|
160 | + public function toPEM(): PEM |
|
161 | + { |
|
162 | + return new PEM(PEM::TYPE_CERTIFICATE_REQUEST, $this->toDER()); |
|
163 | + } |
|
164 | 164 | |
165 | - /** |
|
166 | - * Verify certification request signature. |
|
167 | - * |
|
168 | - * @param Crypto|null $crypto Crypto engine, use default if not set |
|
169 | - * @return bool True if signature matches |
|
170 | - */ |
|
171 | - public function verify(Crypto $crypto = null): bool |
|
172 | - { |
|
173 | - $crypto = $crypto ?: Crypto::getDefault(); |
|
174 | - $data = $this->_certificationRequestInfo->toASN1()->toDER(); |
|
175 | - $pk_info = $this->_certificationRequestInfo->subjectPKInfo(); |
|
176 | - return $crypto->verify($data, $this->_signature, $pk_info, |
|
177 | - $this->_signatureAlgorithm); |
|
178 | - } |
|
165 | + /** |
|
166 | + * Verify certification request signature. |
|
167 | + * |
|
168 | + * @param Crypto|null $crypto Crypto engine, use default if not set |
|
169 | + * @return bool True if signature matches |
|
170 | + */ |
|
171 | + public function verify(Crypto $crypto = null): bool |
|
172 | + { |
|
173 | + $crypto = $crypto ?: Crypto::getDefault(); |
|
174 | + $data = $this->_certificationRequestInfo->toASN1()->toDER(); |
|
175 | + $pk_info = $this->_certificationRequestInfo->subjectPKInfo(); |
|
176 | + return $crypto->verify($data, $this->_signature, $pk_info, |
|
177 | + $this->_signatureAlgorithm); |
|
178 | + } |
|
179 | 179 | |
180 | - /** |
|
181 | - * Get certification request as a PEM formatted string. |
|
182 | - * |
|
183 | - * @return string |
|
184 | - */ |
|
185 | - public function __toString() |
|
186 | - { |
|
187 | - return $this->toPEM()->string(); |
|
188 | - } |
|
180 | + /** |
|
181 | + * Get certification request as a PEM formatted string. |
|
182 | + * |
|
183 | + * @return string |
|
184 | + */ |
|
185 | + public function __toString() |
|
186 | + { |
|
187 | + return $this->toPEM()->string(); |
|
188 | + } |
|
189 | 189 | } |
@@ -17,94 +17,94 @@ |
||
17 | 17 | */ |
18 | 18 | class ExtensionRequestValue extends AttributeValue |
19 | 19 | { |
20 | - const OID = "1.2.840.113549.1.9.14"; |
|
20 | + const OID = "1.2.840.113549.1.9.14"; |
|
21 | 21 | |
22 | - /** |
|
23 | - * Extensions. |
|
24 | - * |
|
25 | - * @var Extensions $_extensions |
|
26 | - */ |
|
27 | - protected $_extensions; |
|
22 | + /** |
|
23 | + * Extensions. |
|
24 | + * |
|
25 | + * @var Extensions $_extensions |
|
26 | + */ |
|
27 | + protected $_extensions; |
|
28 | 28 | |
29 | - /** |
|
30 | - * Constructor. |
|
31 | - * |
|
32 | - * @param Extensions $extensions |
|
33 | - */ |
|
34 | - public function __construct(Extensions $extensions) |
|
35 | - { |
|
36 | - $this->_extensions = $extensions; |
|
37 | - $this->_oid = self::OID; |
|
38 | - } |
|
29 | + /** |
|
30 | + * Constructor. |
|
31 | + * |
|
32 | + * @param Extensions $extensions |
|
33 | + */ |
|
34 | + public function __construct(Extensions $extensions) |
|
35 | + { |
|
36 | + $this->_extensions = $extensions; |
|
37 | + $this->_oid = self::OID; |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * |
|
42 | - * @see \X501\ASN1\AttributeValue\AttributeValue::fromASN1() |
|
43 | - * @param UnspecifiedType $el |
|
44 | - * @return self |
|
45 | - */ |
|
46 | - public static function fromASN1(UnspecifiedType $el): self |
|
47 | - { |
|
48 | - return new self(Extensions::fromASN1($el->asSequence())); |
|
49 | - } |
|
40 | + /** |
|
41 | + * |
|
42 | + * @see \X501\ASN1\AttributeValue\AttributeValue::fromASN1() |
|
43 | + * @param UnspecifiedType $el |
|
44 | + * @return self |
|
45 | + */ |
|
46 | + public static function fromASN1(UnspecifiedType $el): self |
|
47 | + { |
|
48 | + return new self(Extensions::fromASN1($el->asSequence())); |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * Get requested extensions. |
|
53 | - * |
|
54 | - * @return Extensions |
|
55 | - */ |
|
56 | - public function extensions(): Extensions |
|
57 | - { |
|
58 | - return $this->_extensions; |
|
59 | - } |
|
51 | + /** |
|
52 | + * Get requested extensions. |
|
53 | + * |
|
54 | + * @return Extensions |
|
55 | + */ |
|
56 | + public function extensions(): Extensions |
|
57 | + { |
|
58 | + return $this->_extensions; |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * |
|
63 | - * @see \X501\ASN1\AttributeValue\AttributeValue::toASN1() |
|
64 | - * @return Sequence |
|
65 | - */ |
|
66 | - public function toASN1(): Sequence |
|
67 | - { |
|
68 | - return $this->_extensions->toASN1(); |
|
69 | - } |
|
61 | + /** |
|
62 | + * |
|
63 | + * @see \X501\ASN1\AttributeValue\AttributeValue::toASN1() |
|
64 | + * @return Sequence |
|
65 | + */ |
|
66 | + public function toASN1(): Sequence |
|
67 | + { |
|
68 | + return $this->_extensions->toASN1(); |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * |
|
73 | - * @see \X501\ASN1\AttributeValue\AttributeValue::stringValue() |
|
74 | - * @return string |
|
75 | - */ |
|
76 | - public function stringValue(): string |
|
77 | - { |
|
78 | - return "#" . bin2hex($this->toASN1()->toDER()); |
|
79 | - } |
|
71 | + /** |
|
72 | + * |
|
73 | + * @see \X501\ASN1\AttributeValue\AttributeValue::stringValue() |
|
74 | + * @return string |
|
75 | + */ |
|
76 | + public function stringValue(): string |
|
77 | + { |
|
78 | + return "#" . bin2hex($this->toASN1()->toDER()); |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * |
|
83 | - * @see \X501\ASN1\AttributeValue\AttributeValue::equalityMatchingRule() |
|
84 | - * @return BinaryMatch |
|
85 | - */ |
|
86 | - public function equalityMatchingRule(): BinaryMatch |
|
87 | - { |
|
88 | - return new BinaryMatch(); |
|
89 | - } |
|
81 | + /** |
|
82 | + * |
|
83 | + * @see \X501\ASN1\AttributeValue\AttributeValue::equalityMatchingRule() |
|
84 | + * @return BinaryMatch |
|
85 | + */ |
|
86 | + public function equalityMatchingRule(): BinaryMatch |
|
87 | + { |
|
88 | + return new BinaryMatch(); |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * |
|
93 | - * @see \X501\ASN1\AttributeValue\AttributeValue::rfc2253String() |
|
94 | - * @return string |
|
95 | - */ |
|
96 | - public function rfc2253String(): string |
|
97 | - { |
|
98 | - return $this->stringValue(); |
|
99 | - } |
|
91 | + /** |
|
92 | + * |
|
93 | + * @see \X501\ASN1\AttributeValue\AttributeValue::rfc2253String() |
|
94 | + * @return string |
|
95 | + */ |
|
96 | + public function rfc2253String(): string |
|
97 | + { |
|
98 | + return $this->stringValue(); |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * |
|
103 | - * @see \X501\ASN1\AttributeValue\AttributeValue::_transcodedString() |
|
104 | - * @return string |
|
105 | - */ |
|
106 | - protected function _transcodedString(): string |
|
107 | - { |
|
108 | - return $this->stringValue(); |
|
109 | - } |
|
101 | + /** |
|
102 | + * |
|
103 | + * @see \X501\ASN1\AttributeValue\AttributeValue::_transcodedString() |
|
104 | + * @return string |
|
105 | + */ |
|
106 | + protected function _transcodedString(): string |
|
107 | + { |
|
108 | + return $this->stringValue(); |
|
109 | + } |
|
110 | 110 | } |
@@ -20,107 +20,107 @@ |
||
20 | 20 | */ |
21 | 21 | class Attributes implements \Countable, \IteratorAggregate |
22 | 22 | { |
23 | - use AttributeContainer; |
|
23 | + use AttributeContainer; |
|
24 | 24 | |
25 | - /** |
|
26 | - * Mapping from OID to attribute value class name. |
|
27 | - * |
|
28 | - * @internal |
|
29 | - * |
|
30 | - * @var array |
|
31 | - */ |
|
32 | - const MAP_OID_TO_CLASS = array( |
|
33 | - /* @formatter:off */ |
|
34 | - ExtensionRequestValue::OID => ExtensionRequestValue::class |
|
35 | - /* @formatter:on */ |
|
36 | - ); |
|
25 | + /** |
|
26 | + * Mapping from OID to attribute value class name. |
|
27 | + * |
|
28 | + * @internal |
|
29 | + * |
|
30 | + * @var array |
|
31 | + */ |
|
32 | + const MAP_OID_TO_CLASS = array( |
|
33 | + /* @formatter:off */ |
|
34 | + ExtensionRequestValue::OID => ExtensionRequestValue::class |
|
35 | + /* @formatter:on */ |
|
36 | + ); |
|
37 | 37 | |
38 | - /** |
|
39 | - * Constructor. |
|
40 | - * |
|
41 | - * @param Attribute ...$attribs Attribute objects |
|
42 | - */ |
|
43 | - public function __construct(Attribute ...$attribs) |
|
44 | - { |
|
45 | - $this->_attributes = $attribs; |
|
46 | - } |
|
38 | + /** |
|
39 | + * Constructor. |
|
40 | + * |
|
41 | + * @param Attribute ...$attribs Attribute objects |
|
42 | + */ |
|
43 | + public function __construct(Attribute ...$attribs) |
|
44 | + { |
|
45 | + $this->_attributes = $attribs; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * Initialize from attribute values. |
|
50 | - * |
|
51 | - * @param AttributeValue ...$values |
|
52 | - * @return self |
|
53 | - */ |
|
54 | - public static function fromAttributeValues(AttributeValue ...$values): self |
|
55 | - { |
|
56 | - $attribs = array_map( |
|
57 | - function (AttributeValue $value) { |
|
58 | - return $value->toAttribute(); |
|
59 | - }, $values); |
|
60 | - return new self(...$attribs); |
|
61 | - } |
|
48 | + /** |
|
49 | + * Initialize from attribute values. |
|
50 | + * |
|
51 | + * @param AttributeValue ...$values |
|
52 | + * @return self |
|
53 | + */ |
|
54 | + public static function fromAttributeValues(AttributeValue ...$values): self |
|
55 | + { |
|
56 | + $attribs = array_map( |
|
57 | + function (AttributeValue $value) { |
|
58 | + return $value->toAttribute(); |
|
59 | + }, $values); |
|
60 | + return new self(...$attribs); |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * Initialize from ASN.1. |
|
65 | - * |
|
66 | - * @param Set $set |
|
67 | - * @return self |
|
68 | - */ |
|
69 | - public static function fromASN1(Set $set): self |
|
70 | - { |
|
71 | - $attribs = array_map( |
|
72 | - function (UnspecifiedType $el) { |
|
73 | - return Attribute::fromASN1($el->asSequence()); |
|
74 | - }, $set->elements()); |
|
75 | - // cast attributes |
|
76 | - $attribs = array_map( |
|
77 | - function (Attribute $attr) { |
|
78 | - $oid = $attr->oid(); |
|
79 | - if (array_key_exists($oid, self::MAP_OID_TO_CLASS)) { |
|
80 | - $cls = self::MAP_OID_TO_CLASS[$oid]; |
|
81 | - return $attr->castValues($cls); |
|
82 | - } |
|
83 | - return $attr; |
|
84 | - }, $attribs); |
|
85 | - return new self(...$attribs); |
|
86 | - } |
|
63 | + /** |
|
64 | + * Initialize from ASN.1. |
|
65 | + * |
|
66 | + * @param Set $set |
|
67 | + * @return self |
|
68 | + */ |
|
69 | + public static function fromASN1(Set $set): self |
|
70 | + { |
|
71 | + $attribs = array_map( |
|
72 | + function (UnspecifiedType $el) { |
|
73 | + return Attribute::fromASN1($el->asSequence()); |
|
74 | + }, $set->elements()); |
|
75 | + // cast attributes |
|
76 | + $attribs = array_map( |
|
77 | + function (Attribute $attr) { |
|
78 | + $oid = $attr->oid(); |
|
79 | + if (array_key_exists($oid, self::MAP_OID_TO_CLASS)) { |
|
80 | + $cls = self::MAP_OID_TO_CLASS[$oid]; |
|
81 | + return $attr->castValues($cls); |
|
82 | + } |
|
83 | + return $attr; |
|
84 | + }, $attribs); |
|
85 | + return new self(...$attribs); |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * Check whether extension request attribute is present. |
|
90 | - * |
|
91 | - * @return bool |
|
92 | - */ |
|
93 | - public function hasExtensionRequest(): bool |
|
94 | - { |
|
95 | - return $this->has(ExtensionRequestValue::OID); |
|
96 | - } |
|
88 | + /** |
|
89 | + * Check whether extension request attribute is present. |
|
90 | + * |
|
91 | + * @return bool |
|
92 | + */ |
|
93 | + public function hasExtensionRequest(): bool |
|
94 | + { |
|
95 | + return $this->has(ExtensionRequestValue::OID); |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * Get extension request attribute value. |
|
100 | - * |
|
101 | - * @throws \LogicException |
|
102 | - * @return ExtensionRequestValue |
|
103 | - */ |
|
104 | - public function extensionRequest(): ExtensionRequestValue |
|
105 | - { |
|
106 | - if (!$this->hasExtensionRequest()) { |
|
107 | - throw new \LogicException("No extension request attribute."); |
|
108 | - } |
|
109 | - return $this->firstOf(ExtensionRequestValue::OID)->first(); |
|
110 | - } |
|
98 | + /** |
|
99 | + * Get extension request attribute value. |
|
100 | + * |
|
101 | + * @throws \LogicException |
|
102 | + * @return ExtensionRequestValue |
|
103 | + */ |
|
104 | + public function extensionRequest(): ExtensionRequestValue |
|
105 | + { |
|
106 | + if (!$this->hasExtensionRequest()) { |
|
107 | + throw new \LogicException("No extension request attribute."); |
|
108 | + } |
|
109 | + return $this->firstOf(ExtensionRequestValue::OID)->first(); |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * Generate ASN.1 structure. |
|
114 | - * |
|
115 | - * @return Set |
|
116 | - */ |
|
117 | - public function toASN1(): Set |
|
118 | - { |
|
119 | - $elements = array_map( |
|
120 | - function (Attribute $attr) { |
|
121 | - return $attr->toASN1(); |
|
122 | - }, array_values($this->_attributes)); |
|
123 | - $set = new Set(...$elements); |
|
124 | - return $set->sortedSetOf(); |
|
125 | - } |
|
112 | + /** |
|
113 | + * Generate ASN.1 structure. |
|
114 | + * |
|
115 | + * @return Set |
|
116 | + */ |
|
117 | + public function toASN1(): Set |
|
118 | + { |
|
119 | + $elements = array_map( |
|
120 | + function (Attribute $attr) { |
|
121 | + return $attr->toASN1(); |
|
122 | + }, array_values($this->_attributes)); |
|
123 | + $set = new Set(...$elements); |
|
124 | + return $set->sortedSetOf(); |
|
125 | + } |
|
126 | 126 | } |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | public static function fromAttributeValues(AttributeValue ...$values): self |
55 | 55 | { |
56 | 56 | $attribs = array_map( |
57 | - function (AttributeValue $value) { |
|
57 | + function(AttributeValue $value) { |
|
58 | 58 | return $value->toAttribute(); |
59 | 59 | }, $values); |
60 | 60 | return new self(...$attribs); |
@@ -69,12 +69,12 @@ discard block |
||
69 | 69 | public static function fromASN1(Set $set): self |
70 | 70 | { |
71 | 71 | $attribs = array_map( |
72 | - function (UnspecifiedType $el) { |
|
72 | + function(UnspecifiedType $el) { |
|
73 | 73 | return Attribute::fromASN1($el->asSequence()); |
74 | 74 | }, $set->elements()); |
75 | 75 | // cast attributes |
76 | 76 | $attribs = array_map( |
77 | - function (Attribute $attr) { |
|
77 | + function(Attribute $attr) { |
|
78 | 78 | $oid = $attr->oid(); |
79 | 79 | if (array_key_exists($oid, self::MAP_OID_TO_CLASS)) { |
80 | 80 | $cls = self::MAP_OID_TO_CLASS[$oid]; |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | public function toASN1(): Set |
118 | 118 | { |
119 | 119 | $elements = array_map( |
120 | - function (Attribute $attr) { |
|
120 | + function(Attribute $attr) { |
|
121 | 121 | return $attr->toASN1(); |
122 | 122 | }, array_values($this->_attributes)); |
123 | 123 | $set = new Set(...$elements); |
@@ -14,136 +14,136 @@ |
||
14 | 14 | */ |
15 | 15 | trait AttributeContainer |
16 | 16 | { |
17 | - /** |
|
18 | - * Array of attributes. |
|
19 | - * |
|
20 | - * @var Attribute[] $_attributes |
|
21 | - */ |
|
22 | - protected $_attributes; |
|
17 | + /** |
|
18 | + * Array of attributes. |
|
19 | + * |
|
20 | + * @var Attribute[] $_attributes |
|
21 | + */ |
|
22 | + protected $_attributes; |
|
23 | 23 | |
24 | - /** |
|
25 | - * Find first attribute of given name or OID. |
|
26 | - * |
|
27 | - * @param string $name |
|
28 | - * @return Attribute|null |
|
29 | - */ |
|
30 | - protected function _findFirst(string $name) |
|
31 | - { |
|
32 | - $oid = AttributeType::attrNameToOID($name); |
|
33 | - foreach ($this->_attributes as $attr) { |
|
34 | - if ($attr->oid() == $oid) { |
|
35 | - return $attr; |
|
36 | - } |
|
37 | - } |
|
38 | - return null; |
|
39 | - } |
|
24 | + /** |
|
25 | + * Find first attribute of given name or OID. |
|
26 | + * |
|
27 | + * @param string $name |
|
28 | + * @return Attribute|null |
|
29 | + */ |
|
30 | + protected function _findFirst(string $name) |
|
31 | + { |
|
32 | + $oid = AttributeType::attrNameToOID($name); |
|
33 | + foreach ($this->_attributes as $attr) { |
|
34 | + if ($attr->oid() == $oid) { |
|
35 | + return $attr; |
|
36 | + } |
|
37 | + } |
|
38 | + return null; |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * Check whether attribute is present. |
|
43 | - * |
|
44 | - * @param string $name OID or attribute name |
|
45 | - * @return boolean |
|
46 | - */ |
|
47 | - public function has(string $name): bool |
|
48 | - { |
|
49 | - return null !== $this->_findFirst($name); |
|
50 | - } |
|
41 | + /** |
|
42 | + * Check whether attribute is present. |
|
43 | + * |
|
44 | + * @param string $name OID or attribute name |
|
45 | + * @return boolean |
|
46 | + */ |
|
47 | + public function has(string $name): bool |
|
48 | + { |
|
49 | + return null !== $this->_findFirst($name); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Get first attribute by OID or attribute name. |
|
54 | - * |
|
55 | - * @param string $name OID or attribute name |
|
56 | - * @throws \OutOfBoundsException |
|
57 | - * @return Attribute |
|
58 | - */ |
|
59 | - public function firstOf(string $name): Attribute |
|
60 | - { |
|
61 | - $attr = $this->_findFirst($name); |
|
62 | - if (!$attr) { |
|
63 | - throw new \UnexpectedValueException("No $name attribute."); |
|
64 | - } |
|
65 | - return $attr; |
|
66 | - } |
|
52 | + /** |
|
53 | + * Get first attribute by OID or attribute name. |
|
54 | + * |
|
55 | + * @param string $name OID or attribute name |
|
56 | + * @throws \OutOfBoundsException |
|
57 | + * @return Attribute |
|
58 | + */ |
|
59 | + public function firstOf(string $name): Attribute |
|
60 | + { |
|
61 | + $attr = $this->_findFirst($name); |
|
62 | + if (!$attr) { |
|
63 | + throw new \UnexpectedValueException("No $name attribute."); |
|
64 | + } |
|
65 | + return $attr; |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * Get all attributes of given name. |
|
70 | - * |
|
71 | - * @param string $name OID or attribute name |
|
72 | - * @return Attribute[] |
|
73 | - */ |
|
74 | - public function allOf(string $name): array |
|
75 | - { |
|
76 | - $oid = AttributeType::attrNameToOID($name); |
|
77 | - $attrs = array_filter($this->_attributes, |
|
78 | - function (Attribute $attr) use ($oid) { |
|
79 | - return $attr->oid() == $oid; |
|
80 | - }); |
|
81 | - return array_values($attrs); |
|
82 | - } |
|
68 | + /** |
|
69 | + * Get all attributes of given name. |
|
70 | + * |
|
71 | + * @param string $name OID or attribute name |
|
72 | + * @return Attribute[] |
|
73 | + */ |
|
74 | + public function allOf(string $name): array |
|
75 | + { |
|
76 | + $oid = AttributeType::attrNameToOID($name); |
|
77 | + $attrs = array_filter($this->_attributes, |
|
78 | + function (Attribute $attr) use ($oid) { |
|
79 | + return $attr->oid() == $oid; |
|
80 | + }); |
|
81 | + return array_values($attrs); |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * Get all attributes. |
|
86 | - * |
|
87 | - * @return Attribute[] |
|
88 | - */ |
|
89 | - public function all(): array |
|
90 | - { |
|
91 | - return $this->_attributes; |
|
92 | - } |
|
84 | + /** |
|
85 | + * Get all attributes. |
|
86 | + * |
|
87 | + * @return Attribute[] |
|
88 | + */ |
|
89 | + public function all(): array |
|
90 | + { |
|
91 | + return $this->_attributes; |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * Get self with additional attributes added. |
|
96 | - * |
|
97 | - * @param Attribute ...$attribs |
|
98 | - * @return self |
|
99 | - */ |
|
100 | - public function withAdditional(Attribute ...$attribs): self |
|
101 | - { |
|
102 | - $obj = clone $this; |
|
103 | - foreach ($attribs as $attr) { |
|
104 | - $obj->_attributes[] = $attr; |
|
105 | - } |
|
106 | - return $obj; |
|
107 | - } |
|
94 | + /** |
|
95 | + * Get self with additional attributes added. |
|
96 | + * |
|
97 | + * @param Attribute ...$attribs |
|
98 | + * @return self |
|
99 | + */ |
|
100 | + public function withAdditional(Attribute ...$attribs): self |
|
101 | + { |
|
102 | + $obj = clone $this; |
|
103 | + foreach ($attribs as $attr) { |
|
104 | + $obj->_attributes[] = $attr; |
|
105 | + } |
|
106 | + return $obj; |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * Get self with single unique attribute added. |
|
111 | - * |
|
112 | - * All previous attributes of the same type are removed. |
|
113 | - * |
|
114 | - * @param Attribute $attr |
|
115 | - * @return self |
|
116 | - */ |
|
117 | - public function withUnique(Attribute $attr): self |
|
118 | - { |
|
119 | - $obj = clone $this; |
|
120 | - $obj->_attributes = array_filter($obj->_attributes, |
|
121 | - function (Attribute $a) use ($attr) { |
|
122 | - return $a->oid() != $attr->oid(); |
|
123 | - }); |
|
124 | - $obj->_attributes[] = $attr; |
|
125 | - return $obj; |
|
126 | - } |
|
109 | + /** |
|
110 | + * Get self with single unique attribute added. |
|
111 | + * |
|
112 | + * All previous attributes of the same type are removed. |
|
113 | + * |
|
114 | + * @param Attribute $attr |
|
115 | + * @return self |
|
116 | + */ |
|
117 | + public function withUnique(Attribute $attr): self |
|
118 | + { |
|
119 | + $obj = clone $this; |
|
120 | + $obj->_attributes = array_filter($obj->_attributes, |
|
121 | + function (Attribute $a) use ($attr) { |
|
122 | + return $a->oid() != $attr->oid(); |
|
123 | + }); |
|
124 | + $obj->_attributes[] = $attr; |
|
125 | + return $obj; |
|
126 | + } |
|
127 | 127 | |
128 | - /** |
|
129 | - * Get number of attributes. |
|
130 | - * |
|
131 | - * @see \Countable::count() |
|
132 | - * @return int |
|
133 | - */ |
|
134 | - public function count(): int |
|
135 | - { |
|
136 | - return count($this->_attributes); |
|
137 | - } |
|
128 | + /** |
|
129 | + * Get number of attributes. |
|
130 | + * |
|
131 | + * @see \Countable::count() |
|
132 | + * @return int |
|
133 | + */ |
|
134 | + public function count(): int |
|
135 | + { |
|
136 | + return count($this->_attributes); |
|
137 | + } |
|
138 | 138 | |
139 | - /** |
|
140 | - * Get iterator for attributes. |
|
141 | - * |
|
142 | - * @see \IteratorAggregate::getIterator() |
|
143 | - * @return \ArrayIterator |
|
144 | - */ |
|
145 | - public function getIterator(): \ArrayIterator |
|
146 | - { |
|
147 | - return new \ArrayIterator($this->_attributes); |
|
148 | - } |
|
139 | + /** |
|
140 | + * Get iterator for attributes. |
|
141 | + * |
|
142 | + * @see \IteratorAggregate::getIterator() |
|
143 | + * @return \ArrayIterator |
|
144 | + */ |
|
145 | + public function getIterator(): \ArrayIterator |
|
146 | + { |
|
147 | + return new \ArrayIterator($this->_attributes); |
|
148 | + } |
|
149 | 149 | } |
@@ -9,69 +9,69 @@ |
||
9 | 9 | */ |
10 | 10 | trait DateTimeHelper |
11 | 11 | { |
12 | - /** |
|
13 | - * Create DateTime object from time string and timezone. |
|
14 | - * |
|
15 | - * @param string|null $time Time string, default to 'now' |
|
16 | - * @param string|null $tz Timezone, default if omitted |
|
17 | - * @throws \RuntimeException |
|
18 | - * @return \DateTimeImmutable |
|
19 | - */ |
|
20 | - private static function _createDateTime($time = null, $tz = null): \DateTimeImmutable |
|
21 | - { |
|
22 | - if (!isset($time)) { |
|
23 | - $time = 'now'; |
|
24 | - } |
|
25 | - if (!isset($tz)) { |
|
26 | - $tz = date_default_timezone_get(); |
|
27 | - } |
|
28 | - try { |
|
29 | - $dt = new \DateTimeImmutable($time, self::_createTimeZone($tz)); |
|
30 | - return self::_roundDownFractionalSeconds($dt); |
|
31 | - } catch (\Exception $e) { |
|
32 | - throw new \RuntimeException( |
|
33 | - "Failed to create DateTime: " . |
|
34 | - self::_getLastDateTimeImmutableErrorsStr(), 0, $e); |
|
35 | - } |
|
36 | - } |
|
12 | + /** |
|
13 | + * Create DateTime object from time string and timezone. |
|
14 | + * |
|
15 | + * @param string|null $time Time string, default to 'now' |
|
16 | + * @param string|null $tz Timezone, default if omitted |
|
17 | + * @throws \RuntimeException |
|
18 | + * @return \DateTimeImmutable |
|
19 | + */ |
|
20 | + private static function _createDateTime($time = null, $tz = null): \DateTimeImmutable |
|
21 | + { |
|
22 | + if (!isset($time)) { |
|
23 | + $time = 'now'; |
|
24 | + } |
|
25 | + if (!isset($tz)) { |
|
26 | + $tz = date_default_timezone_get(); |
|
27 | + } |
|
28 | + try { |
|
29 | + $dt = new \DateTimeImmutable($time, self::_createTimeZone($tz)); |
|
30 | + return self::_roundDownFractionalSeconds($dt); |
|
31 | + } catch (\Exception $e) { |
|
32 | + throw new \RuntimeException( |
|
33 | + "Failed to create DateTime: " . |
|
34 | + self::_getLastDateTimeImmutableErrorsStr(), 0, $e); |
|
35 | + } |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * Rounds a \DateTimeImmutable value such that fractional |
|
40 | - * seconds are removed. |
|
41 | - * |
|
42 | - * @param \DateTimeImmutable $dt |
|
43 | - * @return \DateTimeImmutable |
|
44 | - */ |
|
45 | - private static function _roundDownFractionalSeconds(\DateTimeImmutable $dt): \DateTimeImmutable |
|
46 | - { |
|
47 | - return \DateTimeImmutable::createFromFormat("Y-m-d H:i:s", |
|
48 | - $dt->format("Y-m-d H:i:s"), $dt->getTimezone()); |
|
49 | - } |
|
38 | + /** |
|
39 | + * Rounds a \DateTimeImmutable value such that fractional |
|
40 | + * seconds are removed. |
|
41 | + * |
|
42 | + * @param \DateTimeImmutable $dt |
|
43 | + * @return \DateTimeImmutable |
|
44 | + */ |
|
45 | + private static function _roundDownFractionalSeconds(\DateTimeImmutable $dt): \DateTimeImmutable |
|
46 | + { |
|
47 | + return \DateTimeImmutable::createFromFormat("Y-m-d H:i:s", |
|
48 | + $dt->format("Y-m-d H:i:s"), $dt->getTimezone()); |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * Create DateTimeZone object from string. |
|
53 | - * |
|
54 | - * @param string $tz |
|
55 | - * @throws \UnexpectedValueException |
|
56 | - * @return \DateTimeZone |
|
57 | - */ |
|
58 | - private static function _createTimeZone(string $tz): \DateTimeZone |
|
59 | - { |
|
60 | - try { |
|
61 | - return new \DateTimeZone($tz); |
|
62 | - } catch (\Exception $e) { |
|
63 | - throw new \UnexpectedValueException("Invalid timezone.", 0, $e); |
|
64 | - } |
|
65 | - } |
|
51 | + /** |
|
52 | + * Create DateTimeZone object from string. |
|
53 | + * |
|
54 | + * @param string $tz |
|
55 | + * @throws \UnexpectedValueException |
|
56 | + * @return \DateTimeZone |
|
57 | + */ |
|
58 | + private static function _createTimeZone(string $tz): \DateTimeZone |
|
59 | + { |
|
60 | + try { |
|
61 | + return new \DateTimeZone($tz); |
|
62 | + } catch (\Exception $e) { |
|
63 | + throw new \UnexpectedValueException("Invalid timezone.", 0, $e); |
|
64 | + } |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * Get last error caused by DateTimeImmutable. |
|
69 | - * |
|
70 | - * @return string |
|
71 | - */ |
|
72 | - private static function _getLastDateTimeImmutableErrorsStr(): string |
|
73 | - { |
|
74 | - $errors = \DateTimeImmutable::getLastErrors()["errors"]; |
|
75 | - return implode(", ", $errors); |
|
76 | - } |
|
67 | + /** |
|
68 | + * Get last error caused by DateTimeImmutable. |
|
69 | + * |
|
70 | + * @return string |
|
71 | + */ |
|
72 | + private static function _getLastDateTimeImmutableErrorsStr(): string |
|
73 | + { |
|
74 | + $errors = \DateTimeImmutable::getLastErrors()["errors"]; |
|
75 | + return implode(", ", $errors); |
|
76 | + } |
|
77 | 77 | } |
@@ -15,147 +15,147 @@ |
||
15 | 15 | */ |
16 | 16 | abstract class GeneralName |
17 | 17 | { |
18 | - // GeneralName CHOICE tags |
|
19 | - const TAG_OTHER_NAME = 0; |
|
20 | - const TAG_RFC822_NAME = 1; |
|
21 | - const TAG_DNS_NAME = 2; |
|
22 | - const TAG_X400_ADDRESS = 3; |
|
23 | - const TAG_DIRECTORY_NAME = 4; |
|
24 | - const TAG_EDI_PARTY_NAME = 5; |
|
25 | - const TAG_URI = 6; |
|
26 | - const TAG_IP_ADDRESS = 7; |
|
27 | - const TAG_REGISTERED_ID = 8; |
|
18 | + // GeneralName CHOICE tags |
|
19 | + const TAG_OTHER_NAME = 0; |
|
20 | + const TAG_RFC822_NAME = 1; |
|
21 | + const TAG_DNS_NAME = 2; |
|
22 | + const TAG_X400_ADDRESS = 3; |
|
23 | + const TAG_DIRECTORY_NAME = 4; |
|
24 | + const TAG_EDI_PARTY_NAME = 5; |
|
25 | + const TAG_URI = 6; |
|
26 | + const TAG_IP_ADDRESS = 7; |
|
27 | + const TAG_REGISTERED_ID = 8; |
|
28 | 28 | |
29 | - /** |
|
30 | - * Chosen tag. |
|
31 | - * |
|
32 | - * @var int $_tag |
|
33 | - */ |
|
34 | - protected $_tag; |
|
29 | + /** |
|
30 | + * Chosen tag. |
|
31 | + * |
|
32 | + * @var int $_tag |
|
33 | + */ |
|
34 | + protected $_tag; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Get string value of the type. |
|
38 | - * |
|
39 | - * @return string |
|
40 | - */ |
|
41 | - abstract public function string(): string; |
|
36 | + /** |
|
37 | + * Get string value of the type. |
|
38 | + * |
|
39 | + * @return string |
|
40 | + */ |
|
41 | + abstract public function string(): string; |
|
42 | 42 | |
43 | - /** |
|
44 | - * Get ASN.1 value in GeneralName CHOICE context. |
|
45 | - * |
|
46 | - * @return TaggedType |
|
47 | - */ |
|
48 | - abstract protected function _choiceASN1(): TaggedType; |
|
43 | + /** |
|
44 | + * Get ASN.1 value in GeneralName CHOICE context. |
|
45 | + * |
|
46 | + * @return TaggedType |
|
47 | + */ |
|
48 | + abstract protected function _choiceASN1(): TaggedType; |
|
49 | 49 | |
50 | - /** |
|
51 | - * Initialize concrete object from the chosen ASN.1 element. |
|
52 | - * |
|
53 | - * @param UnspecifiedType $el |
|
54 | - * @return self |
|
55 | - */ |
|
56 | - public static function fromChosenASN1(UnspecifiedType $el) |
|
57 | - { |
|
58 | - throw new \BadMethodCallException( |
|
59 | - __FUNCTION__ . " must be implemented in the derived class."); |
|
60 | - } |
|
50 | + /** |
|
51 | + * Initialize concrete object from the chosen ASN.1 element. |
|
52 | + * |
|
53 | + * @param UnspecifiedType $el |
|
54 | + * @return self |
|
55 | + */ |
|
56 | + public static function fromChosenASN1(UnspecifiedType $el) |
|
57 | + { |
|
58 | + throw new \BadMethodCallException( |
|
59 | + __FUNCTION__ . " must be implemented in the derived class."); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Initialize from ASN.1. |
|
64 | - * |
|
65 | - * @param TaggedType $el |
|
66 | - * @throws \UnexpectedValueException |
|
67 | - * @return self |
|
68 | - */ |
|
69 | - public static function fromASN1(TaggedType $el): self |
|
70 | - { |
|
71 | - switch ($el->tag()) { |
|
72 | - // otherName |
|
73 | - case self::TAG_OTHER_NAME: |
|
74 | - return OtherName::fromChosenASN1( |
|
75 | - $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
76 | - // rfc822Name |
|
77 | - case self::TAG_RFC822_NAME: |
|
78 | - return RFC822Name::fromChosenASN1( |
|
79 | - $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
80 | - // dNSName |
|
81 | - case self::TAG_DNS_NAME: |
|
82 | - return DNSName::fromChosenASN1( |
|
83 | - $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
84 | - // x400Address |
|
85 | - case self::TAG_X400_ADDRESS: |
|
86 | - return X400Address::fromChosenASN1( |
|
87 | - $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
88 | - // directoryName |
|
89 | - case self::TAG_DIRECTORY_NAME: |
|
90 | - // because Name is a CHOICE, albeit having only one option, |
|
91 | - // explicit tagging must be used |
|
92 | - // (see X.680 07/2002 30.6.c) |
|
93 | - return DirectoryName::fromChosenASN1($el->asExplicit()); |
|
94 | - // ediPartyName |
|
95 | - case self::TAG_EDI_PARTY_NAME: |
|
96 | - return EDIPartyName::fromChosenASN1( |
|
97 | - $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
98 | - // uniformResourceIdentifier |
|
99 | - case self::TAG_URI: |
|
100 | - return UniformResourceIdentifier::fromChosenASN1( |
|
101 | - $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
102 | - // iPAddress |
|
103 | - case self::TAG_IP_ADDRESS: |
|
104 | - return IPAddress::fromChosenASN1( |
|
105 | - $el->asImplicit(Element::TYPE_OCTET_STRING)); |
|
106 | - // registeredID |
|
107 | - case self::TAG_REGISTERED_ID: |
|
108 | - return RegisteredID::fromChosenASN1( |
|
109 | - $el->asImplicit(Element::TYPE_OBJECT_IDENTIFIER)); |
|
110 | - } |
|
111 | - throw new \UnexpectedValueException( |
|
112 | - "GeneralName type " . $el->tag() . " not supported."); |
|
113 | - } |
|
62 | + /** |
|
63 | + * Initialize from ASN.1. |
|
64 | + * |
|
65 | + * @param TaggedType $el |
|
66 | + * @throws \UnexpectedValueException |
|
67 | + * @return self |
|
68 | + */ |
|
69 | + public static function fromASN1(TaggedType $el): self |
|
70 | + { |
|
71 | + switch ($el->tag()) { |
|
72 | + // otherName |
|
73 | + case self::TAG_OTHER_NAME: |
|
74 | + return OtherName::fromChosenASN1( |
|
75 | + $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
76 | + // rfc822Name |
|
77 | + case self::TAG_RFC822_NAME: |
|
78 | + return RFC822Name::fromChosenASN1( |
|
79 | + $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
80 | + // dNSName |
|
81 | + case self::TAG_DNS_NAME: |
|
82 | + return DNSName::fromChosenASN1( |
|
83 | + $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
84 | + // x400Address |
|
85 | + case self::TAG_X400_ADDRESS: |
|
86 | + return X400Address::fromChosenASN1( |
|
87 | + $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
88 | + // directoryName |
|
89 | + case self::TAG_DIRECTORY_NAME: |
|
90 | + // because Name is a CHOICE, albeit having only one option, |
|
91 | + // explicit tagging must be used |
|
92 | + // (see X.680 07/2002 30.6.c) |
|
93 | + return DirectoryName::fromChosenASN1($el->asExplicit()); |
|
94 | + // ediPartyName |
|
95 | + case self::TAG_EDI_PARTY_NAME: |
|
96 | + return EDIPartyName::fromChosenASN1( |
|
97 | + $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
98 | + // uniformResourceIdentifier |
|
99 | + case self::TAG_URI: |
|
100 | + return UniformResourceIdentifier::fromChosenASN1( |
|
101 | + $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
102 | + // iPAddress |
|
103 | + case self::TAG_IP_ADDRESS: |
|
104 | + return IPAddress::fromChosenASN1( |
|
105 | + $el->asImplicit(Element::TYPE_OCTET_STRING)); |
|
106 | + // registeredID |
|
107 | + case self::TAG_REGISTERED_ID: |
|
108 | + return RegisteredID::fromChosenASN1( |
|
109 | + $el->asImplicit(Element::TYPE_OBJECT_IDENTIFIER)); |
|
110 | + } |
|
111 | + throw new \UnexpectedValueException( |
|
112 | + "GeneralName type " . $el->tag() . " not supported."); |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * Get type tag. |
|
117 | - * |
|
118 | - * @return int |
|
119 | - */ |
|
120 | - public function tag(): int |
|
121 | - { |
|
122 | - return $this->_tag; |
|
123 | - } |
|
115 | + /** |
|
116 | + * Get type tag. |
|
117 | + * |
|
118 | + * @return int |
|
119 | + */ |
|
120 | + public function tag(): int |
|
121 | + { |
|
122 | + return $this->_tag; |
|
123 | + } |
|
124 | 124 | |
125 | - /** |
|
126 | - * Generate ASN.1 element. |
|
127 | - * |
|
128 | - * @return Element |
|
129 | - */ |
|
130 | - public function toASN1(): Element |
|
131 | - { |
|
132 | - return $this->_choiceASN1(); |
|
133 | - } |
|
125 | + /** |
|
126 | + * Generate ASN.1 element. |
|
127 | + * |
|
128 | + * @return Element |
|
129 | + */ |
|
130 | + public function toASN1(): Element |
|
131 | + { |
|
132 | + return $this->_choiceASN1(); |
|
133 | + } |
|
134 | 134 | |
135 | - /** |
|
136 | - * Check whether GeneralName is equal to other. |
|
137 | - * |
|
138 | - * @param GeneralName $other GeneralName to compare to |
|
139 | - * @return boolean True if names are equal |
|
140 | - */ |
|
141 | - public function equals(GeneralName $other): bool |
|
142 | - { |
|
143 | - if ($this->_tag != $other->_tag) { |
|
144 | - return false; |
|
145 | - } |
|
146 | - if ($this->_choiceASN1()->toDER() != $other->_choiceASN1()->toDER()) { |
|
147 | - return false; |
|
148 | - } |
|
149 | - return true; |
|
150 | - } |
|
135 | + /** |
|
136 | + * Check whether GeneralName is equal to other. |
|
137 | + * |
|
138 | + * @param GeneralName $other GeneralName to compare to |
|
139 | + * @return boolean True if names are equal |
|
140 | + */ |
|
141 | + public function equals(GeneralName $other): bool |
|
142 | + { |
|
143 | + if ($this->_tag != $other->_tag) { |
|
144 | + return false; |
|
145 | + } |
|
146 | + if ($this->_choiceASN1()->toDER() != $other->_choiceASN1()->toDER()) { |
|
147 | + return false; |
|
148 | + } |
|
149 | + return true; |
|
150 | + } |
|
151 | 151 | |
152 | - /** |
|
153 | - * Get general name as a string. |
|
154 | - * |
|
155 | - * @return string |
|
156 | - */ |
|
157 | - public function __toString() |
|
158 | - { |
|
159 | - return $this->string(); |
|
160 | - } |
|
152 | + /** |
|
153 | + * Get general name as a string. |
|
154 | + * |
|
155 | + * @return string |
|
156 | + */ |
|
157 | + public function __toString() |
|
158 | + { |
|
159 | + return $this->string(); |
|
160 | + } |
|
161 | 161 | } |
@@ -16,59 +16,59 @@ |
||
16 | 16 | */ |
17 | 17 | class RFC822Name extends GeneralName |
18 | 18 | { |
19 | - /** |
|
20 | - * Email. |
|
21 | - * |
|
22 | - * @var string $_email |
|
23 | - */ |
|
24 | - protected $_email; |
|
19 | + /** |
|
20 | + * Email. |
|
21 | + * |
|
22 | + * @var string $_email |
|
23 | + */ |
|
24 | + protected $_email; |
|
25 | 25 | |
26 | - /** |
|
27 | - * Constructor. |
|
28 | - * |
|
29 | - * @param string $email |
|
30 | - */ |
|
31 | - public function __construct(string $email) |
|
32 | - { |
|
33 | - $this->_tag = self::TAG_RFC822_NAME; |
|
34 | - $this->_email = $email; |
|
35 | - } |
|
26 | + /** |
|
27 | + * Constructor. |
|
28 | + * |
|
29 | + * @param string $email |
|
30 | + */ |
|
31 | + public function __construct(string $email) |
|
32 | + { |
|
33 | + $this->_tag = self::TAG_RFC822_NAME; |
|
34 | + $this->_email = $email; |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * |
|
39 | - * @param UnspecifiedType $el |
|
40 | - * @return self |
|
41 | - */ |
|
42 | - public static function fromChosenASN1(UnspecifiedType $el): self |
|
43 | - { |
|
44 | - return new self($el->asIA5String()->string()); |
|
45 | - } |
|
37 | + /** |
|
38 | + * |
|
39 | + * @param UnspecifiedType $el |
|
40 | + * @return self |
|
41 | + */ |
|
42 | + public static function fromChosenASN1(UnspecifiedType $el): self |
|
43 | + { |
|
44 | + return new self($el->asIA5String()->string()); |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * |
|
49 | - * {@inheritdoc} |
|
50 | - */ |
|
51 | - public function string(): string |
|
52 | - { |
|
53 | - return $this->_email; |
|
54 | - } |
|
47 | + /** |
|
48 | + * |
|
49 | + * {@inheritdoc} |
|
50 | + */ |
|
51 | + public function string(): string |
|
52 | + { |
|
53 | + return $this->_email; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * Get email. |
|
58 | - * |
|
59 | - * @return string |
|
60 | - */ |
|
61 | - public function email(): string |
|
62 | - { |
|
63 | - return $this->_email; |
|
64 | - } |
|
56 | + /** |
|
57 | + * Get email. |
|
58 | + * |
|
59 | + * @return string |
|
60 | + */ |
|
61 | + public function email(): string |
|
62 | + { |
|
63 | + return $this->_email; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * |
|
68 | - * {@inheritdoc} |
|
69 | - */ |
|
70 | - protected function _choiceASN1(): TaggedType |
|
71 | - { |
|
72 | - return new ImplicitlyTaggedType($this->_tag, new IA5String($this->_email)); |
|
73 | - } |
|
66 | + /** |
|
67 | + * |
|
68 | + * {@inheritdoc} |
|
69 | + */ |
|
70 | + protected function _choiceASN1(): TaggedType |
|
71 | + { |
|
72 | + return new ImplicitlyTaggedType($this->_tag, new IA5String($this->_email)); |
|
73 | + } |
|
74 | 74 | } |
@@ -18,47 +18,47 @@ |
||
18 | 18 | */ |
19 | 19 | class EDIPartyName extends GeneralName |
20 | 20 | { |
21 | - /** |
|
22 | - * |
|
23 | - * @var \ASN1\Element |
|
24 | - */ |
|
25 | - protected $_element; |
|
21 | + /** |
|
22 | + * |
|
23 | + * @var \ASN1\Element |
|
24 | + */ |
|
25 | + protected $_element; |
|
26 | 26 | |
27 | - /** |
|
28 | - * Constructor. |
|
29 | - */ |
|
30 | - protected function __construct() |
|
31 | - { |
|
32 | - $this->_tag = self::TAG_EDI_PARTY_NAME; |
|
33 | - } |
|
27 | + /** |
|
28 | + * Constructor. |
|
29 | + */ |
|
30 | + protected function __construct() |
|
31 | + { |
|
32 | + $this->_tag = self::TAG_EDI_PARTY_NAME; |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * |
|
37 | - * @param UnspecifiedType $el |
|
38 | - * @return self |
|
39 | - */ |
|
40 | - public static function fromChosenASN1(UnspecifiedType $el): self |
|
41 | - { |
|
42 | - $obj = new self(); |
|
43 | - $obj->_element = $el->asSequence(); |
|
44 | - return $obj; |
|
45 | - } |
|
35 | + /** |
|
36 | + * |
|
37 | + * @param UnspecifiedType $el |
|
38 | + * @return self |
|
39 | + */ |
|
40 | + public static function fromChosenASN1(UnspecifiedType $el): self |
|
41 | + { |
|
42 | + $obj = new self(); |
|
43 | + $obj->_element = $el->asSequence(); |
|
44 | + return $obj; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * |
|
49 | - * {@inheritdoc} |
|
50 | - */ |
|
51 | - public function string(): string |
|
52 | - { |
|
53 | - return bin2hex($this->_element->toDER()); |
|
54 | - } |
|
47 | + /** |
|
48 | + * |
|
49 | + * {@inheritdoc} |
|
50 | + */ |
|
51 | + public function string(): string |
|
52 | + { |
|
53 | + return bin2hex($this->_element->toDER()); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * |
|
58 | - * {@inheritdoc} |
|
59 | - */ |
|
60 | - protected function _choiceASN1(): TaggedType |
|
61 | - { |
|
62 | - return new ImplicitlyTaggedType($this->_tag, $this->_element); |
|
63 | - } |
|
56 | + /** |
|
57 | + * |
|
58 | + * {@inheritdoc} |
|
59 | + */ |
|
60 | + protected function _choiceASN1(): TaggedType |
|
61 | + { |
|
62 | + return new ImplicitlyTaggedType($this->_tag, $this->_element); |
|
63 | + } |
|
64 | 64 | } |
@@ -18,183 +18,183 @@ |
||
18 | 18 | */ |
19 | 19 | class GeneralNames implements \Countable, \IteratorAggregate |
20 | 20 | { |
21 | - /** |
|
22 | - * GeneralName objects. |
|
23 | - * |
|
24 | - * @var GeneralName[] $_names |
|
25 | - */ |
|
26 | - protected $_names; |
|
21 | + /** |
|
22 | + * GeneralName objects. |
|
23 | + * |
|
24 | + * @var GeneralName[] $_names |
|
25 | + */ |
|
26 | + protected $_names; |
|
27 | 27 | |
28 | - /** |
|
29 | - * Constructor. |
|
30 | - * |
|
31 | - * @param GeneralName ...$names One or more GeneralName objects |
|
32 | - */ |
|
33 | - public function __construct(GeneralName ...$names) |
|
34 | - { |
|
35 | - $this->_names = $names; |
|
36 | - } |
|
28 | + /** |
|
29 | + * Constructor. |
|
30 | + * |
|
31 | + * @param GeneralName ...$names One or more GeneralName objects |
|
32 | + */ |
|
33 | + public function __construct(GeneralName ...$names) |
|
34 | + { |
|
35 | + $this->_names = $names; |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * Initialize from ASN.1. |
|
40 | - * |
|
41 | - * @param Sequence $seq |
|
42 | - * @throws \UnexpectedValueException |
|
43 | - * @return self |
|
44 | - */ |
|
45 | - public static function fromASN1(Sequence $seq): self |
|
46 | - { |
|
47 | - if (!count($seq)) { |
|
48 | - throw new \UnexpectedValueException( |
|
49 | - "GeneralNames must have at least one GeneralName."); |
|
50 | - } |
|
51 | - $names = array_map( |
|
52 | - function (UnspecifiedType $el) { |
|
53 | - return GeneralName::fromASN1($el->asTagged()); |
|
54 | - }, $seq->elements()); |
|
55 | - return new self(...$names); |
|
56 | - } |
|
38 | + /** |
|
39 | + * Initialize from ASN.1. |
|
40 | + * |
|
41 | + * @param Sequence $seq |
|
42 | + * @throws \UnexpectedValueException |
|
43 | + * @return self |
|
44 | + */ |
|
45 | + public static function fromASN1(Sequence $seq): self |
|
46 | + { |
|
47 | + if (!count($seq)) { |
|
48 | + throw new \UnexpectedValueException( |
|
49 | + "GeneralNames must have at least one GeneralName."); |
|
50 | + } |
|
51 | + $names = array_map( |
|
52 | + function (UnspecifiedType $el) { |
|
53 | + return GeneralName::fromASN1($el->asTagged()); |
|
54 | + }, $seq->elements()); |
|
55 | + return new self(...$names); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * Find first GeneralName by given tag. |
|
60 | - * |
|
61 | - * @param int $tag |
|
62 | - * @return GeneralName|null |
|
63 | - */ |
|
64 | - protected function _findFirst(int $tag) |
|
65 | - { |
|
66 | - foreach ($this->_names as $name) { |
|
67 | - if ($name->tag() == $tag) { |
|
68 | - return $name; |
|
69 | - } |
|
70 | - } |
|
71 | - return null; |
|
72 | - } |
|
58 | + /** |
|
59 | + * Find first GeneralName by given tag. |
|
60 | + * |
|
61 | + * @param int $tag |
|
62 | + * @return GeneralName|null |
|
63 | + */ |
|
64 | + protected function _findFirst(int $tag) |
|
65 | + { |
|
66 | + foreach ($this->_names as $name) { |
|
67 | + if ($name->tag() == $tag) { |
|
68 | + return $name; |
|
69 | + } |
|
70 | + } |
|
71 | + return null; |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * Check whether GeneralNames contains a GeneralName of given type. |
|
76 | - * |
|
77 | - * @param int $tag One of <code>GeneralName::TAG_*</code> enumerations |
|
78 | - * @return bool |
|
79 | - */ |
|
80 | - public function has(int $tag): bool |
|
81 | - { |
|
82 | - return null !== $this->_findFirst($tag); |
|
83 | - } |
|
74 | + /** |
|
75 | + * Check whether GeneralNames contains a GeneralName of given type. |
|
76 | + * |
|
77 | + * @param int $tag One of <code>GeneralName::TAG_*</code> enumerations |
|
78 | + * @return bool |
|
79 | + */ |
|
80 | + public function has(int $tag): bool |
|
81 | + { |
|
82 | + return null !== $this->_findFirst($tag); |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * Get first GeneralName of given type. |
|
87 | - * |
|
88 | - * @param int $tag One of <code>GeneralName::TAG_*</code> enumerations |
|
89 | - * @throws \OutOfBoundsException |
|
90 | - * @return GeneralName |
|
91 | - */ |
|
92 | - public function firstOf(int $tag): GeneralName |
|
93 | - { |
|
94 | - $name = $this->_findFirst($tag); |
|
95 | - if (!$name) { |
|
96 | - throw new \UnexpectedValueException("No GeneralName by tag $tag."); |
|
97 | - } |
|
98 | - return $name; |
|
99 | - } |
|
85 | + /** |
|
86 | + * Get first GeneralName of given type. |
|
87 | + * |
|
88 | + * @param int $tag One of <code>GeneralName::TAG_*</code> enumerations |
|
89 | + * @throws \OutOfBoundsException |
|
90 | + * @return GeneralName |
|
91 | + */ |
|
92 | + public function firstOf(int $tag): GeneralName |
|
93 | + { |
|
94 | + $name = $this->_findFirst($tag); |
|
95 | + if (!$name) { |
|
96 | + throw new \UnexpectedValueException("No GeneralName by tag $tag."); |
|
97 | + } |
|
98 | + return $name; |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Get all GeneralName objects of given type. |
|
103 | - * |
|
104 | - * @param int $tag One of <code>GeneralName::TAG_*</code> enumerations |
|
105 | - * @return GeneralName[] |
|
106 | - */ |
|
107 | - public function allOf(int $tag): array |
|
108 | - { |
|
109 | - $names = array_filter($this->_names, |
|
110 | - function (GeneralName $name) use ($tag) { |
|
111 | - return $name->tag() == $tag; |
|
112 | - }); |
|
113 | - return array_values($names); |
|
114 | - } |
|
101 | + /** |
|
102 | + * Get all GeneralName objects of given type. |
|
103 | + * |
|
104 | + * @param int $tag One of <code>GeneralName::TAG_*</code> enumerations |
|
105 | + * @return GeneralName[] |
|
106 | + */ |
|
107 | + public function allOf(int $tag): array |
|
108 | + { |
|
109 | + $names = array_filter($this->_names, |
|
110 | + function (GeneralName $name) use ($tag) { |
|
111 | + return $name->tag() == $tag; |
|
112 | + }); |
|
113 | + return array_values($names); |
|
114 | + } |
|
115 | 115 | |
116 | - /** |
|
117 | - * Get value of the first 'dNSName' type. |
|
118 | - * |
|
119 | - * @return string |
|
120 | - */ |
|
121 | - public function firstDNS(): string |
|
122 | - { |
|
123 | - $gn = $this->firstOf(GeneralName::TAG_DNS_NAME); |
|
124 | - if (!$gn instanceof DNSName) { |
|
125 | - throw new \RuntimeException( |
|
126 | - DNSName::class . " expected, got " . get_class($gn)); |
|
127 | - } |
|
128 | - return $gn->name(); |
|
129 | - } |
|
116 | + /** |
|
117 | + * Get value of the first 'dNSName' type. |
|
118 | + * |
|
119 | + * @return string |
|
120 | + */ |
|
121 | + public function firstDNS(): string |
|
122 | + { |
|
123 | + $gn = $this->firstOf(GeneralName::TAG_DNS_NAME); |
|
124 | + if (!$gn instanceof DNSName) { |
|
125 | + throw new \RuntimeException( |
|
126 | + DNSName::class . " expected, got " . get_class($gn)); |
|
127 | + } |
|
128 | + return $gn->name(); |
|
129 | + } |
|
130 | 130 | |
131 | - /** |
|
132 | - * Get value of the first 'directoryName' type. |
|
133 | - * |
|
134 | - * @return Name |
|
135 | - */ |
|
136 | - public function firstDN(): Name |
|
137 | - { |
|
138 | - $gn = $this->firstOf(GeneralName::TAG_DIRECTORY_NAME); |
|
139 | - if (!$gn instanceof DirectoryName) { |
|
140 | - throw new \RuntimeException( |
|
141 | - DirectoryName::class . " expected, got " . get_class($gn)); |
|
142 | - } |
|
143 | - return $gn->dn(); |
|
144 | - } |
|
131 | + /** |
|
132 | + * Get value of the first 'directoryName' type. |
|
133 | + * |
|
134 | + * @return Name |
|
135 | + */ |
|
136 | + public function firstDN(): Name |
|
137 | + { |
|
138 | + $gn = $this->firstOf(GeneralName::TAG_DIRECTORY_NAME); |
|
139 | + if (!$gn instanceof DirectoryName) { |
|
140 | + throw new \RuntimeException( |
|
141 | + DirectoryName::class . " expected, got " . get_class($gn)); |
|
142 | + } |
|
143 | + return $gn->dn(); |
|
144 | + } |
|
145 | 145 | |
146 | - /** |
|
147 | - * Get value of the first 'uniformResourceIdentifier' type. |
|
148 | - * |
|
149 | - * @return string |
|
150 | - */ |
|
151 | - public function firstURI(): string |
|
152 | - { |
|
153 | - $gn = $this->firstOf(GeneralName::TAG_URI); |
|
154 | - if (!$gn instanceof UniformResourceIdentifier) { |
|
155 | - throw new \RuntimeException( |
|
156 | - UniformResourceIdentifier::class . " expected, got " . |
|
157 | - get_class($gn)); |
|
158 | - } |
|
159 | - return $gn->uri(); |
|
160 | - } |
|
146 | + /** |
|
147 | + * Get value of the first 'uniformResourceIdentifier' type. |
|
148 | + * |
|
149 | + * @return string |
|
150 | + */ |
|
151 | + public function firstURI(): string |
|
152 | + { |
|
153 | + $gn = $this->firstOf(GeneralName::TAG_URI); |
|
154 | + if (!$gn instanceof UniformResourceIdentifier) { |
|
155 | + throw new \RuntimeException( |
|
156 | + UniformResourceIdentifier::class . " expected, got " . |
|
157 | + get_class($gn)); |
|
158 | + } |
|
159 | + return $gn->uri(); |
|
160 | + } |
|
161 | 161 | |
162 | - /** |
|
163 | - * Generate ASN.1 structure. |
|
164 | - * |
|
165 | - * @return Sequence |
|
166 | - */ |
|
167 | - public function toASN1(): Sequence |
|
168 | - { |
|
169 | - if (!count($this->_names)) { |
|
170 | - throw new \LogicException( |
|
171 | - "GeneralNames must have at least one GeneralName."); |
|
172 | - } |
|
173 | - $elements = array_map( |
|
174 | - function (GeneralName $name) { |
|
175 | - return $name->toASN1(); |
|
176 | - }, $this->_names); |
|
177 | - return new Sequence(...$elements); |
|
178 | - } |
|
162 | + /** |
|
163 | + * Generate ASN.1 structure. |
|
164 | + * |
|
165 | + * @return Sequence |
|
166 | + */ |
|
167 | + public function toASN1(): Sequence |
|
168 | + { |
|
169 | + if (!count($this->_names)) { |
|
170 | + throw new \LogicException( |
|
171 | + "GeneralNames must have at least one GeneralName."); |
|
172 | + } |
|
173 | + $elements = array_map( |
|
174 | + function (GeneralName $name) { |
|
175 | + return $name->toASN1(); |
|
176 | + }, $this->_names); |
|
177 | + return new Sequence(...$elements); |
|
178 | + } |
|
179 | 179 | |
180 | - /** |
|
181 | - * |
|
182 | - * @see \Countable::count() |
|
183 | - * @return int |
|
184 | - */ |
|
185 | - public function count(): int |
|
186 | - { |
|
187 | - return count($this->_names); |
|
188 | - } |
|
180 | + /** |
|
181 | + * |
|
182 | + * @see \Countable::count() |
|
183 | + * @return int |
|
184 | + */ |
|
185 | + public function count(): int |
|
186 | + { |
|
187 | + return count($this->_names); |
|
188 | + } |
|
189 | 189 | |
190 | - /** |
|
191 | - * Get iterator for GeneralName objects. |
|
192 | - * |
|
193 | - * @see \IteratorAggregate::getIterator() |
|
194 | - * @return \ArrayIterator |
|
195 | - */ |
|
196 | - public function getIterator(): \ArrayIterator |
|
197 | - { |
|
198 | - return new \ArrayIterator($this->_names); |
|
199 | - } |
|
190 | + /** |
|
191 | + * Get iterator for GeneralName objects. |
|
192 | + * |
|
193 | + * @see \IteratorAggregate::getIterator() |
|
194 | + * @return \ArrayIterator |
|
195 | + */ |
|
196 | + public function getIterator(): \ArrayIterator |
|
197 | + { |
|
198 | + return new \ArrayIterator($this->_names); |
|
199 | + } |
|
200 | 200 | } |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | "GeneralNames must have at least one GeneralName."); |
50 | 50 | } |
51 | 51 | $names = array_map( |
52 | - function (UnspecifiedType $el) { |
|
52 | + function(UnspecifiedType $el) { |
|
53 | 53 | return GeneralName::fromASN1($el->asTagged()); |
54 | 54 | }, $seq->elements()); |
55 | 55 | return new self(...$names); |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | public function allOf(int $tag): array |
108 | 108 | { |
109 | 109 | $names = array_filter($this->_names, |
110 | - function (GeneralName $name) use ($tag) { |
|
110 | + function(GeneralName $name) use ($tag) { |
|
111 | 111 | return $name->tag() == $tag; |
112 | 112 | }); |
113 | 113 | return array_values($names); |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | "GeneralNames must have at least one GeneralName."); |
172 | 172 | } |
173 | 173 | $elements = array_map( |
174 | - function (GeneralName $name) { |
|
174 | + function(GeneralName $name) { |
|
175 | 175 | return $name->toASN1(); |
176 | 176 | }, $this->_names); |
177 | 177 | return new Sequence(...$elements); |