From dd031a170256bf6ec323212564ed4a7c91a39b8b Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sun, 6 Sep 2015 12:28:08 +0100 Subject: [PATCH 1/5] PHPDoc fixes --- phpseclib/Crypt/Random.php | 2 +- phpseclib/File/X509.php | 8 ++++---- phpseclib/Math/BigInteger.php | 8 ++++---- phpseclib/Net/SSH1.php | 2 +- phpseclib/Net/SSH2.php | 28 ++++++++++++++-------------- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/phpseclib/Crypt/Random.php b/phpseclib/Crypt/Random.php index af3896d7..4ff913ab 100644 --- a/phpseclib/Crypt/Random.php +++ b/phpseclib/Crypt/Random.php @@ -268,7 +268,7 @@ if (!function_exists('phpseclib_resolve_include_path')) { * PHP 5.3.2) with fallback implementation for earlier PHP versions. * * @param string $filename - * @return mixed Filename (string) on success, false otherwise. + * @return string|false * @access public */ function phpseclib_resolve_include_path($filename) diff --git a/phpseclib/File/X509.php b/phpseclib/File/X509.php index 937c3799..cee91d0d 100644 --- a/phpseclib/File/X509.php +++ b/phpseclib/File/X509.php @@ -3758,7 +3758,7 @@ class File_X509 * @param string $path absolute path with / as component separator * @param bool $create optional * @access private - * @return array item ref or false + * @return mixed */ function &_subArray(&$root, $path, $create = false) { @@ -3794,7 +3794,7 @@ class File_X509 * @param string $path optional absolute path with / as component separator * @param bool $create optional * @access private - * @return array ref or false + * @return mixed */ function &_extensions(&$root, $path = null, $create = false) { @@ -4381,7 +4381,7 @@ class File_X509 * @param string $serial * @param bool $create optional * @access private - * @return int or false + * @return int|false */ function _revokedCertificate(&$rclist, $serial, $create = false) { @@ -4631,7 +4631,7 @@ class File_X509 * getOID('zzz') == 'zzz' * * @access public - * @return String + * @return string */ function getOID($name) { diff --git a/phpseclib/Math/BigInteger.php b/phpseclib/Math/BigInteger.php index 1ec6d5e9..612e65b9 100644 --- a/phpseclib/Math/BigInteger.php +++ b/phpseclib/Math/BigInteger.php @@ -2430,7 +2430,7 @@ class Math_BigInteger * * * @param Math_BigInteger $n - * @return mixed false, if no modular inverse exists, Math_BigInteger, otherwise. + * @return Math_BigInteger|false * @access public * @internal See {@link http://www.cacr.math.uwaterloo.ca/hac/about/chap14.pdf#page=21 HAC 14.64} for more information. */ @@ -3190,13 +3190,13 @@ class Math_BigInteger /** * Generate a random prime number. * - * If there's not a prime within the given range, false will be returned. If more than $timeout seconds have elapsed, - * give up and return false. + * If there's not a prime within the given range, false will be returned. + * If more than $timeout seconds have elapsed, give up and return false. * * @param Math_BigInteger $arg1 * @param Math_BigInteger $arg2 * @param int $timeout - * @return mixed + * @return Math_BigInteger|false * @access public * @internal See {@link http://www.cacr.math.uwaterloo.ca/hac/about/chap4.pdf#page=15 HAC 4.44}. */ diff --git a/phpseclib/Net/SSH1.php b/phpseclib/Net/SSH1.php index 2d1427af..21c305a6 100644 --- a/phpseclib/Net/SSH1.php +++ b/phpseclib/Net/SSH1.php @@ -1414,7 +1414,7 @@ class Net_SSH1 * Returns a string if NET_SSH1_LOGGING == NET_SSH1_LOG_COMPLEX, an array if NET_SSH1_LOGGING == NET_SSH1_LOG_SIMPLE and false if !defined('NET_SSH1_LOGGING') * * @access public - * @return string or Array + * @return array|false|string */ function getLog() { diff --git a/phpseclib/Net/SSH2.php b/phpseclib/Net/SSH2.php index 5543e081..07d7d452 100644 --- a/phpseclib/Net/SSH2.php +++ b/phpseclib/Net/SSH2.php @@ -192,7 +192,7 @@ class Net_SSH2 * Server Identifier * * @see Net_SSH2::getServerIdentification() - * @var mixed false or Array + * @var array|false * @access private */ var $server_identifier = false; @@ -201,7 +201,7 @@ class Net_SSH2 * Key Exchange Algorithms * * @see Net_SSH2::getKexAlgorithims() - * @var mixed false or Array + * @var array|false * @access private */ var $kex_algorithms = false; @@ -237,7 +237,7 @@ class Net_SSH2 * Server Host Key Algorithms * * @see Net_SSH2::getServerHostKeyAlgorithms() - * @var mixed false or Array + * @var array|false * @access private */ var $server_host_key_algorithms = false; @@ -246,7 +246,7 @@ class Net_SSH2 * Encryption Algorithms: Client to Server * * @see Net_SSH2::getEncryptionAlgorithmsClient2Server() - * @var mixed false or Array + * @var array|false * @access private */ var $encryption_algorithms_client_to_server = false; @@ -255,7 +255,7 @@ class Net_SSH2 * Encryption Algorithms: Server to Client * * @see Net_SSH2::getEncryptionAlgorithmsServer2Client() - * @var mixed false or Array + * @var array|false * @access private */ var $encryption_algorithms_server_to_client = false; @@ -264,7 +264,7 @@ class Net_SSH2 * MAC Algorithms: Client to Server * * @see Net_SSH2::getMACAlgorithmsClient2Server() - * @var mixed false or Array + * @var array|false * @access private */ var $mac_algorithms_client_to_server = false; @@ -273,7 +273,7 @@ class Net_SSH2 * MAC Algorithms: Server to Client * * @see Net_SSH2::getMACAlgorithmsServer2Client() - * @var mixed false or Array + * @var array|false * @access private */ var $mac_algorithms_server_to_client = false; @@ -282,7 +282,7 @@ class Net_SSH2 * Compression Algorithms: Client to Server * * @see Net_SSH2::getCompressionAlgorithmsClient2Server() - * @var mixed false or Array + * @var array|false * @access private */ var $compression_algorithms_client_to_server = false; @@ -291,7 +291,7 @@ class Net_SSH2 * Compression Algorithms: Server to Client * * @see Net_SSH2::getCompressionAlgorithmsServer2Client() - * @var mixed false or Array + * @var array|false * @access private */ var $compression_algorithms_server_to_client = false; @@ -300,7 +300,7 @@ class Net_SSH2 * Languages: Server to Client * * @see Net_SSH2::getLanguagesServer2Client() - * @var mixed false or Array + * @var array|false * @access private */ var $languages_server_to_client = false; @@ -309,7 +309,7 @@ class Net_SSH2 * Languages: Client to Server * * @see Net_SSH2::getLanguagesClient2Server() - * @var mixed false or Array + * @var array|false * @access private */ var $languages_client_to_server = false; @@ -1898,7 +1898,7 @@ class Net_SSH2 * Maps an encryption algorithm name to the number of key bytes. * * @param string $algorithm Name of the encryption algorithm - * @return mixed Number of bytes as an integer or null for unknown + * @return int|null Number of bytes as an integer or null for unknown * @access private */ function _encryption_algorithm_to_key_size($algorithm) @@ -3758,7 +3758,7 @@ class Net_SSH2 * Returns a string if NET_SSH2_LOGGING == NET_SSH2_LOG_COMPLEX, an array if NET_SSH2_LOGGING == NET_SSH2_LOG_SIMPLE and false if !defined('NET_SSH2_LOGGING') * * @access public - * @return string or Array + * @return array|false|string */ function getLog() { @@ -4191,7 +4191,7 @@ class Net_SSH2 /** * Returns the exit status of an SSH command or false. * - * @return int or false + * @return false|int * @access public */ function getExitStatus() From eec8c9cb5d1481d24b3e6cf34c992d9a445f46ae Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sun, 6 Sep 2015 12:39:14 +0100 Subject: [PATCH 2/5] More fixes --- phpseclib/Crypt/Base.php | 5 +-- phpseclib/Crypt/Blowfish.php | 4 +- phpseclib/Crypt/RC2.php | 2 +- phpseclib/Crypt/RSA.php | 2 - phpseclib/Crypt/Rijndael.php | 4 +- phpseclib/Crypt/Twofish.php | 34 +++++++-------- phpseclib/Math/BigInteger.php | 28 ++++++------- tests/Functional/Net/SFTPUserStoryTest.php | 4 +- tests/Unit/Crypt/AES/TestCase.php | 48 ++++++++++++---------- tests/Unit/Crypt/BlowfishTest.php | 17 ++++---- tests/Unit/Crypt/RC2Test.php | 17 ++++---- tests/Unit/Crypt/RC4Test.php | 20 +++++---- tests/Unit/Crypt/TripleDESTest.php | 34 ++++++++------- tests/Unit/File/X509/SPKACTest.php | 1 - tests/Unit/Math/BigInteger/TestCase.php | 2 +- 15 files changed, 119 insertions(+), 103 deletions(-) diff --git a/phpseclib/Crypt/Base.php b/phpseclib/Crypt/Base.php index cd6e2ab2..9566f288 100644 --- a/phpseclib/Crypt/Base.php +++ b/phpseclib/Crypt/Base.php @@ -950,7 +950,7 @@ class Crypt_Base if ($this->continuousBuffer) { $this->encryptIV = $xor; if ($start = strlen($plaintext) % $block_size) { - $buffer['xor'] = substr($key, $start) . $buffer['xor']; + $buffer['xor'] = substr($key, $start) . $buffer['xor']; } } break; @@ -1240,7 +1240,7 @@ class Crypt_Base if ($this->continuousBuffer) { $this->decryptIV = $xor; if ($start = strlen($ciphertext) % $block_size) { - $buffer['xor'] = substr($key, $start) . $buffer['xor']; + $buffer['xor'] = substr($key, $start) . $buffer['xor']; } } break; @@ -1790,7 +1790,6 @@ class Crypt_Base if ($this->mode == CRYPT_MODE_CFB) { $this->ecb = mcrypt_module_open($this->cipher_name_mcrypt, '', MCRYPT_MODE_ECB, ''); } - } // else should mcrypt_generic_deinit be called? if ($this->mode == CRYPT_MODE_CFB) { diff --git a/phpseclib/Crypt/Blowfish.php b/phpseclib/Crypt/Blowfish.php index 5e53a54b..943e4476 100644 --- a/phpseclib/Crypt/Blowfish.php +++ b/phpseclib/Crypt/Blowfish.php @@ -165,7 +165,7 @@ class Crypt_Blowfish extends Crypt_Base * @access private * @var array */ - var $sbox0 = array ( + var $sbox0 = array( 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99, 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e, 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013, @@ -544,7 +544,7 @@ class Crypt_Blowfish extends Crypt_Base // We create max. 10 hi-optimized code for memory reason. Means: For each $key one ultra fast inline-crypt function. // (Currently, for Crypt_Blowfish, one generated $lambda_function cost on php5.5@32bit ~100kb unfreeable mem and ~180kb on php5.5@64bit) // After that, we'll still create very fast optimized code but not the hi-ultimative code, for each $mode one. - $gen_hi_opt_code = (bool)( count($lambda_functions) < 10 ); + $gen_hi_opt_code = (bool)(count($lambda_functions) < 10); // Generation of a unique hash for our generated code $code_hash = "Crypt_Blowfish, {$this->mode}"; diff --git a/phpseclib/Crypt/RC2.php b/phpseclib/Crypt/RC2.php index e170d9b1..eb41fe8f 100644 --- a/phpseclib/Crypt/RC2.php +++ b/phpseclib/Crypt/RC2.php @@ -637,7 +637,7 @@ class Crypt_RC2 extends Crypt_Base // for the mixing rounds, for better inline crypt performance [~20% faster]. // But for memory reason we have to limit those ultra-optimized $lambda_functions to an amount of 10. // (Currently, for Crypt_RC2, one generated $lambda_function cost on php5.5@32bit ~60kb unfreeable mem and ~100kb on php5.5@64bit) - $gen_hi_opt_code = (bool)( count($lambda_functions) < 10 ); + $gen_hi_opt_code = (bool)(count($lambda_functions) < 10); // Generation of a uniqe hash for our generated code $code_hash = "Crypt_RC2, {$this->mode}"; diff --git a/phpseclib/Crypt/RSA.php b/phpseclib/Crypt/RSA.php index 64a9d0c2..58111419 100644 --- a/phpseclib/Crypt/RSA.php +++ b/phpseclib/Crypt/RSA.php @@ -1644,7 +1644,6 @@ class Crypt_RSA break; } } - } else { $components = $this->_parseKey($key, $type); } @@ -1859,7 +1858,6 @@ class Crypt_RSA default: return false; } - } /** diff --git a/phpseclib/Crypt/Rijndael.php b/phpseclib/Crypt/Rijndael.php index e2cf7f84..17bbb864 100644 --- a/phpseclib/Crypt/Rijndael.php +++ b/phpseclib/Crypt/Rijndael.php @@ -755,7 +755,7 @@ class Crypt_Rijndael extends Crypt_Base { static $sbox; if (empty($sbox)) { - list(,,,, $sbox) = $this->_getTables(); + list(, , , , $sbox) = $this->_getTables(); } return $sbox[$word & 0x000000FF] | @@ -954,7 +954,7 @@ class Crypt_Rijndael extends Crypt_Base // We create max. 10 hi-optimized code for memory reason. Means: For each $key one ultra fast inline-crypt function. // (Currently, for Crypt_Rijndael/AES, one generated $lambda_function cost on php5.5@32bit ~80kb unfreeable mem and ~130kb on php5.5@64bit) // After that, we'll still create very fast optimized code but not the hi-ultimative code, for each $mode one. - $gen_hi_opt_code = (bool)( count($lambda_functions) < 10 ); + $gen_hi_opt_code = (bool)(count($lambda_functions) < 10); // Generation of a uniqe hash for our generated code $code_hash = "Crypt_Rijndael, {$this->mode}, {$this->Nr}, {$this->Nb}"; diff --git a/phpseclib/Crypt/Twofish.php b/phpseclib/Crypt/Twofish.php index b7d76f01..07b43ed5 100644 --- a/phpseclib/Crypt/Twofish.php +++ b/phpseclib/Crypt/Twofish.php @@ -144,7 +144,7 @@ class Crypt_Twofish extends Crypt_Base * @var array * @access private */ - var $q0 = array ( + var $q0 = array( 0xA9, 0x67, 0xB3, 0xE8, 0x04, 0xFD, 0xA3, 0x76, 0x9A, 0x92, 0x80, 0x78, 0xE4, 0xDD, 0xD1, 0x38, 0x0D, 0xC6, 0x35, 0x98, 0x18, 0xF7, 0xEC, 0x6C, @@ -185,7 +185,7 @@ class Crypt_Twofish extends Crypt_Base * @var array * @access private */ - var $q1 = array ( + var $q1 = array( 0x75, 0xF3, 0xC6, 0xF4, 0xDB, 0x7B, 0xFB, 0xC8, 0x4A, 0xD3, 0xE6, 0x6B, 0x45, 0x7D, 0xE8, 0x4B, 0xD6, 0x32, 0xD8, 0xFD, 0x37, 0x71, 0xF1, 0xE1, @@ -226,7 +226,7 @@ class Crypt_Twofish extends Crypt_Base * @var array * @access private */ - var $m0 = array ( + var $m0 = array( 0xBCBC3275, 0xECEC21F3, 0x202043C6, 0xB3B3C9F4, 0xDADA03DB, 0x02028B7B, 0xE2E22BFB, 0x9E9EFAC8, 0xC9C9EC4A, 0xD4D409D3, 0x18186BE6, 0x1E1E9F6B, 0x98980E45, 0xB2B2387D, 0xA6A6D2E8, 0x2626B74B, 0x3C3C57D6, 0x93938A32, 0x8282EED8, 0x525298FD, 0x7B7BD437, 0xBBBB3771, 0x5B5B97F1, 0x474783E1, @@ -267,7 +267,7 @@ class Crypt_Twofish extends Crypt_Base * @var array * @access private */ - var $m1 = array ( + var $m1 = array( 0xA9D93939, 0x67901717, 0xB3719C9C, 0xE8D2A6A6, 0x04050707, 0xFD985252, 0xA3658080, 0x76DFE4E4, 0x9A084545, 0x92024B4B, 0x80A0E0E0, 0x78665A5A, 0xE4DDAFAF, 0xDDB06A6A, 0xD1BF6363, 0x38362A2A, 0x0D54E6E6, 0xC6432020, 0x3562CCCC, 0x98BEF2F2, 0x181E1212, 0xF724EBEB, 0xECD7A1A1, 0x6C774141, @@ -308,7 +308,7 @@ class Crypt_Twofish extends Crypt_Base * @var array * @access private */ - var $m2 = array ( + var $m2 = array( 0xBC75BC32, 0xECF3EC21, 0x20C62043, 0xB3F4B3C9, 0xDADBDA03, 0x027B028B, 0xE2FBE22B, 0x9EC89EFA, 0xC94AC9EC, 0xD4D3D409, 0x18E6186B, 0x1E6B1E9F, 0x9845980E, 0xB27DB238, 0xA6E8A6D2, 0x264B26B7, 0x3CD63C57, 0x9332938A, 0x82D882EE, 0x52FD5298, 0x7B377BD4, 0xBB71BB37, 0x5BF15B97, 0x47E14783, @@ -349,7 +349,7 @@ class Crypt_Twofish extends Crypt_Base * @var array * @access private */ - var $m3 = array ( + var $m3 = array( 0xD939A9D9, 0x90176790, 0x719CB371, 0xD2A6E8D2, 0x05070405, 0x9852FD98, 0x6580A365, 0xDFE476DF, 0x08459A08, 0x024B9202, 0xA0E080A0, 0x665A7866, 0xDDAFE4DD, 0xB06ADDB0, 0xBF63D1BF, 0x362A3836, 0x54E60D54, 0x4320C643, 0x62CC3562, 0xBEF298BE, 0x1E12181E, 0x24EBF724, 0xD7A1ECD7, 0x77416C77, @@ -492,9 +492,9 @@ class Crypt_Twofish extends Crypt_Base switch (strlen($this->key)) { case 16: - list ($s7, $s6, $s5, $s4) = $this->_mdsrem($le_longs[1], $le_longs[2]); - list ($s3, $s2, $s1, $s0) = $this->_mdsrem($le_longs[3], $le_longs[4]); - for ($i = 0, $j = 1; $i < 40; $i+= 2,$j+= 2) { + list($s7, $s6, $s5, $s4) = $this->_mdsrem($le_longs[1], $le_longs[2]); + list($s3, $s2, $s1, $s0) = $this->_mdsrem($le_longs[3], $le_longs[4]); + for ($i = 0, $j = 1; $i < 40; $i+= 2, $j+= 2) { $A = $m0[$q0[$q0[$i] ^ $key[ 9]] ^ $key[1]] ^ $m1[$q0[$q1[$i] ^ $key[10]] ^ $key[2]] ^ $m2[$q1[$q0[$i] ^ $key[11]] ^ $key[3]] ^ @@ -515,9 +515,9 @@ class Crypt_Twofish extends Crypt_Base } break; case 24: - list ($sb, $sa, $s9, $s8) = $this->_mdsrem($le_longs[1], $le_longs[2]); - list ($s7, $s6, $s5, $s4) = $this->_mdsrem($le_longs[3], $le_longs[4]); - list ($s3, $s2, $s1, $s0) = $this->_mdsrem($le_longs[5], $le_longs[6]); + list($sb, $sa, $s9, $s8) = $this->_mdsrem($le_longs[1], $le_longs[2]); + list($s7, $s6, $s5, $s4) = $this->_mdsrem($le_longs[3], $le_longs[4]); + list($s3, $s2, $s1, $s0) = $this->_mdsrem($le_longs[5], $le_longs[6]); for ($i = 0, $j = 1; $i < 40; $i+= 2, $j+= 2) { $A = $m0[$q0[$q0[$q1[$i] ^ $key[17]] ^ $key[ 9]] ^ $key[1]] ^ $m1[$q0[$q1[$q1[$i] ^ $key[18]] ^ $key[10]] ^ $key[2]] ^ @@ -539,10 +539,10 @@ class Crypt_Twofish extends Crypt_Base } break; default: // 32 - list ($sf, $se, $sd, $sc) = $this->_mdsrem($le_longs[1], $le_longs[2]); - list ($sb, $sa, $s9, $s8) = $this->_mdsrem($le_longs[3], $le_longs[4]); - list ($s7, $s6, $s5, $s4) = $this->_mdsrem($le_longs[5], $le_longs[6]); - list ($s3, $s2, $s1, $s0) = $this->_mdsrem($le_longs[7], $le_longs[8]); + list($sf, $se, $sd, $sc) = $this->_mdsrem($le_longs[1], $le_longs[2]); + list($sb, $sa, $s9, $s8) = $this->_mdsrem($le_longs[3], $le_longs[4]); + list($s7, $s6, $s5, $s4) = $this->_mdsrem($le_longs[5], $le_longs[6]); + list($s3, $s2, $s1, $s0) = $this->_mdsrem($le_longs[7], $le_longs[8]); for ($i = 0, $j = 1; $i < 40; $i+= 2, $j+= 2) { $A = $m0[$q0[$q0[$q1[$q1[$i] ^ $key[25]] ^ $key[17]] ^ $key[ 9]] ^ $key[1]] ^ $m1[$q0[$q1[$q1[$q0[$i] ^ $key[26]] ^ $key[18]] ^ $key[10]] ^ $key[2]] ^ @@ -743,7 +743,7 @@ class Crypt_Twofish extends Crypt_Base // Max. 10 Ultra-Hi-optimized inline-crypt functions. After that, we'll (still) create very fast code, but not the ultimate fast one. // (Currently, for Crypt_Twofish, one generated $lambda_function cost on php5.5@32bit ~140kb unfreeable mem and ~240kb on php5.5@64bit) - $gen_hi_opt_code = (bool)( count($lambda_functions) < 10 ); + $gen_hi_opt_code = (bool)(count($lambda_functions) < 10); // Generation of a uniqe hash for our generated code $code_hash = "Crypt_Twofish, {$this->mode}"; diff --git a/phpseclib/Math/BigInteger.php b/phpseclib/Math/BigInteger.php index 612e65b9..13a54e70 100644 --- a/phpseclib/Math/BigInteger.php +++ b/phpseclib/Math/BigInteger.php @@ -423,13 +423,13 @@ class Math_BigInteger $this->is_negative = false; break; case MATH_BIGINTEGER_MODE_BCMATH: - $x = ( strlen($x) & 1 ) ? '0' . $x : $x; + $x = (strlen($x) & 1) ? '0' . $x : $x; $temp = new Math_BigInteger(pack('H*', $x), 256); $this->value = $this->is_negative ? '-' . $temp->value : $temp->value; $this->is_negative = false; break; default: - $x = ( strlen($x) & 1 ) ? '0' . $x : $x; + $x = (strlen($x) & 1) ? '0' . $x : $x; $temp = new Math_BigInteger(pack('H*', $x), 256); $this->value = $temp->value; } @@ -558,7 +558,7 @@ class Math_BigInteger } $temp = gmp_strval(gmp_abs($this->value), 16); - $temp = ( strlen($temp) & 1 ) ? '0' . $temp : $temp; + $temp = (strlen($temp) & 1) ? '0' . $temp : $temp; $temp = pack('H*', $temp); return $this->precision > 0 ? @@ -802,7 +802,6 @@ class Math_BigInteger $vars[] = 'precision'; } return $vars; - } /** @@ -1512,7 +1511,7 @@ class Math_BigInteger ); $y_window = array( $y_value[$y_max], - ( $y_max > 0 ) ? $y_value[$y_max - 1] : 0 + ($y_max > 0) ? $y_value[$y_max - 1] : 0 ); $q_index = $i - $y_max - 1; @@ -1706,10 +1705,10 @@ class Math_BigInteger } if (MATH_BIGINTEGER_MODE == MATH_BIGINTEGER_MODE_BCMATH) { - $temp = new Math_BigInteger(); - $temp->value = bcpowmod($this->value, $e->value, $n->value, 0); + $temp = new Math_BigInteger(); + $temp->value = bcpowmod($this->value, $e->value, $n->value, 0); - return $this->_normalize($temp); + return $this->_normalize($temp); } if (empty($e->value)) { @@ -1760,7 +1759,7 @@ class Math_BigInteger $mod2->value = array(1); $mod2->_lshift($j); - $part1 = ( $mod1->value != array(1) ) ? $this->_slidingWindow($e, $mod1, MATH_BIGINTEGER_MONTGOMERY) : new Math_BigInteger(); + $part1 = ($mod1->value != array(1)) ? $this->_slidingWindow($e, $mod1, MATH_BIGINTEGER_MONTGOMERY) : new Math_BigInteger(); $part2 = $this->_slidingWindow($e, $mod2, MATH_BIGINTEGER_POWEROF2); $y1 = $mod2->modInverse($mod1); @@ -1855,7 +1854,8 @@ class Math_BigInteger } } - for ($k = 0; $k <= $j; ++$k) {// eg. the length of substr($e_bits, $i, $j+1) + for ($k = 0; $k <= $j; ++$k) { + // eg. the length of substr($e_bits, $i, $j+1) $result = $this->_squareReduce($result, $n_value, $mode); } @@ -2441,7 +2441,7 @@ class Math_BigInteger $temp = new Math_BigInteger(); $temp->value = gmp_invert($this->value, $n->value); - return ( $temp->value === false ) ? false : $this->_normalize($temp); + return ($temp->value === false) ? false : $this->_normalize($temp); } static $zero, $one; @@ -2705,13 +2705,13 @@ class Math_BigInteger function _compare($x_value, $x_negative, $y_value, $y_negative) { if ($x_negative != $y_negative) { - return ( !$x_negative && $y_negative ) ? 1 : -1; + return (!$x_negative && $y_negative) ? 1 : -1; } $result = $x_negative ? -1 : 1; if (count($x_value) != count($y_value)) { - return ( count($x_value) > count($y_value) ) ? $result : -$result; + return (count($x_value) > count($y_value)) ? $result : -$result; } $size = max(count($x_value), count($y_value)); @@ -2720,7 +2720,7 @@ class Math_BigInteger for ($i = count($x_value) - 1; $i >= 0; --$i) { if ($x_value[$i] != $y_value[$i]) { - return ( $x_value[$i] > $y_value[$i] ) ? $result : -$result; + return ($x_value[$i] > $y_value[$i]) ? $result : -$result; } } diff --git a/tests/Functional/Net/SFTPUserStoryTest.php b/tests/Functional/Net/SFTPUserStoryTest.php index 53cc548d..b4e930ef 100644 --- a/tests/Functional/Net/SFTPUserStoryTest.php +++ b/tests/Functional/Net/SFTPUserStoryTest.php @@ -144,8 +144,8 @@ class Functional_Net_SFTPUserStoryTest extends PhpseclibFunctionalTestCase } /** - * @depends testStatOnDir - */ + * @depends testStatOnDir + */ public function testPutSizeGetFileCallback($sftp) { self::$buffer = self::$exampleData; diff --git a/tests/Unit/Crypt/AES/TestCase.php b/tests/Unit/Crypt/AES/TestCase.php index 39b7734e..5a277c8b 100644 --- a/tests/Unit/Crypt/AES/TestCase.php +++ b/tests/Unit/Crypt/AES/TestCase.php @@ -56,13 +56,15 @@ abstract class Unit_Crypt_AES_TestCase extends PhpseclibTestCase $result = array(); - // @codingStandardsIgnoreStart - foreach ($modes as $mode) - foreach ($plaintexts as $plaintext) - foreach ($ivs as $iv) - foreach ($keys as $key) - $result[] = array($mode, $plaintext, $iv, $key); - // @codingStandardsIgnoreEnd + foreach ($modes as $mode) { + foreach ($plaintexts as $plaintext) { + foreach ($ivs as $iv) { + foreach ($keys as $key) { + $result[] = array($mode, $plaintext, $iv, $key); + } + } + } + } return $result; } @@ -122,10 +124,10 @@ abstract class Unit_Crypt_AES_TestCase extends PhpseclibTestCase } /** - * Produces all combinations of test values. - * - * @return array - */ + * Produces all combinations of test values. + * + * @return array + */ public function continuousBufferBatteryCombos() { $modes = array( @@ -153,19 +155,20 @@ abstract class Unit_Crypt_AES_TestCase extends PhpseclibTestCase $result = array(); - // @codingStandardsIgnoreStart - foreach ($modes as $mode) - foreach ($combos as $combo) - foreach (array('encrypt', 'decrypt') as $op) - $result[] = array($op, $mode, $combo); - // @codingStandardsIgnoreEnd + foreach ($modes as $mode) { + foreach ($combos as $combo) { + foreach (array('encrypt', 'decrypt') as $op) { + $result[] = array($op, $mode, $combo); + } + } + } return $result; } /** - * @dataProvider continuousBufferBatteryCombos - */ + * @dataProvider continuousBufferBatteryCombos + */ public function testContinuousBufferBattery($op, $mode, $test) { $iv = str_repeat('x', 16); @@ -209,9 +212,10 @@ abstract class Unit_Crypt_AES_TestCase extends PhpseclibTestCase } /** - * @dataProvider continuousBufferBatteryCombos - */ - // pretty much the same as testContinuousBufferBattery with the caveat that continuous mode is not enabled + * Pretty much the same as testContinuousBufferBattery with the caveat that continuous mode is not enabled. + * + * @dataProvider continuousBufferBatteryCombos + */ public function testNonContinuousBufferBattery($op, $mode, $test) { if (count($test) == 1) { diff --git a/tests/Unit/Crypt/BlowfishTest.php b/tests/Unit/Crypt/BlowfishTest.php index 162c4707..92553e25 100644 --- a/tests/Unit/Crypt/BlowfishTest.php +++ b/tests/Unit/Crypt/BlowfishTest.php @@ -55,18 +55,21 @@ class Unit_Crypt_BlowfishTest extends PhpseclibTestCase array(pack('H*', '0123456789ABCDEF'), pack('H*', '0000000000000000'), pack('H*', '245946885754369A')), array(pack('H*', 'FEDCBA9876543210'), pack('H*', 'FFFFFFFFFFFFFFFF'), pack('H*', '6B5C5A9C5D9E0A5A')) ); + $result = array(); - // @codingStandardsIgnoreStart - foreach ($engines as $engine => $engineName) - foreach ($tests as $test) - $result[] = array($engine, $engineName, $test[0], $test[1], $test[2]); - // @codingStandardsIgnoreEnd + + foreach ($engines as $engine => $engineName) { + foreach ($tests as $test) { + $result[] = array($engine, $engineName, $test[0], $test[1], $test[2]); + } + } + return $result; } /** - * @dataProvider engineVectors - */ + * @dataProvider engineVectors + */ public function testVectors($engine, $engineName, $key, $plaintext, $expected) { $bf = new Crypt_Blowfish(); diff --git a/tests/Unit/Crypt/RC2Test.php b/tests/Unit/Crypt/RC2Test.php index 8bf5ecd7..430b69c8 100644 --- a/tests/Unit/Crypt/RC2Test.php +++ b/tests/Unit/Crypt/RC2Test.php @@ -29,12 +29,15 @@ class Unit_Crypt_RC2Test extends PhpseclibTestCase array('88bca90e90875a7f0f79c384627bafb2', 128, '0000000000000000', '2269552ab0f85ca6'), array('88bca90e90875a7f0f79c384627bafb216f80a6f85920584c42fceb0be255daf1e', 129, '0000000000000000', '5b78d3a43dfff1f1') ); + $result = array(); - // @codingStandardsIgnoreStart - foreach ($this->engines as $engine => $engineName) - foreach ($tests as $test) - $result[] = array($engine, $engineName, $test[0], $test[1], $test[2], $test[3]); - // @codingStandardsIgnoreEnd + + foreach ($this->engines as $engine => $engineName) { + foreach ($tests as $test) { + $result[] = array($engine, $engineName, $test[0], $test[1], $test[2], $test[3]); + } + } + return $result; } @@ -102,8 +105,8 @@ class Unit_Crypt_RC2Test extends PhpseclibTestCase } /** - * @dataProvider engineVectors - */ + * @dataProvider engineVectors + */ public function testVectors($engine, $engineName, $key, $keyLen, $plaintext, $ciphertext) { $rc2 = new Crypt_RC2(); diff --git a/tests/Unit/Crypt/RC4Test.php b/tests/Unit/Crypt/RC4Test.php index 7613d3c8..a9c3ffdc 100644 --- a/tests/Unit/Crypt/RC4Test.php +++ b/tests/Unit/Crypt/RC4Test.php @@ -180,19 +180,23 @@ class Unit_Crypt_RC4Test extends PhpseclibTestCase ) ) ); + $result = array(); - // @codingStandardsIgnoreStart - foreach ($engines as $engine => $engineName) - foreach ($tests as $test) - foreach ($test['output'] as $output) - $result[] = array($engine, $engineName, $test['key'], $output['offset'], $output['result']); - // @codingStandardsIgnoreEnd + + foreach ($engines as $engine => $engineName) { + foreach ($tests as $test) { + foreach ($test['output'] as $output) { + $result[] = array($engine, $engineName, $test['key'], $output['offset'], $output['result']); + } + } + } + return $result; } /** - * @dataProvider engineVectors - */ + * @dataProvider engineVectors + */ public function testVectors($engine, $engineName, $key, $offset, $expected) { $rc4 = new Crypt_RC4(); diff --git a/tests/Unit/Crypt/TripleDESTest.php b/tests/Unit/Crypt/TripleDESTest.php index a1b07f86..c1f09ba1 100644 --- a/tests/Unit/Crypt/TripleDESTest.php +++ b/tests/Unit/Crypt/TripleDESTest.php @@ -86,18 +86,21 @@ class Unit_Crypt_TripleDESTest extends PhpseclibTestCase array(str_repeat("\x01", 24), pack('H*', '0000000000000002'), pack('H*', '06E7EA22CE92708F')), array(str_repeat("\x01", 24), pack('H*', '0000000000000001'), pack('H*', '166B40B44ABA4BD6')) ); + $result = array(); - // @codingStandardsIgnoreStart - foreach ($this->engines as $engine => $engineName) - foreach ($tests as $test) - $result[] = array($engine, $engineName, $test[0], $test[1], $test[2]); - // @codingStandardsIgnoreEnd + + foreach ($this->engines as $engine => $engineName) { + foreach ($tests as $test) { + $result[] = array($engine, $engineName, $test[0], $test[1], $test[2]); + } + } + return $result; } /** - * @dataProvider engineVectors - */ + * @dataProvider engineVectors + */ public function testVectors($engine, $engineName, $key, $plaintext, $expected) { $des = new Crypt_TripleDES(); @@ -134,18 +137,21 @@ class Unit_Crypt_TripleDESTest extends PhpseclibTestCase pack('H*', '84401f78fe6c10876d8ea23094ea5309'), pack('H*', '7b1f7c7e3b1c948ebd04a75ffba7d2f5')) ); + $result = array(); - // @codingStandardsIgnoreStart - foreach ($engines as $engine => $engineName) - foreach ($tests as $test) - $result[] = array($engine, $engineName, $test[0], $test[1], $test[2], $test[3]); - // @codingStandardsIgnoreEnd + + foreach ($engines as $engine => $engineName) { + foreach ($tests as $test) { + $result[] = array($engine, $engineName, $test[0], $test[1], $test[2], $test[3]); + } + } + return $result; } /** - * @dataProvider engineIVVectors - */ + * @dataProvider engineIVVectors + */ public function testVectorsWithIV($engine, $engineName, $key, $iv, $plaintext, $expected) { $des = new Crypt_TripleDES(); diff --git a/tests/Unit/File/X509/SPKACTest.php b/tests/Unit/File/X509/SPKACTest.php index 7f53f18a..59bda3ae 100644 --- a/tests/Unit/File/X509/SPKACTest.php +++ b/tests/Unit/File/X509/SPKACTest.php @@ -94,6 +94,5 @@ class Unit_File_X509_SPKACTest extends PhpseclibTestCase $x509->validateSignature(), 'Failed asserting that the signature is invalid' ); - } } diff --git a/tests/Unit/Math/BigInteger/TestCase.php b/tests/Unit/Math/BigInteger/TestCase.php index 78a01d7f..10eacc66 100644 --- a/tests/Unit/Math/BigInteger/TestCase.php +++ b/tests/Unit/Math/BigInteger/TestCase.php @@ -52,7 +52,7 @@ abstract class Unit_Math_BigInteger_TestCase extends PhpseclibTestCase public function testToHex() { - $this->assertSame('41', $this->getInstance('65')->toHex()); + $this->assertSame('41', $this->getInstance('65')->toHex()); } public function testToBits() From 06a1d3d9819e94745497a8c17cf603a35ece78c7 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sun, 6 Sep 2015 22:19:34 +0100 Subject: [PATCH 3/5] Fixed error --- phpseclib/File/X509.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpseclib/File/X509.php b/phpseclib/File/X509.php index cee91d0d..8f966754 100644 --- a/phpseclib/File/X509.php +++ b/phpseclib/File/X509.php @@ -3794,7 +3794,7 @@ class File_X509 * @param string $path optional absolute path with / as component separator * @param bool $create optional * @access private - * @return mixed + * @return array|false */ function &_extensions(&$root, $path = null, $create = false) { From b1db7f05d9a91296a977620f19dc0031d67de0d7 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sun, 6 Sep 2015 23:01:03 +0100 Subject: [PATCH 4/5] Minor tweaks --- phpseclib/Math/BigInteger.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpseclib/Math/BigInteger.php b/phpseclib/Math/BigInteger.php index 13a54e70..14452dd0 100644 --- a/phpseclib/Math/BigInteger.php +++ b/phpseclib/Math/BigInteger.php @@ -1854,14 +1854,14 @@ class Math_BigInteger } } + // eg. the length of substr($e_bits, $i, $j + 1) for ($k = 0; $k <= $j; ++$k) { - // eg. the length of substr($e_bits, $i, $j+1) $result = $this->_squareReduce($result, $n_value, $mode); } $result = $this->_multiplyReduce($result, $powers[bindec(substr($e_bits, $i, $j + 1))], $n_value, $mode); - $i+=$j + 1; + $i += $j + 1; } } From 010c1285ba5f5437e3a65430b69a2926c4c076e6 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sun, 6 Sep 2015 23:05:41 +0100 Subject: [PATCH 5/5] Fixed another case --- phpseclib/File/X509.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpseclib/File/X509.php b/phpseclib/File/X509.php index 8f966754..34dbafad 100644 --- a/phpseclib/File/X509.php +++ b/phpseclib/File/X509.php @@ -3758,7 +3758,7 @@ class File_X509 * @param string $path absolute path with / as component separator * @param bool $create optional * @access private - * @return mixed + * @return array|false */ function &_subArray(&$root, $path, $create = false) {