Completed
Push — develop ( 23fb07...aaf888 )
by Fabian
13s queued 11s
created

Signer::createSignature()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 8
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 11
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cakasim\Payone\Sdk\Redirect\Token\Format;
6
7
use Cakasim\Payone\Sdk\Config\ConfigExceptionInterface;
8
use Cakasim\Payone\Sdk\Config\ConfigInterface;
9
10
/**
11
 * @author Fabian Böttcher <[email protected]>
12
 * @since 0.1.0
13
 */
14
class Signer implements SignerInterface
15
{
16
    /**
17
     * @var ConfigInterface The SDK config.
18
     */
19
    protected $config;
20
21
    /**
22
     * Constructs the token signer.
23
     *
24
     * @param ConfigInterface $config The SDK config.
25
     */
26
    public function __construct(ConfigInterface $config)
27
    {
28
        $this->config = $config;
29
    }
30
31
    /**
32
     * @inheritDoc
33
     */
34
    public function createSignature(string $data): string
35
    {
36
        try {
37
            return hash_hmac(
38
                $this->config->get('redirect.token_signing_algo'),
39
                $data,
40
                $this->config->get('redirect.token_signing_key'),
41
                true
42
            );
43
        } catch (ConfigExceptionInterface $e) {
44
            throw new SignerException("Failed signing of provided data.", 0, $e);
45
        }
46
    }
47
}
48