Replace stream_resolve_include_path with phpseclib_is_includable.

This commit is contained in:
Andreas Fischer 2014-06-17 14:38:24 +02:00
parent 82b5e02f06
commit 9c90beaf82
3 changed files with 21 additions and 31 deletions

View File

@ -194,37 +194,37 @@ if (!function_exists('crypt_random_string')) {
//
// http://en.wikipedia.org/wiki/Cryptographically_secure_pseudorandom_number_generator#Designs_based_on_cryptographic_primitives
switch (true) {
case stream_resolve_include_path('Crypt/AES.php'):
case phpseclib_is_includable('Crypt/AES.php'):
if (!class_exists('Crypt_AES')) {
include_once 'AES.php';
}
$crypto = new Crypt_AES(CRYPT_AES_MODE_CTR);
break;
case stream_resolve_include_path('Crypt/Twofish.php'):
case phpseclib_is_includable('Crypt/Twofish.php'):
if (!class_exists('Crypt_Twofish')) {
include_once 'Twofish.php';
}
$crypto = new Crypt_Twofish(CRYPT_TWOFISH_MODE_CTR);
break;
case stream_resolve_include_path('Crypt/Blowfish.php'):
case phpseclib_is_includable('Crypt/Blowfish.php'):
if (!class_exists('Crypt_Blowfish')) {
include_once 'Blowfish.php';
}
$crypto = new Crypt_Blowfish(CRYPT_BLOWFISH_MODE_CTR);
break;
case stream_resolve_include_path('Crypt/TripleDES.php'):
case phpseclib_is_includable('Crypt/TripleDES.php'):
if (!class_exists('Crypt_TripleDES')) {
include_once 'TripleDES.php';
}
$crypto = new Crypt_TripleDES(CRYPT_DES_MODE_CTR);
break;
case stream_resolve_include_path('Crypt/DES.php'):
case phpseclib_is_includable('Crypt/DES.php'):
if (!class_exists('Crypt_DES')) {
include_once 'DES.php';
}
$crypto = new Crypt_DES(CRYPT_DES_MODE_CTR);
break;
case stream_resolve_include_path('Crypt/RC4.php'):
case phpseclib_is_includable('Crypt/RC4.php'):
if (!class_exists('Crypt_RC4')) {
include_once 'RC4.php';
}
@ -261,30 +261,32 @@ if (!function_exists('crypt_random_string')) {
}
}
if (!function_exists('stream_resolve_include_path')) {
if (!function_exists('phpseclib_is_includable')) {
/**
* Resolve filename against the include path.
*
* stream_resolve_include_path was introduced in PHP 5.3.2. This is kinda a PHP_Compat layer for those not using that version.
* Wrapper around stream_resolve_include_path() (which was introduced in
* PHP 5.3.2) with fallback implementation for earlier PHP versions.
*
* @param Integer $length
* @return String
* @param string $filename
* @return mixed Filename (string) on success, false otherwise.
* @access public
*/
function stream_resolve_include_path($filename)
function phpseclib_is_includable($filename)
{
if (function_exists('stream_resolve_include_path')) {
return stream_resolve_include_path($filename);
}
$paths = PATH_SEPARATOR == ':' ?
preg_split('#(?<!phar):#', get_include_path()) :
explode(PATH_SEPARATOR, get_include_path());
foreach ($paths as $prefix) {
$ds = substr($prefix, -1) == DIRECTORY_SEPARATOR ? '' : DIRECTORY_SEPARATOR;
$file = $prefix . $ds . $filename;
if (file_exists($file)) {
return $file;
}
}
return false;
}
}

View File

@ -1107,31 +1107,31 @@ class Net_SSH2
'none' // OPTIONAL no encryption; NOT RECOMMENDED
);
if (stream_resolve_include_path('Crypt/RC4.php') === false) {
if (phpseclib_is_includable('Crypt/RC4.php') === false) {
$encryption_algorithms = array_diff(
$encryption_algorithms,
array('arcfour256', 'arcfour128', 'arcfour')
);
}
if (stream_resolve_include_path('Crypt/Rijndael.php') === false) {
if (phpseclib_is_includable('Crypt/Rijndael.php') === false) {
$encryption_algorithms = array_diff(
$encryption_algorithms,
array('aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'aes128-cbc', 'aes192-cbc', 'aes256-cbc')
);
}
if (stream_resolve_include_path('Crypt/Twofish.php') === false) {
if (phpseclib_is_includable('Crypt/Twofish.php') === false) {
$encryption_algorithms = array_diff(
$encryption_algorithms,
array('twofish128-ctr', 'twofish192-ctr', 'twofish256-ctr', 'twofish128-cbc', 'twofish192-cbc', 'twofish256-cbc', 'twofish-cbc')
);
}
if (stream_resolve_include_path('Crypt/Blowfish.php') === false) {
if (phpseclib_is_includable('Crypt/Blowfish.php') === false) {
$encryption_algorithms = array_diff(
$encryption_algorithms,
array('blowfish-ctr', 'blowfish-cbc')
);
}
if (stream_resolve_include_path('Crypt/TripleDES.php') === false) {
if (phpseclib_is_includable('Crypt/TripleDES.php') === false) {
$encryption_algorithms = array_diff(
$encryption_algorithms,
array('3des-ctr', '3des-cbc')

View File

@ -15,19 +15,7 @@ set_include_path(implode(PATH_SEPARATOR, array(
get_include_path(),
)));
function phpseclib_is_includable($suffix)
{
foreach (explode(PATH_SEPARATOR, get_include_path()) as $prefix) {
$ds = substr($prefix, -1) == DIRECTORY_SEPARATOR ? '' : DIRECTORY_SEPARATOR;
$file = $prefix . $ds . $suffix;
if (file_exists($file)) {
return true;
}
}
return false;
}
require_once 'Crypt/Random.php';
function phpseclib_autoload($class)
{