Update Random_Compat to master.

This update mostly concerns OpenSSL being unusable on PHP 5.3~5.3.3.
See #28633, #34409


git-svn-id: https://develop.svn.wordpress.org/trunk@35410 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dion Hulse 2015-10-28 01:11:57 +00:00
parent 60f6db0c06
commit fb109971e4
1 changed files with 22 additions and 14 deletions

View File

@ -30,16 +30,16 @@ if (!defined('PHP_VERSION_ID')) {
// This constant was introduced in PHP 5.2.7 // This constant was introduced in PHP 5.2.7
$RandomCompatversion = explode('.', PHP_VERSION); $RandomCompatversion = explode('.', PHP_VERSION);
define('PHP_VERSION_ID', ($RandomCompatversion[0] * 10000 + $RandomCompatversion[1] * 100 + $RandomCompatversion[2])); define('PHP_VERSION_ID', ($RandomCompatversion[0] * 10000 + $RandomCompatversion[1] * 100 + $RandomCompatversion[2]));
unset($RandomCompatversion); $RandomCompatversion = null;
} }
if (PHP_VERSION_ID < 70000) { if (PHP_VERSION_ID < 70000) {
if (!defined('RANDOM_COMPAT_READ_BUFFER')) { if (!defined('RANDOM_COMPAT_READ_BUFFER')) {
define('RANDOM_COMPAT_READ_BUFFER', 8); define('RANDOM_COMPAT_READ_BUFFER', 8);
} }
$__DIR__ = dirname(__FILE__); $RandomCompatDIR = dirname(__FILE__);
require_once $__DIR__.'/byte_safe_strings.php'; require_once $RandomCompatDIR.'/byte_safe_strings.php';
require_once $__DIR__.'/cast_to_int.php'; require_once $RandomCompatDIR.'/cast_to_int.php';
require_once $__DIR__.'/error_polyfill.php'; require_once $RandomCompatDIR.'/error_polyfill.php';
if (!function_exists('random_bytes')) { if (!function_exists('random_bytes')) {
/** /**
* PHP 5.2.0 - 5.6.x way to implement random_bytes() * PHP 5.2.0 - 5.6.x way to implement random_bytes()
@ -58,7 +58,7 @@ if (PHP_VERSION_ID < 70000) {
*/ */
if (extension_loaded('libsodium')) { if (extension_loaded('libsodium')) {
// See random_bytes_libsodium.php // See random_bytes_libsodium.php
require_once $__DIR__.'/random_bytes_libsodium.php'; require_once $RandomCompatDIR.'/random_bytes_libsodium.php';
} }
if ( if (
!function_exists('random_bytes') && !function_exists('random_bytes') &&
@ -75,7 +75,7 @@ if (PHP_VERSION_ID < 70000) {
// that is not helpful to us here. // that is not helpful to us here.
// See random_bytes_dev_urandom.php // See random_bytes_dev_urandom.php
require_once $__DIR__.'/random_bytes_dev_urandom.php'; require_once $RandomCompatDIR.'/random_bytes_dev_urandom.php';
} }
if ( if (
!function_exists('random_bytes') && !function_exists('random_bytes') &&
@ -83,7 +83,7 @@ if (PHP_VERSION_ID < 70000) {
extension_loaded('mcrypt') extension_loaded('mcrypt')
) { ) {
// See random_bytes_mcrypt.php // See random_bytes_mcrypt.php
require_once $__DIR__.'/random_bytes_mcrypt.php'; require_once $RandomCompatDIR.'/random_bytes_mcrypt.php';
} }
if ( if (
!function_exists('random_bytes') && !function_exists('random_bytes') &&
@ -94,20 +94,28 @@ if (PHP_VERSION_ID < 70000) {
$RandomCompatCOMtest = new COM('CAPICOM.Utilities.1'); $RandomCompatCOMtest = new COM('CAPICOM.Utilities.1');
if (method_exists($RandomCompatCOMtest, 'GetRandom')) { if (method_exists($RandomCompatCOMtest, 'GetRandom')) {
// See random_bytes_com_dotnet.php // See random_bytes_com_dotnet.php
require_once $__DIR__.'/random_bytes_com_dotnet.php'; require_once $RandomCompatDIR.'/random_bytes_com_dotnet.php';
} }
} catch (com_exception $e) { } catch (com_exception $e) {
// Don't try to use it. // Don't try to use it.
} }
unset($RandomCompatCOMtest); $RandomCompatCOMtest = null;
} }
if ( if (
!function_exists('random_bytes') && !function_exists('random_bytes') &&
extension_loaded('openssl') && extension_loaded('openssl') &&
(
// Unix-like with PHP >= 5.3.0 or
(
DIRECTORY_SEPARATOR === '/' &&
PHP_VERSION_ID >= 50300 PHP_VERSION_ID >= 50300
) ||
// Windows with PHP >= 5.3.4
PHP_VERSION_ID >= 50304
)
) { ) {
// See random_bytes_openssl.php // See random_bytes_openssl.php
require_once $__DIR__.'/random_bytes_openssl.php'; require_once $RandomCompatDIR.'/random_bytes_openssl.php';
} }
if (!function_exists('random_bytes')) { if (!function_exists('random_bytes')) {
/** /**
@ -123,7 +131,7 @@ if (PHP_VERSION_ID < 70000) {
} }
} }
if (!function_exists('random_int')) { if (!function_exists('random_int')) {
require_once $__DIR__.'/random_int.php'; require_once $RandomCompatDIR.'/random_int.php';
} }
unset($__DIR__); $RandomCompatDIR = null;
} }