1 | <?php |
||
23 | abstract class HMAC implements SignatureAlgorithmInterface |
||
24 | { |
||
25 | /** |
||
26 | * {@inheritdoc} |
||
27 | */ |
||
28 | public function sign(JWKInterface $key, $input) |
||
29 | { |
||
30 | $this->checkKey($key); |
||
31 | |||
32 | return hash_hmac($this->getHashAlgorithm(), $input, Base64Url::decode($key->get('k')), true); |
||
33 | } |
||
34 | |||
35 | /** |
||
36 | * {@inheritdoc} |
||
37 | */ |
||
38 | public function verify(JWKInterface $key, $input, $signature) |
||
39 | { |
||
40 | return hash_equals($this->sign($key, $input), $signature); |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * @param JWKInterface $key |
||
45 | */ |
||
46 | protected function checkKey(JWKInterface $key) |
||
51 | |||
52 | /** |
||
53 | * @return string |
||
54 | */ |
||
55 | abstract protected function getHashAlgorithm(); |
||
56 | } |
||
57 |