Total Complexity | 6 |
Total Lines | 26 |
Duplicated Lines | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 2 |
1 | <?php |
||
6 | class NonceGenerator { |
||
7 | |||
8 | private array $nonces = []; |
||
9 | |||
10 | private $onNonce; |
||
11 | |||
12 | public function __construct(?callable $onNonce) { |
||
14 | } |
||
15 | |||
16 | protected function _generateNonce(string $name, ?int $value = null): string { |
||
17 | $bytes = \random_bytes((int) ($value ?? 32)); |
||
18 | $nonce = \base64_encode($bytes); |
||
19 | if (isset($this->onNonce) && ! URequest::isAjax()) { |
||
20 | $onNonce=$this->onNonce; |
||
21 | $onNonce($name, $nonce); |
||
22 | } |
||
23 | return $nonce; |
||
24 | } |
||
25 | |||
26 | public function getNonce(string $name,int $size=32) { |
||
28 | } |
||
29 | |||
30 | public function __toString(){ |
||
35 |