1 | <?php |
||
11 | class HashHmac |
||
12 | { |
||
13 | |||
14 | /** |
||
15 | * Hashing Algorithm. |
||
16 | * |
||
17 | * @var string |
||
18 | */ |
||
19 | private $algorithm; |
||
20 | |||
21 | /** |
||
22 | * Private Key. |
||
23 | * |
||
24 | * @var string |
||
25 | */ |
||
26 | private $privateKey; |
||
27 | |||
28 | /** |
||
29 | * Payload Data. |
||
30 | * |
||
31 | * @var array |
||
32 | */ |
||
33 | private $payload = []; |
||
34 | |||
35 | /** |
||
36 | * Date Time Zone. |
||
37 | * |
||
38 | * @var \DateTimeZone |
||
39 | */ |
||
40 | private $timezone; |
||
41 | |||
42 | /** |
||
43 | * @param string $privateKey |
||
44 | * @param string $algo |
||
45 | * @param string $timezone |
||
46 | */ |
||
47 | public function __construct($privateKey, $algo = 'sha512', $timezone = 'UTC') |
||
53 | 13 | ||
54 | |||
55 | 13 | /** |
|
56 | 13 | * Create Hash Hmac from payload. |
|
57 | 13 | * |
|
58 | 13 | * @param array $payload |
|
59 | * @return string |
||
60 | */ |
||
61 | public function create(array $payload = []){ |
||
65 | 4 | ||
66 | /** |
||
67 | * Internal Function to creates hash from payload. |
||
68 | 4 | * |
|
69 | * @param array $payload |
||
70 | 4 | * @return mixed |
|
71 | 4 | */ |
|
72 | 4 | private function generate($algorithm, array $payload = [], $privateKey) |
|
82 | |||
83 | /** |
||
84 | * Compare received hash against payload. |
||
85 | * |
||
86 | * @param $encodedHash |
||
87 | * @param array $payload |
||
88 | * @return bool |
||
89 | * @throws \Exception |
||
90 | */ |
||
91 | 3 | public function verify($encodedHash, array $payload = []) |
|
109 | |||
110 | /** |
||
111 | * With Private Key. |
||
112 | * |
||
113 | * @param string $key |
||
114 | 1 | * @return $this |
|
115 | */ |
||
116 | 1 | public function withPrivateKey(string $key) |
|
122 | |||
123 | /** |
||
124 | * With Payload Data |
||
125 | * |
||
126 | 1 | * @param array $payload |
|
127 | * @return $this |
||
128 | 1 | */ |
|
129 | public function withPayload(array $payload) |
||
135 | |||
136 | /** |
||
137 | * Return current Algorithm |
||
138 | * |
||
139 | * @return string |
||
140 | */ |
||
141 | 2 | public function getAlgorithm() |
|
145 | |||
146 | |||
147 | /** |
||
148 | * Return active payload. |
||
149 | * |
||
150 | * @return array |
||
151 | */ |
||
152 | 7 | public function getPayload(){ |
|
155 | 1 | ||
156 | /** |
||
157 | 6 | * Returns Private Key |
|
158 | 6 | * |
|
159 | 6 | * @return string |
|
160 | 3 | */ |
|
161 | public function getPrivateKey() |
||
165 | 5 | ||
166 | /** |
||
167 | 5 | * @param string $hash |
|
168 | 5 | * @param string $payloadHash |
|
169 | 3 | * @return bool |
|
170 | 3 | * @throws \Exception |
|
171 | */ |
||
172 | 5 | private function verifyHash($hash = '', $payloadHash = '') |
|
187 | |||
188 | /** |
||
189 | * @param $algo |
||
190 | * @return string |
||
191 | * @throws \Exception |
||
192 | */ |
||
193 | private function verifyAlgorithm($algo) |
||
204 | } |
||
205 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..