HMAC   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 85.71%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 29
wmc 3
lcom 0
cbo 0
ccs 6
cts 7
cp 0.8571
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A sign() 0 4 1
A verify() 0 10 2
hashingAlgorithm() 0 1 ?
1
<?php
2
3
namespace Zenstruck\JWT\Signer;
4
5
use Zenstruck\JWT\Signer;
6
7
/**
8
 * @author Alessandro Nadalin <[email protected]>
9
 * @author Kevin Bond <[email protected]>
10
 */
11
abstract class HMAC implements Signer
12
{
13
    /**
14
     * {@inheritdoc}
15
     */
16 7
    public function sign($input, $key)
17
    {
18 7
        return hash_hmac($this->hashingAlgorithm(), $input, (string) $key, true);
19
    }
20
21
    /**
22
     * {@inheritdoc}
23
     */
24 6
    public function verify($input, $signature, $key)
25
    {
26 6
        if (!function_exists('hash_equals')) {
27
            throw new \RuntimeException('hash_equals is only available in PHP 5.6+, install symfony/polyfill-php56 in PHP 5.4/5.5');
28
        }
29
30 6
        $signedInput = $this->sign($input, $key);
31
32 6
        return hash_equals($signedInput, $signature);
33
    }
34
35
    /**
36
     * @return string
37
     */
38
    abstract protected function hashingAlgorithm();
39
}
40