1 | <?php |
||
20 | class Certificate |
||
21 | { |
||
22 | /** |
||
23 | * "To be signed" certificate information. |
||
24 | * |
||
25 | * @var TBSCertificate $_tbsCertificate |
||
26 | */ |
||
27 | protected $_tbsCertificate; |
||
28 | |||
29 | /** |
||
30 | * Signature algorithm. |
||
31 | * |
||
32 | * @var SignatureAlgorithmIdentifier $_signatureAlgorithm |
||
33 | */ |
||
34 | protected $_signatureAlgorithm; |
||
35 | |||
36 | /** |
||
37 | * Signature value. |
||
38 | * |
||
39 | * @var Signature $_signatureValue |
||
40 | */ |
||
41 | protected $_signatureValue; |
||
42 | |||
43 | /** |
||
44 | * Constructor |
||
45 | * |
||
46 | * @param TBSCertificate $tbsCert |
||
47 | * @param SignatureAlgorithmIdentifier $algo |
||
48 | * @param Signature $signature |
||
49 | */ |
||
50 | 20 | public function __construct(TBSCertificate $tbsCert, |
|
56 | |||
57 | /** |
||
58 | * Initialize from ASN.1. |
||
59 | * |
||
60 | * @param Sequence $seq |
||
61 | * @return self |
||
62 | */ |
||
63 | 11 | public static function fromASN1(Sequence $seq) { |
|
64 | 11 | $tbsCert = TBSCertificate::fromASN1($seq->at(0)->asSequence()); |
|
65 | 11 | $algo = AlgorithmIdentifier::fromASN1($seq->at(1)->asSequence()); |
|
66 | 11 | if (!$algo instanceof SignatureAlgorithmIdentifier) { |
|
67 | 1 | throw new \UnexpectedValueException( |
|
68 | 1 | "Unsupported signature algorithm " . $algo->oid() . "."); |
|
69 | } |
||
70 | 10 | $signature = Signature::fromASN1($seq->at(2)->asBitString()); |
|
71 | 10 | return new self($tbsCert, $algo, $signature); |
|
72 | } |
||
73 | |||
74 | /** |
||
75 | * Initialize from DER. |
||
76 | * |
||
77 | * @param string $data |
||
78 | * @return self |
||
79 | */ |
||
80 | 9 | public static function fromDER($data) { |
|
83 | |||
84 | /** |
||
85 | * Initialize from PEM. |
||
86 | * |
||
87 | * @param PEM $pem |
||
88 | * @throws \UnexpectedValueException |
||
89 | * @return self |
||
90 | */ |
||
91 | 10 | public static function fromPEM(PEM $pem) { |
|
97 | |||
98 | /** |
||
99 | * Get certificate information. |
||
100 | * |
||
101 | * @return TBSCertificate |
||
102 | */ |
||
103 | 49 | public function tbsCertificate() { |
|
106 | |||
107 | /** |
||
108 | * Get signature algorithm. |
||
109 | * |
||
110 | * @return SignatureAlgorithmIdentifier |
||
111 | */ |
||
112 | 28 | public function signatureAlgorithm() { |
|
115 | |||
116 | /** |
||
117 | * Get signature value. |
||
118 | * |
||
119 | * @return Signature |
||
120 | */ |
||
121 | 2 | public function signatureValue() { |
|
124 | |||
125 | /** |
||
126 | * Check whether certificate is self-issued. |
||
127 | * |
||
128 | * @return bool |
||
129 | */ |
||
130 | 28 | public function isSelfIssued() { |
|
134 | |||
135 | /** |
||
136 | * Check whether certificate is semantically equal to another. |
||
137 | * |
||
138 | * @param Certificate $cert Certificate to compare to |
||
139 | * @return bool |
||
140 | */ |
||
141 | 11 | public function equals(Certificate $cert) { |
|
156 | |||
157 | /** |
||
158 | * Generate ASN.1 structure. |
||
159 | * |
||
160 | * @return Sequence |
||
161 | */ |
||
162 | 4 | public function toASN1() { |
|
167 | |||
168 | /** |
||
169 | * Get certificate as a DER. |
||
170 | * |
||
171 | * @return string |
||
172 | */ |
||
173 | 2 | public function toDER() { |
|
176 | |||
177 | /** |
||
178 | * Get certificate as a PEM. |
||
179 | * |
||
180 | * @return PEM |
||
181 | */ |
||
182 | 2 | public function toPEM() { |
|
185 | |||
186 | /** |
||
187 | * Verify certificate signature. |
||
188 | * |
||
189 | * @param Crypto $crypto |
||
190 | * @param PublicKeyInfo $pubkey_info Issuer's public key |
||
191 | * @return bool True if certificate signature is valid |
||
192 | */ |
||
193 | 24 | public function verify(Crypto $crypto, PublicKeyInfo $pubkey_info) { |
|
198 | |||
199 | /** |
||
200 | * Get certificate as a PEM formatted string. |
||
201 | * |
||
202 | * @return string |
||
203 | */ |
||
204 | 1 | public function __toString() { |
|
207 | } |
||
208 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: