Digest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
dl 0
loc 34
ccs 8
cts 8
cp 1
rs 10
c 1
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A hash() 0 3 1
A __construct() 0 3 1
A sign() 0 7 1
1
<?php
2
3
namespace Acquia\Hmac\Digest;
4
5
class Digest implements DigestInterface
6
{
7
    /**
8
     * @var string
9
     */
10
    protected $algorithm;
11
12
    /**
13
     * @param string $algorithm
14
     */
15 28
    public function __construct($algorithm = 'sha256')
16
    {
17 28
        $this->algorithm = $algorithm;
18 28
    }
19
20
    /**
21
     * {@inheritDoc}
22
     */
23 21
    public function sign($message, $secretKey)
24
    {
25
        // The Acquia HMAC spec requires that we use MIME Base64 encoded
26
        // secrets, but PHP requires them to be decoded before signing.
27 21
        $digest = hash_hmac($this->algorithm, $message, base64_decode($secretKey, true), true);
28
29 21
        return base64_encode($digest);
30
    }
31
32
33
    /**
34
     * {@inheritDoc}
35
     */
36 6
    public function hash($message)
37
    {
38 6
        return base64_encode(hash($this->algorithm, $message, true));
39
    }
40
}
41