Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame^] | 1 | <?php |
| 2 | |
| 3 | namespace Tests\Providers\Rng; |
| 4 | |
| 5 | use RobThree\Auth\Providers\Rng\IRNGProvider; |
| 6 | |
| 7 | class TestRNGProvider implements IRNGProvider |
| 8 | { |
| 9 | /** @var bool */ |
| 10 | private $isSecure; |
| 11 | |
| 12 | /** |
| 13 | * @param bool $isSecure whether this provider is cryptographically secure |
| 14 | */ |
| 15 | function __construct($isSecure = false) |
| 16 | { |
| 17 | $this->isSecure = $isSecure; |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * {@inheritdoc} |
| 22 | */ |
| 23 | public function getRandomBytes($bytecount) |
| 24 | { |
| 25 | $result = ''; |
| 26 | |
| 27 | for ($i = 0; $i < $bytecount; $i++) { |
| 28 | $result .= chr($i); |
| 29 | } |
| 30 | |
| 31 | return $result; |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * {@inheritdoc} |
| 36 | */ |
| 37 | public function isCryptographicallySecure() |
| 38 | { |
| 39 | return $this->isSecure; |
| 40 | } |
| 41 | } |