|
|
@@ -1,6 +1,6 @@
|
|
|
<?php
|
|
|
/**
|
|
|
- * Copyright 2016 Facebook, Inc.
|
|
|
+ * Copyright 2017 Facebook, Inc.
|
|
|
*
|
|
|
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
|
|
|
* use, copy, modify, and distribute this software in source code or binary
|
|
|
@@ -38,7 +38,7 @@ class PseudoRandomStringGeneratorFactory
|
|
|
*
|
|
|
* @param PseudoRandomStringGeneratorInterface|string|null $generator
|
|
|
*
|
|
|
- * @throws InvalidArgumentException If the pseudo random string generator must be set to "mcrypt", "openssl", or "urandom", or be an instance of Facebook\PseudoRandomString\PseudoRandomStringGeneratorInterface.
|
|
|
+ * @throws InvalidArgumentException If the pseudo random string generator must be set to "random_bytes", "mcrypt", "openssl", or "urandom", or be an instance of Facebook\PseudoRandomString\PseudoRandomStringGeneratorInterface.
|
|
|
*
|
|
|
* @return PseudoRandomStringGeneratorInterface
|
|
|
*/
|
|
|
@@ -52,6 +52,9 @@ class PseudoRandomStringGeneratorFactory
|
|
|
return $generator;
|
|
|
}
|
|
|
|
|
|
+ if ('random_bytes' === $generator) {
|
|
|
+ return new RandomBytesPseudoRandomStringGenerator();
|
|
|
+ }
|
|
|
if ('mcrypt' === $generator) {
|
|
|
return new McryptPseudoRandomStringGenerator();
|
|
|
}
|
|
|
@@ -62,7 +65,7 @@ class PseudoRandomStringGeneratorFactory
|
|
|
return new UrandomPseudoRandomStringGenerator();
|
|
|
}
|
|
|
|
|
|
- throw new InvalidArgumentException('The pseudo random string generator must be set to "mcrypt", "openssl", or "urandom", or be an instance of Facebook\PseudoRandomString\PseudoRandomStringGeneratorInterface');
|
|
|
+ throw new InvalidArgumentException('The pseudo random string generator must be set to "random_bytes", "mcrypt", "openssl", or "urandom", or be an instance of Facebook\PseudoRandomString\PseudoRandomStringGeneratorInterface');
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -74,8 +77,13 @@ class PseudoRandomStringGeneratorFactory
|
|
|
*/
|
|
|
private static function detectDefaultPseudoRandomStringGenerator()
|
|
|
{
|
|
|
+ // Check for PHP 7's CSPRNG first to keep mcrypt deprecation messages from appearing in PHP 7.1.
|
|
|
+ if (function_exists('random_bytes')) {
|
|
|
+ return new RandomBytesPseudoRandomStringGenerator();
|
|
|
+ }
|
|
|
+
|
|
|
// Since openssl_random_pseudo_bytes() can sometimes return non-cryptographically
|
|
|
- // secure pseudo-random strings (in rare cases), we check for mcrypt_create_iv() first.
|
|
|
+ // secure pseudo-random strings (in rare cases), we check for mcrypt_create_iv() next.
|
|
|
if (function_exists('mcrypt_create_iv')) {
|
|
|
return new McryptPseudoRandomStringGenerator();
|
|
|
}
|