From d899b7988d1cedd8659237a2afc5d8d3e1eb2631 Mon Sep 17 00:00:00 2001 From: Scott Date: Fri, 9 Oct 2015 15:19:59 -0400 Subject: [PATCH] Update random_bytes() to conform to PHP7.0.0-RC3 Fixes #843 --- phpseclib/Crypt/Random.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/phpseclib/Crypt/Random.php b/phpseclib/Crypt/Random.php index 0bee3c45..586bd6c4 100644 --- a/phpseclib/Crypt/Random.php +++ b/phpseclib/Crypt/Random.php @@ -55,9 +55,10 @@ class Random { 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. + return \random_bytes($length); + } catch (\Throwable $e) { + // If a sufficient source of randomness is unavailable, random_bytes() will throw an + // object that implements the Throwable interface (Exception, TypeError, Error). // 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