1 | <?php declare(strict_types=1); |
||
9 | class HmacGenerator |
||
10 | { |
||
11 | // see https://secure.php.net/manual/en/function.hash-hmac-algos.php |
||
12 | private const DEFAULT_HASHING_ALGORITHM = 'sha256'; |
||
13 | |||
14 | /** |
||
15 | * @var string |
||
16 | */ |
||
17 | private $secretKey; |
||
18 | |||
19 | /** |
||
20 | * Transforms a request into a data string used by the hash_mac function. The default transfomer builds the |
||
21 | * data string in the format "%method% %uri%\n%content%". Inject your own transformer if you want to support |
||
22 | * a different data string. |
||
23 | * |
||
24 | * @var HmacDataTransformerInterface |
||
25 | */ |
||
26 | private $hmacDataTransformer; |
||
27 | |||
28 | 3 | public function __construct(string $key, HmacDataTransformerInterface $hmacDataTransformer = null) |
|
42 | |||
43 | 3 | public function generateHmac(string $data, string $hashingAlgorithm = self::DEFAULT_HASHING_ALGORITHM): string |
|
55 | |||
56 | 2 | public function generateHmacForRequest(RequestAdapterInterface $request): string |
|
62 | } |
||
63 |