1 | <?php |
||
25 | final class ECKey extends Sequence |
||
26 | { |
||
27 | /** |
||
28 | * @var bool |
||
29 | */ |
||
30 | private $private = false; |
||
31 | |||
32 | /** |
||
33 | * @var array |
||
34 | */ |
||
35 | private $values = []; |
||
36 | |||
37 | /** |
||
38 | * @param \Jose\Object\JWKInterface|string|array $data |
||
39 | */ |
||
40 | public function __construct($data) |
||
55 | |||
56 | /** |
||
57 | * @param string $data |
||
58 | * |
||
59 | * @throws \Exception |
||
60 | * @throws \FG\ASN1\Exception\ParserException |
||
61 | * |
||
62 | * @return array |
||
63 | */ |
||
64 | private function loadPEM($data) |
||
65 | { |
||
66 | $data = base64_decode(preg_replace('#-.*-|\r|\n#', '', $data)); |
||
67 | $asnObject = ASNObject::fromBinary($data); |
||
68 | |||
69 | Assertion::isInstanceOf($asnObject, Sequence::class); |
||
70 | $children = $asnObject->getChildren(); |
||
|
|||
71 | if (self::isPKCS8($children)) { |
||
72 | $children = self::loadPKCS8($children); |
||
73 | } |
||
74 | |||
75 | if (4 === count($children)) { |
||
76 | return $this->loadPrivatePEM($children); |
||
77 | } elseif (2 === count($children)) { |
||
78 | return $this->loadPublicPEM($children); |
||
79 | } |
||
80 | |||
81 | throw new \Exception('Unable to load the key'); |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * @param array $children |
||
86 | * |
||
87 | * @return array |
||
88 | */ |
||
89 | private function loadPKCS8(array $children) |
||
97 | |||
98 | /** |
||
99 | * @param array $children |
||
100 | * |
||
101 | * @return bool |
||
102 | */ |
||
103 | private function isPKCS8(array $children) |
||
118 | |||
119 | /** |
||
120 | * @param array $jwk |
||
121 | */ |
||
122 | private function loadJWK(array $jwk) |
||
137 | |||
138 | private function initPublicKey() |
||
150 | |||
151 | private function initPrivateKey() |
||
165 | |||
166 | /** |
||
167 | * @param array $children |
||
168 | * |
||
169 | * @throws \Exception |
||
170 | * |
||
171 | * @return array |
||
172 | */ |
||
173 | private function loadPublicPEM(array $children) |
||
194 | |||
195 | /** |
||
196 | * @param \FG\ASN1\ASNObject $children |
||
197 | */ |
||
198 | private function verifyVersion(ASNObject $children) |
||
203 | |||
204 | /** |
||
205 | * @param \FG\ASN1\ASNObject $children |
||
206 | * @param string|null $x |
||
207 | * @param string|null $y |
||
208 | */ |
||
209 | private function getXAndY(ASNObject $children, &$x, &$y) |
||
223 | |||
224 | /** |
||
225 | * @param \FG\ASN1\ASNObject $children |
||
226 | * |
||
227 | * @return string |
||
228 | */ |
||
229 | private function getD(ASNObject $children) |
||
235 | |||
236 | /** |
||
237 | * @param array $children |
||
238 | * |
||
239 | * @return array |
||
240 | */ |
||
241 | private function loadPrivatePEM(array $children) |
||
262 | |||
263 | /** |
||
264 | * @return bool |
||
265 | */ |
||
266 | public function isPrivate() |
||
270 | |||
271 | /** |
||
272 | * @param \Jose\KeyConverter\ECKey $private |
||
273 | * |
||
274 | * @return \Jose\KeyConverter\ECKey |
||
275 | */ |
||
276 | public static function toPublic(ECKey $private) |
||
285 | |||
286 | /** |
||
287 | * @return string |
||
288 | */ |
||
289 | public function __toString() |
||
293 | |||
294 | /** |
||
295 | * @return array |
||
296 | */ |
||
297 | public function toArray() |
||
301 | |||
302 | /** |
||
303 | * @return string |
||
304 | */ |
||
305 | public function toDER() |
||
309 | |||
310 | /** |
||
311 | * @return string |
||
312 | */ |
||
313 | public function toPEM() |
||
321 | |||
322 | /** |
||
323 | * @param $curve |
||
324 | * |
||
325 | * @return string |
||
326 | */ |
||
327 | private function getOID($curve) |
||
336 | |||
337 | /** |
||
338 | * @param string $oid |
||
339 | * |
||
340 | * @return string |
||
341 | */ |
||
342 | private function getCurve($oid) |
||
350 | |||
351 | /** |
||
352 | * @return array |
||
353 | */ |
||
354 | private function getSupportedCurves() |
||
362 | } |
||
363 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: