Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| SignatureGenerator | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 1 |
| generate | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace oat\tao\model\security; |
| 4 | |
| 5 | use oat\oatbox\service\ConfigurableService; |
| 6 | use oat\tao\model\metadata\exception\InconsistencyConfigException; |
| 7 | |
| 8 | class SignatureGenerator extends ConfigurableService |
| 9 | { |
| 10 | public const SERVICE_ID = 'tao/SignatureGenerator'; |
| 11 | |
| 12 | public const OPTION_SALT = 'salt'; |
| 13 | |
| 14 | /** |
| 15 | * @param string[] $dataToSign |
| 16 | * |
| 17 | * @return string |
| 18 | * |
| 19 | * @throws InconsistencyConfigException |
| 20 | */ |
| 21 | public function generate(...$dataToSign) |
| 22 | { |
| 23 | $salt = $this->getOption(self::OPTION_SALT); |
| 24 | |
| 25 | if (empty($salt)) { |
| 26 | throw new InconsistencyConfigException(sprintf('Option %s is not defined', self::OPTION_SALT)); |
| 27 | } |
| 28 | |
| 29 | $dataToCheck = json_encode($dataToSign); |
| 30 | |
| 31 | return hash('sha256', $salt . $dataToCheck . $salt); |
| 32 | } |
| 33 | } |