From 6d1fb9f7dbbb962ac0cfb01942bcd1f26f946097 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 6 Dec 2013 01:03:34 +0100 Subject: [PATCH] CS: Fix "PEAR.Files.IncludingFile.UseIncludeOnce" sniff. --- phpseclib/Crypt/AES.php | 2 +- phpseclib/Crypt/Base.php | 2 +- phpseclib/Crypt/Blowfish.php | 2 +- phpseclib/Crypt/DES.php | 2 +- phpseclib/Crypt/Hash.php | 2 +- phpseclib/Crypt/RC2.php | 2 +- phpseclib/Crypt/RC4.php | 2 +- phpseclib/Crypt/RSA.php | 26 ++++++++++---------- phpseclib/Crypt/Rijndael.php | 2 +- phpseclib/Crypt/TripleDES.php | 2 +- phpseclib/Crypt/Twofish.php | 2 +- phpseclib/File/ASN1.php | 2 +- phpseclib/File/X509.php | 18 +++++++------- phpseclib/Net/SFTP.php | 2 +- phpseclib/Net/SFTP/Stream.php | 2 +- phpseclib/Net/SSH1.php | 14 +++++------ phpseclib/Net/SSH2.php | 44 +++++++++++++++++----------------- tests/code_sniffer_ruleset.xml | 1 - 18 files changed, 64 insertions(+), 65 deletions(-) diff --git a/phpseclib/Crypt/AES.php b/phpseclib/Crypt/AES.php index 7fbff79d..5977ad8c 100644 --- a/phpseclib/Crypt/AES.php +++ b/phpseclib/Crypt/AES.php @@ -65,7 +65,7 @@ * Include Crypt_Rijndael */ if (!class_exists('Crypt_Rijndael')) { - require_once 'Rijndael.php'; + include_once 'Rijndael.php'; } /**#@+ diff --git a/phpseclib/Crypt/Base.php b/phpseclib/Crypt/Base.php index 2c9002a0..ebf5fdde 100644 --- a/phpseclib/Crypt/Base.php +++ b/phpseclib/Crypt/Base.php @@ -582,7 +582,7 @@ class Crypt_Base case !function_exists('hash_algos'): case !in_array($hash, hash_algos()): if (!class_exists('Crypt_Hash')) { - require_once 'Crypt/Hash.php'; + include_once 'Crypt/Hash.php'; } $i = 1; while (strlen($key) < $dkLen) { diff --git a/phpseclib/Crypt/Blowfish.php b/phpseclib/Crypt/Blowfish.php index 40389980..3e2bcf16 100644 --- a/phpseclib/Crypt/Blowfish.php +++ b/phpseclib/Crypt/Blowfish.php @@ -60,7 +60,7 @@ * Base cipher class */ if (!class_exists('Crypt_Base')) { - require_once 'Base.php'; + include_once 'Base.php'; } /**#@+ diff --git a/phpseclib/Crypt/DES.php b/phpseclib/Crypt/DES.php index 167a4128..637bae2c 100644 --- a/phpseclib/Crypt/DES.php +++ b/phpseclib/Crypt/DES.php @@ -64,7 +64,7 @@ * Base cipher class */ if (!class_exists('Crypt_Base')) { - require_once 'Base.php'; + include_once 'Base.php'; } /**#@+ diff --git a/phpseclib/Crypt/Hash.php b/phpseclib/Crypt/Hash.php index a2ba4b11..221ba8cf 100644 --- a/phpseclib/Crypt/Hash.php +++ b/phpseclib/Crypt/Hash.php @@ -581,7 +581,7 @@ class Crypt_Hash function _sha512($m) { if (!class_exists('Math_BigInteger')) { - require_once 'Math/BigInteger.php'; + include_once 'Math/BigInteger.php'; } static $init384, $init512, $k; diff --git a/phpseclib/Crypt/RC2.php b/phpseclib/Crypt/RC2.php index 629f80d3..9975319b 100755 --- a/phpseclib/Crypt/RC2.php +++ b/phpseclib/Crypt/RC2.php @@ -57,7 +57,7 @@ * Base cipher class */ if (!class_exists('Crypt_Base')) { - require_once 'Base.php'; + include_once 'Base.php'; } /**#@+ diff --git a/phpseclib/Crypt/RC4.php b/phpseclib/Crypt/RC4.php index 75919717..e023f101 100644 --- a/phpseclib/Crypt/RC4.php +++ b/phpseclib/Crypt/RC4.php @@ -66,7 +66,7 @@ * Base cipher class */ if (!class_exists('Crypt_Base')) { - require_once 'Base.php'; + include_once 'Base.php'; } /**#@+ diff --git a/phpseclib/Crypt/RSA.php b/phpseclib/Crypt/RSA.php index 2df9c431..184cf93d 100644 --- a/phpseclib/Crypt/RSA.php +++ b/phpseclib/Crypt/RSA.php @@ -72,17 +72,17 @@ */ // the class_exists() will only be called if the crypt_random_string function hasn't been defined and // will trigger a call to __autoload() if you're wanting to auto-load classes -// call function_exists() a second time to stop the require_once from being called outside +// call function_exists() a second time to stop the include_once from being called outside // of the auto loader if (!function_exists('crypt_random_string')) { - require_once 'Random.php'; + include_once 'Random.php'; } /** * Include Crypt_Hash */ if (!class_exists('Crypt_Hash')) { - require_once 'Hash.php'; + include_once 'Hash.php'; } /**#@+ @@ -461,7 +461,7 @@ class Crypt_RSA function Crypt_RSA() { if (!class_exists('Math_BigInteger')) { - require_once 'Math/BigInteger.php'; + include_once 'Math/BigInteger.php'; } $this->configFile = CRYPT_RSA_OPENSSL_CONFIG; @@ -773,7 +773,7 @@ class Crypt_RSA $private.= crypt_random_string(16 - (strlen($private) & 15)); $source.= pack('Na*', strlen($private), $private); if (!class_exists('Crypt_AES')) { - require_once 'Crypt/AES.php'; + include_once 'Crypt/AES.php'; } $sequence = 0; $symkey = ''; @@ -794,7 +794,7 @@ class Crypt_RSA $key.= 'Private-Lines: ' . ((strlen($private) + 63) >> 6) . "\r\n"; $key.= chunk_split($private, 64); if (!class_exists('Crypt_Hash')) { - require_once 'Crypt/Hash.php'; + include_once 'Crypt/Hash.php'; } $hash = new Crypt_Hash('sha1'); $hash->setKey(pack('H*', sha1($hashkey))); @@ -834,7 +834,7 @@ class Crypt_RSA $symkey = pack('H*', md5($this->password . $iv)); // symkey is short for symmetric key $symkey.= substr(pack('H*', md5($symkey . $this->password . $iv)), 0, 8); if (!class_exists('Crypt_TripleDES')) { - require_once 'Crypt/TripleDES.php'; + include_once 'Crypt/TripleDES.php'; } $des = new Crypt_TripleDES(); $des->setKey($symkey); @@ -1000,33 +1000,33 @@ class Crypt_RSA switch ($matches[1]) { case 'AES-256-CBC': if (!class_exists('Crypt_AES')) { - require_once 'Crypt/AES.php'; + include_once 'Crypt/AES.php'; } $crypto = new Crypt_AES(); break; case 'AES-128-CBC': if (!class_exists('Crypt_AES')) { - require_once 'Crypt/AES.php'; + include_once 'Crypt/AES.php'; } $symkey = substr($symkey, 0, 16); $crypto = new Crypt_AES(); break; case 'DES-EDE3-CFB': if (!class_exists('Crypt_TripleDES')) { - require_once 'Crypt/TripleDES.php'; + include_once 'Crypt/TripleDES.php'; } $crypto = new Crypt_TripleDES(CRYPT_DES_MODE_CFB); break; case 'DES-EDE3-CBC': if (!class_exists('Crypt_TripleDES')) { - require_once 'Crypt/TripleDES.php'; + include_once 'Crypt/TripleDES.php'; } $symkey = substr($symkey, 0, 24); $crypto = new Crypt_TripleDES(); break; case 'DES-CBC': if (!class_exists('Crypt_DES')) { - require_once 'Crypt/DES.php'; + include_once 'Crypt/DES.php'; } $crypto = new Crypt_DES(); break; @@ -1240,7 +1240,7 @@ class Crypt_RSA switch ($encryption) { case 'aes256-cbc': if (!class_exists('Crypt_AES')) { - require_once 'Crypt/AES.php'; + include_once 'Crypt/AES.php'; } $symkey = ''; $sequence = 0; diff --git a/phpseclib/Crypt/Rijndael.php b/phpseclib/Crypt/Rijndael.php index 884fa8a2..4718062a 100644 --- a/phpseclib/Crypt/Rijndael.php +++ b/phpseclib/Crypt/Rijndael.php @@ -76,7 +76,7 @@ * Base cipher class */ if (!class_exists('Crypt_Base')) { - require_once 'Base.php'; + include_once 'Base.php'; } /**#@+ diff --git a/phpseclib/Crypt/TripleDES.php b/phpseclib/Crypt/TripleDES.php index 84c10e16..9239fa37 100644 --- a/phpseclib/Crypt/TripleDES.php +++ b/phpseclib/Crypt/TripleDES.php @@ -56,7 +56,7 @@ * Include Crypt_DES */ if (!class_exists('Crypt_DES')) { - require_once 'DES.php'; + include_once 'DES.php'; } /** diff --git a/phpseclib/Crypt/Twofish.php b/phpseclib/Crypt/Twofish.php index 68d5c0d9..31424f66 100644 --- a/phpseclib/Crypt/Twofish.php +++ b/phpseclib/Crypt/Twofish.php @@ -60,7 +60,7 @@ * Base cipher class */ if (!class_exists('Crypt_Base')) { - require_once 'Base.php'; + include_once 'Base.php'; } /**#@+ diff --git a/phpseclib/File/ASN1.php b/phpseclib/File/ASN1.php index bce5c80e..8e0898f2 100644 --- a/phpseclib/File/ASN1.php +++ b/phpseclib/File/ASN1.php @@ -253,7 +253,7 @@ class File_ASN1 if (!$static_init) { $static_init = true; if (!class_exists('Math_BigInteger')) { - require_once 'Math/BigInteger.php'; + include_once 'Math/BigInteger.php'; } } } diff --git a/phpseclib/File/X509.php b/phpseclib/File/X509.php index e392839e..446fc815 100644 --- a/phpseclib/File/X509.php +++ b/phpseclib/File/X509.php @@ -46,7 +46,7 @@ * Include File_ASN1 */ if (!class_exists('File_ASN1')) { - require_once 'ASN1.php'; + include_once 'ASN1.php'; } /** @@ -307,7 +307,7 @@ class File_X509 function File_X509() { if (!class_exists('Math_BigInteger')) { - require_once 'Math/BigInteger.php'; + include_once 'Math/BigInteger.php'; } // Explicitly Tagged Module, 1988 Syntax @@ -2121,7 +2121,7 @@ class File_X509 switch ($publicKeyAlgorithm) { case 'rsaEncryption': if (!class_exists('Crypt_RSA')) { - require_once 'Crypt/RSA.php'; + include_once 'Crypt/RSA.php'; } $rsa = new Crypt_RSA(); $rsa->loadKey($publicKey); @@ -2523,7 +2523,7 @@ class File_X509 case FILE_X509_DN_HASH: $dn = $this->getDN(FILE_X509_DN_CANON, $dn); if (!class_exists('Crypt_Hash')) { - require_once 'Crypt/Hash.php'; + include_once 'Crypt/Hash.php'; } $hash = new Crypt_Hash('sha1'); $hash = $hash->hash($dn); @@ -2791,7 +2791,7 @@ class File_X509 switch ($keyinfo['algorithm']['algorithm']) { case 'rsaEncryption': if (!class_exists('Crypt_RSA')) { - require_once 'Crypt/RSA.php'; + include_once 'Crypt/RSA.php'; } $publicKey = new Crypt_RSA(); $publicKey->loadKey($key); @@ -2864,7 +2864,7 @@ class File_X509 switch ($algorithm) { case 'rsaEncryption': if (!class_exists('Crypt_RSA')) { - require_once 'Crypt/RSA.php'; + include_once 'Crypt/RSA.php'; } $this->publicKey = new Crypt_RSA(); $this->publicKey->loadKey($key); @@ -2989,7 +2989,7 @@ class File_X509 switch ($algorithm) { case 'rsaEncryption': if (!class_exists('Crypt_RSA')) { - require_once 'Crypt/RSA.php'; + include_once 'Crypt/RSA.php'; } $this->publicKey = new Crypt_RSA(); $this->publicKey->loadKey($key); @@ -4061,7 +4061,7 @@ class File_X509 $raw = base64_decode($raw); // If the key is private, compute identifier from its corresponding public key. if (!class_exists('Crypt_RSA')) { - require_once 'Crypt/RSA.php'; + include_once 'Crypt/RSA.php'; } $key = new Crypt_RSA(); if (!$key->loadKey($raw)) { @@ -4093,7 +4093,7 @@ class File_X509 // Now we have the key string: compute its sha-1 sum. if (!class_exists('Crypt_Hash')) { - require_once 'Crypt/Hash.php'; + include_once 'Crypt/Hash.php'; } $hash = new Crypt_Hash('sha1'); $hash = $hash->hash($key); diff --git a/phpseclib/Net/SFTP.php b/phpseclib/Net/SFTP.php index 9dfb35ee..17321d35 100644 --- a/phpseclib/Net/SFTP.php +++ b/phpseclib/Net/SFTP.php @@ -57,7 +57,7 @@ * Include Net_SSH2 */ if (!class_exists('Net_SSH2')) { - require_once 'SSH2.php'; + include_once 'SSH2.php'; } /**#@+ diff --git a/phpseclib/Net/SFTP/Stream.php b/phpseclib/Net/SFTP/Stream.php index 14ce6286..294532ff 100644 --- a/phpseclib/Net/SFTP/Stream.php +++ b/phpseclib/Net/SFTP/Stream.php @@ -139,7 +139,7 @@ class Net_SFTP_Stream } if (!class_exists('Net_SFTP')) { - require_once 'Net/SFTP.php'; + include_once 'Net/SFTP.php'; } } diff --git a/phpseclib/Net/SSH1.php b/phpseclib/Net/SSH1.php index 682b4455..ef3492d7 100644 --- a/phpseclib/Net/SSH1.php +++ b/phpseclib/Net/SSH1.php @@ -449,16 +449,16 @@ class Net_SSH1 function Net_SSH1($host, $port = 22, $timeout = 10, $cipher = NET_SSH1_CIPHER_3DES) { if (!class_exists('Math_BigInteger')) { - require_once 'Math/BigInteger.php'; + include_once 'Math/BigInteger.php'; } // Include Crypt_Random // the class_exists() will only be called if the crypt_random_string function hasn't been defined and // will trigger a call to __autoload() if you're wanting to auto-load classes - // call function_exists() a second time to stop the require_once from being called outside + // call function_exists() a second time to stop the include_once from being called outside // of the auto loader if (!function_exists('crypt_random_string') && !class_exists('Crypt_Random') && !function_exists('crypt_random_string')) { - require_once 'Crypt/Random.php'; + include_once 'Crypt/Random.php'; } $this->protocol_flags = array( @@ -603,7 +603,7 @@ class Net_SSH1 // break; case NET_SSH1_CIPHER_DES: if (!class_exists('Crypt_DES')) { - require_once 'Crypt/DES.php'; + include_once 'Crypt/DES.php'; } $this->crypto = new Crypt_DES(); $this->crypto->disablePadding(); @@ -612,7 +612,7 @@ class Net_SSH1 break; case NET_SSH1_CIPHER_3DES: if (!class_exists('Crypt_TripleDES')) { - require_once 'Crypt/TripleDES.php'; + include_once 'Crypt/TripleDES.php'; } $this->crypto = new Crypt_TripleDES(CRYPT_DES_MODE_3CBC); $this->crypto->disablePadding(); @@ -621,7 +621,7 @@ class Net_SSH1 break; //case NET_SSH1_CIPHER_RC4: // if (!class_exists('Crypt_RC4')) { - // require_once('Crypt/RC4.php'); + // include_once('Crypt/RC4.php'); // } // $this->crypto = new Crypt_RC4(); // $this->crypto->enableContinuousBuffer(); @@ -1253,7 +1253,7 @@ class Net_SSH1 { /* if (!class_exists('Crypt_RSA')) { - require_once 'Crypt/RSA.php'; + include_once 'Crypt/RSA.php'; } $rsa = new Crypt_RSA(); diff --git a/phpseclib/Net/SSH2.php b/phpseclib/Net/SSH2.php index 4204ffe8..8454df06 100644 --- a/phpseclib/Net/SSH2.php +++ b/phpseclib/Net/SSH2.php @@ -763,15 +763,15 @@ class Net_SSH2 // Include Math_BigInteger // Used to do Diffie-Hellman key exchange and DSA/RSA signature verification. if (!class_exists('Math_BigInteger')) { - require_once 'Math/BigInteger.php'; + include_once 'Math/BigInteger.php'; } if (!function_exists('crypt_random_string')) { - require_once 'Crypt/Random.php'; + include_once 'Crypt/Random.php'; } if (!class_exists('Crypt_Hash')) { - require_once 'Crypt/Hash.php'; + include_once 'Crypt/Hash.php'; } $this->last_packet = strtok(microtime(), ' ') + strtok(''); // == microtime(true) in PHP5 @@ -1353,14 +1353,14 @@ class Net_SSH2 switch ($encrypt) { case '3des-cbc': if (!class_exists('Crypt_TripleDES')) { - require_once 'Crypt/TripleDES.php'; + include_once 'Crypt/TripleDES.php'; } $this->encrypt = new Crypt_TripleDES(); // $this->encrypt_block_size = 64 / 8 == the default break; case '3des-ctr': if (!class_exists('Crypt_TripleDES')) { - require_once 'Crypt/TripleDES.php'; + include_once 'Crypt/TripleDES.php'; } $this->encrypt = new Crypt_TripleDES(CRYPT_DES_MODE_CTR); // $this->encrypt_block_size = 64 / 8 == the default @@ -1369,7 +1369,7 @@ class Net_SSH2 case 'aes192-cbc': case 'aes128-cbc': if (!class_exists('Crypt_Rijndael')) { - require_once 'Crypt/Rijndael.php'; + include_once 'Crypt/Rijndael.php'; } $this->encrypt = new Crypt_Rijndael(); $this->encrypt_block_size = 16; // eg. 128 / 8 @@ -1378,21 +1378,21 @@ class Net_SSH2 case 'aes192-ctr': case 'aes128-ctr': if (!class_exists('Crypt_Rijndael')) { - require_once 'Crypt/Rijndael.php'; + include_once 'Crypt/Rijndael.php'; } $this->encrypt = new Crypt_Rijndael(CRYPT_RIJNDAEL_MODE_CTR); $this->encrypt_block_size = 16; // eg. 128 / 8 break; case 'blowfish-cbc': if (!class_exists('Crypt_Blowfish')) { - require_once 'Crypt/Blowfish.php'; + include_once 'Crypt/Blowfish.php'; } $this->encrypt = new Crypt_Blowfish(); $this->encrypt_block_size = 8; break; case 'blowfish-ctr': if (!class_exists('Crypt_Blowfish')) { - require_once 'Crypt/Blowfish.php'; + include_once 'Crypt/Blowfish.php'; } $this->encrypt = new Crypt_Blowfish(CRYPT_BLOWFISH_MODE_CTR); $this->encrypt_block_size = 8; @@ -1402,7 +1402,7 @@ class Net_SSH2 case 'twofish256-cbc': case 'twofish-cbc': if (!class_exists('Crypt_Twofish')) { - require_once 'Crypt/Twofish.php'; + include_once 'Crypt/Twofish.php'; } $this->encrypt = new Crypt_Twofish(); $this->encrypt_block_size = 16; @@ -1411,7 +1411,7 @@ class Net_SSH2 case 'twofish192-ctr': case 'twofish256-ctr': if (!class_exists('Crypt_Twofish')) { - require_once 'Crypt/Twofish.php'; + include_once 'Crypt/Twofish.php'; } $this->encrypt = new Crypt_Twofish(CRYPT_TWOFISH_MODE_CTR); $this->encrypt_block_size = 16; @@ -1420,7 +1420,7 @@ class Net_SSH2 case 'arcfour128': case 'arcfour256': if (!class_exists('Crypt_RC4')) { - require_once 'Crypt/RC4.php'; + include_once 'Crypt/RC4.php'; } $this->encrypt = new Crypt_RC4(); break; @@ -1431,13 +1431,13 @@ class Net_SSH2 switch ($decrypt) { case '3des-cbc': if (!class_exists('Crypt_TripleDES')) { - require_once 'Crypt/TripleDES.php'; + include_once 'Crypt/TripleDES.php'; } $this->decrypt = new Crypt_TripleDES(); break; case '3des-ctr': if (!class_exists('Crypt_TripleDES')) { - require_once 'Crypt/TripleDES.php'; + include_once 'Crypt/TripleDES.php'; } $this->decrypt = new Crypt_TripleDES(CRYPT_DES_MODE_CTR); break; @@ -1445,7 +1445,7 @@ class Net_SSH2 case 'aes192-cbc': case 'aes128-cbc': if (!class_exists('Crypt_Rijndael')) { - require_once 'Crypt/Rijndael.php'; + include_once 'Crypt/Rijndael.php'; } $this->decrypt = new Crypt_Rijndael(); $this->decrypt_block_size = 16; @@ -1454,21 +1454,21 @@ class Net_SSH2 case 'aes192-ctr': case 'aes128-ctr': if (!class_exists('Crypt_Rijndael')) { - require_once 'Crypt/Rijndael.php'; + include_once 'Crypt/Rijndael.php'; } $this->decrypt = new Crypt_Rijndael(CRYPT_RIJNDAEL_MODE_CTR); $this->decrypt_block_size = 16; break; case 'blowfish-cbc': if (!class_exists('Crypt_Blowfish')) { - require_once 'Crypt/Blowfish.php'; + include_once 'Crypt/Blowfish.php'; } $this->decrypt = new Crypt_Blowfish(); $this->decrypt_block_size = 8; break; case 'blowfish-ctr': if (!class_exists('Crypt_Blowfish')) { - require_once 'Crypt/Blowfish.php'; + include_once 'Crypt/Blowfish.php'; } $this->decrypt = new Crypt_Blowfish(CRYPT_BLOWFISH_MODE_CTR); $this->decrypt_block_size = 8; @@ -1478,7 +1478,7 @@ class Net_SSH2 case 'twofish256-cbc': case 'twofish-cbc': if (!class_exists('Crypt_Twofish')) { - require_once 'Crypt/Twofish.php'; + include_once 'Crypt/Twofish.php'; } $this->decrypt = new Crypt_Twofish(); $this->decrypt_block_size = 16; @@ -1487,7 +1487,7 @@ class Net_SSH2 case 'twofish192-ctr': case 'twofish256-ctr': if (!class_exists('Crypt_Twofish')) { - require_once 'Crypt/Twofish.php'; + include_once 'Crypt/Twofish.php'; } $this->decrypt = new Crypt_Twofish(CRYPT_TWOFISH_MODE_CTR); $this->decrypt_block_size = 16; @@ -1496,7 +1496,7 @@ class Net_SSH2 case 'arcfour128': case 'arcfour256': if (!class_exists('Crypt_RC4')) { - require_once 'Crypt/RC4.php'; + include_once 'Crypt/RC4.php'; } $this->decrypt = new Crypt_RC4(); break; @@ -3503,7 +3503,7 @@ class Net_SSH2 $signature = $this->_string_shift($signature, $temp['length']); if (!class_exists('Crypt_RSA')) { - require_once 'Crypt/RSA.php'; + include_once 'Crypt/RSA.php'; } $rsa = new Crypt_RSA(); diff --git a/tests/code_sniffer_ruleset.xml b/tests/code_sniffer_ruleset.xml index 047b3229..41aca9f1 100644 --- a/tests/code_sniffer_ruleset.xml +++ b/tests/code_sniffer_ruleset.xml @@ -29,7 +29,6 @@ 0 0 0 - 0 0 0 0