mirror of
https://github.com/phpseclib/phpseclib.git
synced 2025-01-14 02:11:20 +00:00
Merge branch '3.0'
This commit is contained in:
commit
ca2c9588ea
@ -130,6 +130,11 @@ abstract class AsymmetricKey
|
||||
{
|
||||
self::initialize_static_variables();
|
||||
|
||||
$class = new \ReflectionClass(static::class);
|
||||
if ($class->isFinal()) {
|
||||
throw new \RuntimeException('load() should not be called from final classes (' . static::class . ')');
|
||||
}
|
||||
|
||||
$components = false;
|
||||
foreach (self::$plugins[static::ALGORITHM]['Keys'] as $format) {
|
||||
if (isset(self::$invisiblePlugins[static::ALGORITHM]) && in_array($format, self::$invisiblePlugins[static::ALGORITHM])) {
|
||||
|
@ -82,6 +82,11 @@ abstract class DH extends AsymmetricKey
|
||||
*/
|
||||
public static function createParameters(...$args): Parameters
|
||||
{
|
||||
$class = new \ReflectionClass(static::class);
|
||||
if ($class->isFinal()) {
|
||||
throw new \RuntimeException('createParameters() should not be called from final classes (' . static::class . ')');
|
||||
}
|
||||
|
||||
$params = new Parameters();
|
||||
if (count($args) == 2 && $args[0] instanceof BigInteger && $args[1] instanceof BigInteger) {
|
||||
//if (!$args[0]->isPrime()) {
|
||||
@ -242,6 +247,11 @@ abstract class DH extends AsymmetricKey
|
||||
*/
|
||||
public static function createKey(Parameters $params, int $length = 0): PrivateKey
|
||||
{
|
||||
$class = new \ReflectionClass(static::class);
|
||||
if ($class->isFinal()) {
|
||||
throw new \RuntimeException('createKey() should not be called from final classes (' . static::class . ')');
|
||||
}
|
||||
|
||||
$one = new BigInteger(1);
|
||||
if ($length) {
|
||||
$max = $one->bitwise_leftShift($length);
|
||||
@ -380,9 +390,9 @@ abstract class DH extends AsymmetricKey
|
||||
*/
|
||||
public function getParameters(): AsymmetricKey
|
||||
{
|
||||
$type = self::validatePlugin('Keys', 'PKCS1', 'saveParameters');
|
||||
$type = DH::validatePlugin('Keys', 'PKCS1', 'saveParameters');
|
||||
|
||||
$key = $type::saveParameters($this->prime, $this->base);
|
||||
return self::load($key, 'PKCS1');
|
||||
return DH::load($key, 'PKCS1');
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ use phpseclib3\Crypt\DH;
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
class Parameters extends DH
|
||||
final class Parameters extends DH
|
||||
{
|
||||
/**
|
||||
* Returns the parameters
|
||||
|
@ -22,7 +22,7 @@ use phpseclib3\Math\BigInteger;
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
class PrivateKey extends DH
|
||||
final class PrivateKey extends DH
|
||||
{
|
||||
use Common\Traits\PasswordProtected;
|
||||
|
||||
|
@ -22,7 +22,7 @@ use phpseclib3\Math\BigInteger;
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
class PublicKey extends DH
|
||||
final class PublicKey extends DH
|
||||
{
|
||||
use Common\Traits\Fingerprint;
|
||||
|
||||
|
@ -106,6 +106,11 @@ abstract class DSA extends AsymmetricKey
|
||||
{
|
||||
self::initialize_static_variables();
|
||||
|
||||
$class = new \ReflectionClass(static::class);
|
||||
if ($class->isFinal()) {
|
||||
throw new \RuntimeException('createParameters() should not be called from final classes (' . static::class . ')');
|
||||
}
|
||||
|
||||
if (!isset(self::$engines['PHP'])) {
|
||||
self::useBestEngine();
|
||||
}
|
||||
@ -181,6 +186,11 @@ abstract class DSA extends AsymmetricKey
|
||||
{
|
||||
self::initialize_static_variables();
|
||||
|
||||
$class = new \ReflectionClass(static::class);
|
||||
if ($class->isFinal()) {
|
||||
throw new \RuntimeException('createKey() should not be called from final classes (' . static::class . ')');
|
||||
}
|
||||
|
||||
if (!isset(self::$engines['PHP'])) {
|
||||
self::useBestEngine();
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ use phpseclib3\Crypt\DSA;
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
class Parameters extends DSA
|
||||
final class Parameters extends DSA
|
||||
{
|
||||
/**
|
||||
* Returns the parameters
|
||||
|
@ -23,7 +23,7 @@ use phpseclib3\Math\BigInteger;
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
class PrivateKey extends DSA implements Common\PrivateKey
|
||||
final class PrivateKey extends DSA implements Common\PrivateKey
|
||||
{
|
||||
use Common\Traits\PasswordProtected;
|
||||
|
||||
|
@ -22,7 +22,7 @@ use phpseclib3\Crypt\DSA\Formats\Signature\ASN1 as ASN1Signature;
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
class PublicKey extends DSA implements Common\PublicKey
|
||||
final class PublicKey extends DSA implements Common\PublicKey
|
||||
{
|
||||
use Common\Traits\Fingerprint;
|
||||
|
||||
|
@ -142,6 +142,11 @@ abstract class EC extends AsymmetricKey
|
||||
{
|
||||
self::initialize_static_variables();
|
||||
|
||||
$class = new \ReflectionClass(static::class);
|
||||
if ($class->isFinal()) {
|
||||
throw new \RuntimeException('createKey() should not be called from final classes (' . static::class . ')');
|
||||
}
|
||||
|
||||
if (!isset(self::$engines['PHP'])) {
|
||||
self::useBestEngine();
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ use phpseclib3\Crypt\EC;
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
class Parameters extends EC
|
||||
final class Parameters extends EC
|
||||
{
|
||||
/**
|
||||
* Returns the parameters
|
||||
|
@ -32,7 +32,7 @@ use phpseclib3\Math\BigInteger;
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
class PrivateKey extends EC implements Common\PrivateKey
|
||||
final class PrivateKey extends EC implements Common\PrivateKey
|
||||
{
|
||||
use Common\Traits\PasswordProtected;
|
||||
|
||||
|
@ -30,7 +30,7 @@ use phpseclib3\Math\BigInteger;
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
class PublicKey extends EC implements Common\PublicKey
|
||||
final class PublicKey extends EC implements Common\PublicKey
|
||||
{
|
||||
use Common\Traits\Fingerprint;
|
||||
|
||||
|
@ -299,6 +299,11 @@ abstract class RSA extends AsymmetricKey
|
||||
{
|
||||
self::initialize_static_variables();
|
||||
|
||||
$class = new \ReflectionClass(static::class);
|
||||
if ($class->isFinal()) {
|
||||
throw new \RuntimeException('createKey() should not be called from final classes (' . static::class . ')');
|
||||
}
|
||||
|
||||
$regSize = $bits >> 1; // divide by two to see how many bits P and Q would be
|
||||
if ($regSize > self::$smallestPrime) {
|
||||
$num_primes = floor($bits / self::$smallestPrime);
|
||||
|
@ -28,7 +28,7 @@ use phpseclib3\Math\BigInteger;
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
class PrivateKey extends RSA implements Common\PrivateKey
|
||||
final class PrivateKey extends RSA implements Common\PrivateKey
|
||||
{
|
||||
use Common\Traits\PasswordProtected;
|
||||
|
||||
|
@ -32,7 +32,7 @@ use phpseclib3\Math\BigInteger;
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
class PublicKey extends RSA implements Common\PublicKey
|
||||
final class PublicKey extends RSA implements Common\PublicKey
|
||||
{
|
||||
use Common\Traits\Fingerprint;
|
||||
|
||||
|
@ -110,6 +110,7 @@ class SSH2Test extends PhpseclibFunctionalTestCase
|
||||
/**
|
||||
* @depends testPasswordLogin
|
||||
* @group github280
|
||||
* @requires PHPUnit < 10
|
||||
*/
|
||||
public function testExecWithMethodCallback(SSH2 $ssh): SSH2
|
||||
{
|
||||
|
@ -99,66 +99,36 @@ abstract class PhpseclibTestCase extends TestCase
|
||||
// assertIsArray was not introduced until PHPUnit 8
|
||||
public static function assertIsArray($actual, string $message = ''): void
|
||||
{
|
||||
if (method_exists(parent::class, 'assertIsArray')) {
|
||||
parent::assertIsArray($actual, $message);
|
||||
return;
|
||||
}
|
||||
|
||||
parent::assertInternalType('array', $actual, $message);
|
||||
}
|
||||
|
||||
// assertIsString was not introduced until PHPUnit 8
|
||||
public static function assertIsString($actual, string $message = ''): void
|
||||
{
|
||||
if (method_exists(parent::class, 'assertIsString')) {
|
||||
parent::assertIsString($actual, $message);
|
||||
return;
|
||||
}
|
||||
|
||||
parent::assertInternalType('string', $actual, $message);
|
||||
}
|
||||
|
||||
// assertIsResource was not introduced until PHPUnit 8
|
||||
public static function assertIsResource($actual, string $message = ''): void
|
||||
{
|
||||
if (method_exists(parent::class, 'assertIsResource')) {
|
||||
parent::assertIsResource($actual, $message);
|
||||
return;
|
||||
}
|
||||
|
||||
parent::assertInternalType('resource', $actual, $message);
|
||||
}
|
||||
|
||||
// assertIsObject was not introduced until PHPUnit 8
|
||||
public static function assertIsObject($actual, string $message = ''): void
|
||||
{
|
||||
if (method_exists(parent::class, 'assertIsObject')) {
|
||||
parent::assertIsObject($actual, $message);
|
||||
return;
|
||||
}
|
||||
|
||||
parent::assertInternalType('object', $actual, $message);
|
||||
}
|
||||
|
||||
// assertContains is deprecated for strings in PHPUnit 8
|
||||
public static function assertStringContainsString(string $needle, string $haystack, string $message = ''): void
|
||||
{
|
||||
if (method_exists(parent::class, 'assertStringContainsString')) {
|
||||
parent::assertStringContainsString($needle, $haystack, $message);
|
||||
return;
|
||||
}
|
||||
|
||||
parent::assertContains($needle, $haystack, $message);
|
||||
}
|
||||
|
||||
// assertNotContains is deprecated for strings in PHPUnit 8
|
||||
public static function assertStringNotContainsString(string $needle, string $haystack, string $message = ''): void
|
||||
{
|
||||
if (method_exists(parent::class, 'assertStringContainsString')) {
|
||||
parent::assertStringNotContainsString($needle, $haystack, $message);
|
||||
return;
|
||||
}
|
||||
|
||||
parent::assertNotContains($needle, $haystack, $message);
|
||||
}
|
||||
|
||||
@ -167,10 +137,6 @@ abstract class PhpseclibTestCase extends TestCase
|
||||
*/
|
||||
public static function assertMatchesRegularExpression(string $pattern, string $string, string $message = ''): void
|
||||
{
|
||||
if (method_exists(parent::class, 'assertMatchesRegularExpression')) {
|
||||
parent::assertMatchesRegularExpression($pattern, $string, $message);
|
||||
} else {
|
||||
parent::assertRegExp($pattern, $string, $message);
|
||||
}
|
||||
parent::assertRegExp($pattern, $string, $message);
|
||||
}
|
||||
}
|
||||
|
@ -171,7 +171,7 @@ class HashTest extends PhpseclibTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider hmacData()
|
||||
* @dataProvider hmacData
|
||||
*/
|
||||
public function testHMAC($hash, $key, $message, $result): void
|
||||
{
|
||||
@ -179,7 +179,7 @@ class HashTest extends PhpseclibTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider hmacData()
|
||||
* @dataProvider hmacData
|
||||
*/
|
||||
public function testHMAC96($hash, $key, $message, $result): void
|
||||
{
|
||||
@ -372,7 +372,7 @@ class HashTest extends PhpseclibTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider hashData()
|
||||
* @dataProvider hashData
|
||||
*/
|
||||
public function testHash($hash, $message, $result): void
|
||||
{
|
||||
@ -380,7 +380,7 @@ class HashTest extends PhpseclibTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider hashData()
|
||||
* @dataProvider hashData
|
||||
*/
|
||||
public function testHash96($hash, $message, $result): void
|
||||
{
|
||||
|
@ -34,6 +34,7 @@ class SSH2UnitTest extends PhpseclibTestCase
|
||||
|
||||
/**
|
||||
* @dataProvider formatLogDataProvider
|
||||
* @requires PHPUnit < 10
|
||||
*/
|
||||
public function testFormatLog(array $message_log, array $message_number_log, $expected): void
|
||||
{
|
||||
@ -43,6 +44,9 @@ class SSH2UnitTest extends PhpseclibTestCase
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHPUnit < 10
|
||||
*/
|
||||
public function testGenerateIdentifier(): void
|
||||
{
|
||||
$identifier = self::callFunc($this->createSSHMock(), 'generate_identifier');
|
||||
@ -70,6 +74,9 @@ class SSH2UnitTest extends PhpseclibTestCase
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHPUnit < 10
|
||||
*/
|
||||
public function testGetExitStatusIfNotConnected(): void
|
||||
{
|
||||
$ssh = $this->createSSHMock();
|
||||
@ -77,12 +84,18 @@ class SSH2UnitTest extends PhpseclibTestCase
|
||||
$this->assertFalse($ssh->getExitStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHPUnit < 10
|
||||
*/
|
||||
public function testPTYIDefaultValue(): void
|
||||
{
|
||||
$ssh = $this->createSSHMock();
|
||||
$this->assertFalse($ssh->isPTYEnabled());
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHPUnit < 10
|
||||
*/
|
||||
public function testEnablePTY(): void
|
||||
{
|
||||
$ssh = $this->createSSHMock();
|
||||
@ -94,6 +107,9 @@ class SSH2UnitTest extends PhpseclibTestCase
|
||||
$this->assertFalse($ssh->isPTYEnabled());
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHPUnit < 10
|
||||
*/
|
||||
public function testQuietModeDefaultValue(): void
|
||||
{
|
||||
$ssh = $this->createSSHMock();
|
||||
@ -101,6 +117,9 @@ class SSH2UnitTest extends PhpseclibTestCase
|
||||
$this->assertFalse($ssh->isQuietModeEnabled());
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHPUnit < 10
|
||||
*/
|
||||
public function testEnableQuietMode(): void
|
||||
{
|
||||
$ssh = $this->createSSHMock();
|
||||
|
31
tests/make_compatible_with_phpunit7.php
Normal file
31
tests/make_compatible_with_phpunit7.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/** @var iterable<SplFileInfo> $files */
|
||||
$files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(__DIR__));
|
||||
foreach ($files as $file) {
|
||||
if ($file->getExtension() === 'php' && $file->getPathname() !== __FILE__) {
|
||||
$fileContents = file_get_contents($file->getPathname());
|
||||
if ($fileContents === false) {
|
||||
throw new \RuntimeException('file_get_contents() failed: ' . $file->getPathname());
|
||||
}
|
||||
$patternToReplacementMap = [
|
||||
'~ function setUpBeforeClass\(\)~' => ' function setUpBeforeClass(): void',
|
||||
'~ function setUp\(\)~' => ' function setUp(): void',
|
||||
'~ function tearDown\(\)~' => ' function tearDown(): void',
|
||||
'~ function assertIsArray\(\$actual, \$message = \'\'\)~' => ' function _assertIsArray($actual, string $message = \'\')',
|
||||
'~ function assertIsResource\(\$actual, \$message = \'\'\)~' => ' function _assertIsResource($actual, string $message = \'\')',
|
||||
'~ function assertIsObject\(\$actual, \$message = \'\'\)~' => ' function _assertIsObject($actual, string $message = \'\')',
|
||||
'~ function assertIsString\(\$actual, \$message = \'\'\)~' => ' function _assertIsString($actual, string $message = \'\')',
|
||||
'~ function assertStringContainsString\(\$needle, \$haystack, \$message = \'\'\)~' => ' function _assertStringContainsString(string $needle, string $haystack, string $message = \'\')',
|
||||
'~ function assertStringNotContainsString\(\$needle, \$haystack, \$message = \'\'\)~' => ' function _assertStringNotContainsString(string $needle, string $haystack, string $message = \'\')'
|
||||
];
|
||||
$updatedFileContents = preg_replace(
|
||||
array_keys($patternToReplacementMap),
|
||||
array_values($patternToReplacementMap),
|
||||
$fileContents
|
||||
);
|
||||
if (file_put_contents($file->getPathname(), $updatedFileContents) === false) {
|
||||
throw new \RuntimeException('file_put_contents() failed: ' . $file->getPathname());
|
||||
}
|
||||
}
|
||||
}
|
23
tests/make_compatible_with_phpunit9.php
Normal file
23
tests/make_compatible_with_phpunit9.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
/** @var iterable<SplFileInfo> $files */
|
||||
$files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(__DIR__));
|
||||
foreach ($files as $file) {
|
||||
if ($file->getExtension() === 'php' && $file->getPathname() !== __FILE__) {
|
||||
$fileContents = file_get_contents($file->getPathname());
|
||||
if ($fileContents === false) {
|
||||
throw new \RuntimeException('file_get_contents() failed: ' . $file->getPathname());
|
||||
}
|
||||
$patternToReplacementMap = [
|
||||
'~ function assertMatchesRegularExpression\(\$pattern, \$string, \$message = \'\'\)~' => ' function _assertMatchesRegularExpression(string $pattern, string $string, string $message = \'\')',
|
||||
];
|
||||
$updatedFileContents = preg_replace(
|
||||
array_keys($patternToReplacementMap),
|
||||
array_values($patternToReplacementMap),
|
||||
$fileContents
|
||||
);
|
||||
if (file_put_contents($file->getPathname(), $updatedFileContents) === false) {
|
||||
throw new \RuntimeException('file_put_contents() failed: ' . $file->getPathname());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user