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