| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
* This file is part of the Symfony package. |
| 5 |
* |
| 6 |
* (c) Fabien Potencier <[email protected]> |
| 7 |
* |
| 8 |
* For the full copyright and license information, please view the LICENSE |
| 9 |
* file that was distributed with this source code. |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace Symfony\Polyfill\Php82\Random\Engine; |
| 13 |
|
| 14 |
use Random\RandomException; |
| 15 |
use Symfony\Polyfill\Php82\NoDynamicProperties; |
| 16 |
|
| 17 |
/** |
| 18 |
* @author Tim Düsterhus <[email protected]> |
| 19 |
* @author Anton Smirnov <[email protected]> |
| 20 |
* |
| 21 |
* @internal |
| 22 |
*/ |
| 23 |
class Secure |
| 24 |
{ |
| 25 |
use NoDynamicProperties; |
| 26 |
|
| 27 |
public function generate(): string |
| 28 |
{ |
| 29 |
try { |
| 30 |
return random_bytes(\PHP_INT_SIZE); |
| 31 |
} catch (\Exception $e) { |
| 32 |
throw new RandomException($e->getMessage(), $e->getCode(), $e->getPrevious()); |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
public function __sleep(): array |
| 37 |
{ |
| 38 |
throw new \Exception("Serialization of 'Random\Engine\Secure' is not allowed"); |
| 39 |
} |
| 40 |
|
| 41 |
public function __wakeup(): void |
| 42 |
{ |
| 43 |
throw new \Exception("Unserialization of 'Random\Engine\Secure' is not allowed"); |
| 44 |
} |
| 45 |
|
| 46 |
public function __clone() |
| 47 |
{ |
| 48 |
throw new \Error('Trying to clone an uncloneable object of class Random\Engine\Secure'); |
| 49 |
} |
| 50 |
} |