1 | <?php |
||
13 | class PublicKey extends Key implements PublicKeyInterface |
||
14 | { |
||
15 | /** |
||
16 | * @var EcAdapter |
||
17 | */ |
||
18 | private $ecAdapter; |
||
19 | |||
20 | /** |
||
21 | * @var bool|false |
||
22 | */ |
||
23 | private $compressed; |
||
24 | |||
25 | /** |
||
26 | * @var resource |
||
27 | */ |
||
28 | private $pubkey_t; |
||
29 | |||
30 | /** |
||
31 | * @param EcAdapter $ecAdapter |
||
32 | * @param resource $secp256k1_pubkey_t |
||
33 | * @param bool|false $compressed |
||
34 | */ |
||
35 | 133 | public function __construct(EcAdapter $ecAdapter, $secp256k1_pubkey_t, $compressed = false) |
|
50 | |||
51 | /** |
||
52 | * @param BufferInterface $msg32 |
||
53 | * @param SignatureInterface $signature |
||
54 | * @return bool |
||
55 | */ |
||
56 | public function verify(BufferInterface $msg32, SignatureInterface $signature) |
||
60 | |||
61 | /** |
||
62 | * @param PublicKey $other |
||
63 | * @return bool |
||
64 | */ |
||
65 | 6 | private function doEquals(self $other) |
|
66 | { |
||
67 | 6 | $context = $this->ecAdapter->getContext(); |
|
68 | 6 | $pubA = ''; |
|
69 | 6 | $pubB = ''; |
|
70 | 6 | if (!(secp256k1_ec_pubkey_serialize($context, $pubA, $this->pubkey_t, $this->compressed) && secp256k1_ec_pubkey_serialize($context, $pubB, $other->pubkey_t, $this->compressed))) { |
|
71 | throw new \RuntimeException('Unable to serialize public key during equals'); |
||
72 | } |
||
73 | |||
74 | 6 | return hash_equals($pubA, $pubB); |
|
75 | } |
||
76 | |||
77 | /** |
||
78 | * @param PublicKeyInterface $other |
||
79 | * @return bool |
||
80 | */ |
||
81 | 6 | public function equals(PublicKeyInterface $other) |
|
82 | { |
||
83 | /** @var self $other */ |
||
84 | 6 | return $this->doEquals($other); |
|
|
|||
85 | } |
||
86 | |||
87 | /** |
||
88 | * @return bool|false |
||
89 | */ |
||
90 | 119 | public function isCompressed() |
|
94 | |||
95 | /** |
||
96 | * @return resource |
||
97 | */ |
||
98 | 115 | public function getResource() |
|
102 | |||
103 | /** |
||
104 | * @return resource |
||
105 | * @throws \Exception |
||
106 | */ |
||
107 | 5 | private function clonePubkey() |
|
123 | |||
124 | /** |
||
125 | * @param \GMP $tweak |
||
126 | * @return PublicKey |
||
127 | * @throws \Exception |
||
128 | */ |
||
129 | 4 | public function tweakAdd(\GMP $tweak) |
|
141 | |||
142 | /** |
||
143 | * @param \GMP $tweak |
||
144 | * @return PublicKey |
||
145 | * @throws \Exception |
||
146 | */ |
||
147 | 1 | public function tweakMul(\GMP $tweak) |
|
159 | |||
160 | /** |
||
161 | * @return BufferInterface |
||
162 | */ |
||
163 | 104 | public function getBuffer() |
|
167 | } |
||
168 |
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: