| Total Complexity | 3 |
| Total Lines | 34 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 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) |
|
| 39 | } |
||
| 40 | } |
||
| 41 |