Bump PHP version requirement to 7.0.0+
[lhc/web/wiklou.git] / includes / libs / CryptRand.php
index 0d3613a..474c564 100644 (file)
@@ -94,9 +94,9 @@ class CryptRand {
                $files[] = dirname( __DIR__ );
 
                foreach ( $files as $file ) {
-                       MediaWiki\suppressWarnings();
+                       Wikimedia\suppressWarnings();
                        $stat = stat( $file );
-                       MediaWiki\restoreWarnings();
+                       Wikimedia\restoreWarnings();
                        if ( $stat ) {
                                // stat() duplicates data into numeric and string keys so kill off all the numeric ones
                                foreach ( $stat as $k => $v ) {
@@ -234,7 +234,6 @@ class CryptRand {
         * @return string Raw binary random data
         */
        public function generate( $bytes, $forceStrong = false ) {
-
                $bytes = floor( $bytes );
                static $buffer = '';
                if ( is_null( $this->strong ) ) {
@@ -247,8 +246,11 @@ class CryptRand {
                        // On Linux, getrandom syscall will be used if available.
                        // On Windows CryptGenRandom will always be used
                        // On other platforms, /dev/urandom will be used.
+                       // Avoids polyfills from before php 7.0
                        // All error situations will throw Exceptions and or Errors
-                       if ( function_exists( 'random_bytes' ) ) {
+                       if ( PHP_VERSION_ID >= 70000
+                               || ( defined( 'HHVM_VERSION_ID' ) && HHVM_VERSION_ID >= 31101 )
+                       ) {
                                $rem = $bytes - strlen( $buffer );
                                $buffer .= random_bytes( $rem );
                        }
@@ -308,9 +310,9 @@ class CryptRand {
                        }
                        // /dev/urandom is generally considered the best possible commonly
                        // available random source, and is available on most *nix systems.
-                       MediaWiki\suppressWarnings();
+                       Wikimedia\suppressWarnings();
                        $urandom = fopen( "/dev/urandom", "rb" );
-                       MediaWiki\restoreWarnings();
+                       Wikimedia\restoreWarnings();
 
                        // Attempt to read all our random data from urandom
                        // php's fread always does buffered reads based on the stream's chunk_size