Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/Symfony/Component/Security/Core/Util/SecureRandom.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ public function __construct($seedFile = null, LoggerInterface $logger = null)
$this->seedFile = $seedFile;
$this->logger = $logger;

$isUnsupportedPhp = '\\' === DIRECTORY_SEPARATOR && PHP_VERSION_ID < 50304;

// determine whether to use OpenSSL
if ('\\' === DIRECTORY_SEPARATOR && PHP_VERSION_ID < 50304) {
$this->useOpenSsl = false;
} elseif (!function_exists('openssl_random_pseudo_bytes')) {
if (!function_exists('random_bytes') && ($isUnsupportedPhp || !function_exists('openssl_random_pseudo_bytes'))) {
if (null !== $this->logger) {
$this->logger->notice('It is recommended that you enable the "openssl" extension for random number generation.');
$this->logger->notice('It is recommended that you install the "paragonie/random_compat" library or enable the "openssl" extension for random number generation.');
}
$this->useOpenSsl = false;
} else {
Expand All @@ -60,6 +60,10 @@ public function __construct($seedFile = null, LoggerInterface $logger = null)
*/
public function nextBytes($nbBytes)
{
if (function_exists('random_bytes')) {
return random_bytes($nbBytes);
}

// try OpenSSL
if ($this->useOpenSsl) {
$bytes = openssl_random_pseudo_bytes($nbBytes, $strong);
Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Component/Security/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"symfony/validator": "",
"symfony/routing": "",
"doctrine/dbal": "to use the built-in ACL implementation",
"ircmaxell/password-compat": ""
"ircmaxell/password-compat": "",
"paragonie/random_compat": ""
},
"autoload": {
"psr-0": { "Symfony\\Component\\Security\\": "" }
Expand Down