Analyzer.php
1 year ago
ClosureContext.php
2 years ago
ClosureScope.php
2 years ago
ClosureStream.php
1 year ago
ISecurityProvider.php
2 years ago
ReflectionClosure.php
1 year ago
SecurityException.php
2 years ago
SecurityProvider.php
1 year ago
SelfReference.php
2 years ago
SerializableClosure.php
1 year ago
SecurityProvider.php
37 lines
| 1 | <?php |
| 2 | |
| 3 | /* =========================================================================== |
| 4 | * Copyright (c) 2018-2021 Zindex Software |
| 5 | * |
| 6 | * Licensed under the MIT License |
| 7 | * =========================================================================== */ |
| 8 | namespace Matomo\Dependencies\Opis\Closure; |
| 9 | |
| 10 | class SecurityProvider implements ISecurityProvider |
| 11 | { |
| 12 | /** @var string */ |
| 13 | protected $secret; |
| 14 | /** |
| 15 | * SecurityProvider constructor. |
| 16 | * @param string $secret |
| 17 | */ |
| 18 | public function __construct($secret) |
| 19 | { |
| 20 | $this->secret = $secret; |
| 21 | } |
| 22 | /** |
| 23 | * @inheritdoc |
| 24 | */ |
| 25 | public function sign($closure) |
| 26 | { |
| 27 | return array('closure' => $closure, 'hash' => base64_encode(hash_hmac('sha256', $closure, $this->secret, \true))); |
| 28 | } |
| 29 | /** |
| 30 | * @inheritdoc |
| 31 | */ |
| 32 | public function verify(array $data) |
| 33 | { |
| 34 | return base64_encode(hash_hmac('sha256', $data['closure'], $this->secret, \true)) === $data['hash']; |
| 35 | } |
| 36 | } |
| 37 |