diff --git a/phpseclib/Net/SSH2.php b/phpseclib/Net/SSH2.php index c705f119..3953a77f 100644 --- a/phpseclib/Net/SSH2.php +++ b/phpseclib/Net/SSH2.php @@ -950,6 +950,8 @@ class SSH2 * Default Constructor. * * $host can either be a string, representing the host, or a stream resource. + * If $host is a stream resource then $port doesn't do anything, altho $timeout + * still will be used * * @see self::login() */ @@ -957,6 +959,8 @@ class SSH2 { self::$connections[$this->getResourceId()] = \WeakReference::create($this); + $this->timeout = $timeout; + if (is_resource($host)) { $this->fsock = $host; return; @@ -965,7 +969,6 @@ class SSH2 if (Strings::is_stringable($host)) { $this->host = $host; $this->port = $port; - $this->timeout = $timeout; } } @@ -3195,6 +3198,9 @@ class SSH2 } $start = microtime(true); + $sec = (int) floor($this->curTimeout); + $usec = (int) (1000000 * ($this->curTimeout - $sec)); + stream_set_timeout($this->fsock, $sec, $usec); $raw = stream_get_contents($this->fsock, $this->decrypt_block_size); if (!strlen($raw)) { diff --git a/tests/Unit/Crypt/AES/TestCase.php b/tests/Unit/Crypt/AES/TestCase.php index 6a984aaa..8ec6fb1e 100644 --- a/tests/Unit/Crypt/AES/TestCase.php +++ b/tests/Unit/Crypt/AES/TestCase.php @@ -30,7 +30,7 @@ abstract class TestCase extends PhpseclibTestCase /** * Produces all combinations of test values. */ - public function continuousBufferCombos(): array + public static function continuousBufferCombos(): array { $modes = [ 'ctr', @@ -133,7 +133,7 @@ abstract class TestCase extends PhpseclibTestCase * * @return list */ - public function continuousBufferBatteryCombos(): array + public static function continuousBufferBatteryCombos(): array { $modes = [ 'ctr', @@ -178,7 +178,7 @@ abstract class TestCase extends PhpseclibTestCase */ public function continuousBufferBatteryCombosWithoutSingleCombos(): array { - return array_filter($this->continuousBufferBatteryCombos(), fn (array $continuousBufferBatteryCombo) => count($continuousBufferBatteryCombo[2]) > 1); + return array_filter(self::$continuousBufferBatteryCombos(), fn (array $continuousBufferBatteryCombo) => count($continuousBufferBatteryCombo[2]) > 1); } /** diff --git a/tests/Unit/Crypt/BlowfishTest.php b/tests/Unit/Crypt/BlowfishTest.php index 5b0d89e7..a552950d 100644 --- a/tests/Unit/Crypt/BlowfishTest.php +++ b/tests/Unit/Crypt/BlowfishTest.php @@ -16,7 +16,7 @@ use phpseclib3\Tests\PhpseclibTestCase; class BlowfishTest extends PhpseclibTestCase { - public function engineVectors(): array + public static function engineVectors(): array { $engines = [ 'PHP', diff --git a/tests/Unit/Crypt/EC/CurveTest.php b/tests/Unit/Crypt/EC/CurveTest.php index c3ac5bbb..8aa02ab2 100644 --- a/tests/Unit/Crypt/EC/CurveTest.php +++ b/tests/Unit/Crypt/EC/CurveTest.php @@ -18,7 +18,7 @@ use phpseclib3\Tests\PhpseclibTestCase; class CurveTest extends PhpseclibTestCase { - public function curves(): array + public static function curves(): array { $curves = []; foreach (new \DirectoryIterator(__DIR__ . '/../../../../phpseclib/Crypt/EC/Curves/') as $file) { @@ -40,7 +40,7 @@ class CurveTest extends PhpseclibTestCase return $curves; } - public function allCurves(): array + public static function allCurves(): array { $curves = []; foreach (new \DirectoryIterator(__DIR__ . '/../../../../phpseclib/Crypt/EC/Curves/') as $file) { @@ -57,7 +57,7 @@ class CurveTest extends PhpseclibTestCase return $curves; } - public function curvesWithOIDs(): array + public static function curvesWithOIDs(): array { $class = new \ReflectionClass('phpseclib3\Crypt\EC\Formats\Keys\PKCS8'); diff --git a/tests/Unit/Crypt/GCMTest.php b/tests/Unit/Crypt/GCMTest.php index b0d3bf2b..16981b95 100644 --- a/tests/Unit/Crypt/GCMTest.php +++ b/tests/Unit/Crypt/GCMTest.php @@ -18,7 +18,7 @@ class GCMTest extends PhpseclibTestCase /** * Produces all combinations of test values. */ - public function engine128Vectors(): array + public static function engine128Vectors(): array { $engines = [ 'PHP', @@ -128,7 +128,7 @@ class GCMTest extends PhpseclibTestCase /** * Produces all combinations of test values. */ - public function engine256Vectors(): array + public static function engine256Vectors(): array { $engines = [ 'PHP', diff --git a/tests/Unit/Crypt/HashTest.php b/tests/Unit/Crypt/HashTest.php index 821f7ca3..0d9e455f 100644 --- a/tests/Unit/Crypt/HashTest.php +++ b/tests/Unit/Crypt/HashTest.php @@ -428,7 +428,7 @@ class HashTest extends PhpseclibTestCase $this->assertSame($hash->getLengthInBytes(), $length); } - public function lengths(): array + public static function lengths(): array { return [ // known @@ -441,7 +441,7 @@ class HashTest extends PhpseclibTestCase ]; } - public function UMACs(): array + public static function UMACs(): array { return [ ['', 'umac-32', '113145FB', "umac-32 and message of "], diff --git a/tests/Unit/Crypt/RC2Test.php b/tests/Unit/Crypt/RC2Test.php index 3be19476..2bae103b 100644 --- a/tests/Unit/Crypt/RC2Test.php +++ b/tests/Unit/Crypt/RC2Test.php @@ -15,13 +15,13 @@ use phpseclib3\Tests\PhpseclibTestCase; class RC2Test extends PhpseclibTestCase { - public $engines = [ + public static $engines = [ 'PHP', 'Eval', 'OpenSSL', ]; - public function engineVectors(): array + public static function engineVectors(): array { // tests from https://tools.ietf.org/html/rfc2268#page-8 $tests = [ @@ -38,7 +38,7 @@ class RC2Test extends PhpseclibTestCase $result = []; - foreach ($this->engines as $engine) { + foreach (self::$engines as $engine) { foreach ($tests as $test) { $result[] = [$engine, $test[0], $test[1], $test[2], $test[3]]; } diff --git a/tests/Unit/Crypt/RC4Test.php b/tests/Unit/Crypt/RC4Test.php index 72909da3..eed1bc92 100644 --- a/tests/Unit/Crypt/RC4Test.php +++ b/tests/Unit/Crypt/RC4Test.php @@ -16,7 +16,7 @@ use phpseclib3\Tests\PhpseclibTestCase; class RC4Test extends PhpseclibTestCase { - public function engineVectors(): array + public static function engineVectors(): array { $engines = [ 'PHP', diff --git a/tests/Unit/Crypt/RandomTest.php b/tests/Unit/Crypt/RandomTest.php index 4cbd9d28..d1fad3c9 100644 --- a/tests/Unit/Crypt/RandomTest.php +++ b/tests/Unit/Crypt/RandomTest.php @@ -15,9 +15,9 @@ use phpseclib3\Tests\PhpseclibTestCase; class RandomTest extends PhpseclibTestCase { - public function stringLengthData(): array + public static function stringLengthData(): array { - return array_map([$this, 'wrap'], [ + return array_map(fn($x) => [$x], [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 17, 19, 20, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 111, 128, 1000, 1024, 10000, 12345, 100000, 123456, @@ -52,10 +52,4 @@ class RandomTest extends PhpseclibTestCase $values[$rand] = true; } } - - protected function wrap($x): array - { - // array() is not a function, but $this->wrap() is. - return [$x]; - } } diff --git a/tests/Unit/Crypt/Salsa20Test.php b/tests/Unit/Crypt/Salsa20Test.php index 469c2cdb..9de1729f 100644 --- a/tests/Unit/Crypt/Salsa20Test.php +++ b/tests/Unit/Crypt/Salsa20Test.php @@ -15,7 +15,7 @@ use phpseclib3\Tests\PhpseclibTestCase; class Salsa20Test extends PhpseclibTestCase { - public function engineVectors(): array + public static function engineVectors(): array { $engines = [ 'PHP', diff --git a/tests/Unit/Crypt/TripleDESTest.php b/tests/Unit/Crypt/TripleDESTest.php index 9aad0095..c748dce0 100644 --- a/tests/Unit/Crypt/TripleDESTest.php +++ b/tests/Unit/Crypt/TripleDESTest.php @@ -15,13 +15,13 @@ use phpseclib3\Tests\PhpseclibTestCase; class TripleDESTest extends PhpseclibTestCase { - public $engines = [ + public static $engines = [ 'PHP', 'Eval', 'OpenSSL', ]; - public function engineVectors(): array + public static function engineVectors(): array { // tests from http://csrc.nist.gov/publications/nistpubs/800-20/800-20.pdf#page=273 $tests = [ @@ -95,7 +95,7 @@ class TripleDESTest extends PhpseclibTestCase $result = []; - foreach ($this->engines as $engine) { + foreach (self::$engines as $engine) { foreach ($tests as $test) { $result[] = [$engine, $test[0], $test[1], $test[2]]; } @@ -122,7 +122,7 @@ class TripleDESTest extends PhpseclibTestCase $this->assertEquals($result, $expected, "Failed asserting that $plaintext yielded expected output in $engine engine"); } - public function engineIVVectors(): array + public static function engineIVVectors(): array { $engines = [ 'PHP', @@ -184,7 +184,7 @@ class TripleDESTest extends PhpseclibTestCase $des->setKey('abcdefghijklmnopqrstuvwx'); $des->setIV(str_repeat("\0", $des->getBlockLength() >> 3)); - foreach ($this->engines as $engine) { + foreach (self::$engines as $engine) { $des->setPreferredEngine($engine); if (!$des->isValidEngine($engine)) { self::markTestSkipped("Unable to initialize $engine engine"); @@ -209,7 +209,7 @@ class TripleDESTest extends PhpseclibTestCase /** * @return list */ - public function provideForCorrectSelfUseInLambda(): array + public static function provideForCorrectSelfUseInLambda(): array { return [ ['YWFhYWFhYWFhYWFhYWFhYWFhYWG9l9gm', 'fDSmC5bbLdx8NKYLltst3Hw0pguW2y3cfDSmC5bbLdxmhqEOIeS2ig=='], diff --git a/tests/Unit/Net/SSH2UnitTest.php b/tests/Unit/Net/SSH2UnitTest.php index fe817347..afc297c1 100644 --- a/tests/Unit/Net/SSH2UnitTest.php +++ b/tests/Unit/Net/SSH2UnitTest.php @@ -16,7 +16,7 @@ use phpseclib3\Tests\PhpseclibTestCase; class SSH2UnitTest extends PhpseclibTestCase { - public function formatLogDataProvider(): array + public static function formatLogDataProvider(): array { return [ [