mirror of
https://github.com/phpseclib/phpseclib.git
synced 2024-11-09 15:20:58 +00:00
Merge branch '2.0'
* 2.0: Backport to 2.0: Add PHP7 to Travis CI. Remove duplicate allow_failures section Test on PHP 7 & allow failures Coding standards fix Switch from EngineException to Error Remove string assignment Use random_bytes() when appropriate.
This commit is contained in:
commit
618215dd0d
@ -54,6 +54,18 @@ class Random
|
|||||||
*/
|
*/
|
||||||
public static function string($length)
|
public static function string($length)
|
||||||
{
|
{
|
||||||
|
if (version_compare(PHP_VERSION, '7.0.0', '>=')) {
|
||||||
|
try {
|
||||||
|
return random_bytes($length);
|
||||||
|
} catch (\Error $e) {
|
||||||
|
// If a sufficient source of randomness is unavailable, random_bytes() will emit a warning.
|
||||||
|
// We don't actually need to do anything here. The string() method should just continue
|
||||||
|
// as normal. Note, however, that if we don't have a sufficient source of randomness for
|
||||||
|
// random_bytes(), most of the other calls here will fail too, so we'll end up using
|
||||||
|
// the PHP implementation.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
|
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
|
||||||
// method 1. prior to PHP 5.3 this would call rand() on windows hence the function_exists('class_alias') call.
|
// method 1. prior to PHP 5.3 this would call rand() on windows hence the function_exists('class_alias') call.
|
||||||
// ie. class_alias is a function that was introduced in PHP 5.3
|
// ie. class_alias is a function that was introduced in PHP 5.3
|
||||||
|
Loading…
Reference in New Issue
Block a user