mirror of
https://github.com/phpseclib/phpseclib.git
synced 2024-12-26 03:27:31 +00:00
Merge branch '3.0'
This commit is contained in:
commit
cfaeb34813
@ -35,6 +35,7 @@ declare(strict_types=1);
|
||||
namespace phpseclib3\System\SSH;
|
||||
|
||||
use phpseclib3\Common\Functions\Strings;
|
||||
use phpseclib3\Crypt\Common\PublicKey;
|
||||
use phpseclib3\Crypt\PublicKeyLoader;
|
||||
use phpseclib3\Exception\BadConfigurationException;
|
||||
use phpseclib3\Exception\RuntimeException;
|
||||
@ -193,7 +194,8 @@ class Agent
|
||||
if (isset($key)) {
|
||||
$identity = (new Identity($this->fsock))
|
||||
->withPublicKey($key)
|
||||
->withPublicKeyBlob($key_blob);
|
||||
->withPublicKeyBlob($key_blob)
|
||||
->withComment($comment);
|
||||
$identities[] = $identity;
|
||||
unset($key);
|
||||
}
|
||||
@ -202,6 +204,24 @@ class Agent
|
||||
return $identities;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the SSH Agent identity matching a given public key or null if no identity is found
|
||||
*
|
||||
* @return ?Identity
|
||||
*/
|
||||
public function findIdentityByPublicKey(PublicKey $key)
|
||||
{
|
||||
$identities = $this->requestIdentities();
|
||||
$key = (string) $key;
|
||||
foreach ($identities as $identity) {
|
||||
if (((string) $identity->getPublicKey()) == $key) {
|
||||
return $identity;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Signal that agent forwarding should
|
||||
* be requested when a channel is opened
|
||||
@ -216,7 +236,7 @@ class Agent
|
||||
/**
|
||||
* Request agent forwarding of remote server
|
||||
*/
|
||||
private function request_forwarding(SSH2 $ssh)
|
||||
private function request_forwarding(SSH2 $ssh): bool
|
||||
{
|
||||
if (!$ssh->requestAgentForwarding()) {
|
||||
return false;
|
||||
|
@ -82,6 +82,13 @@ class Identity implements PrivateKey
|
||||
*/
|
||||
private $flags = 0;
|
||||
|
||||
/**
|
||||
* Comment
|
||||
*
|
||||
* @var null|string
|
||||
*/
|
||||
private $comment;
|
||||
|
||||
/**
|
||||
* Curve Aliases
|
||||
*
|
||||
@ -139,10 +146,8 @@ class Identity implements PrivateKey
|
||||
* Get Public Key
|
||||
*
|
||||
* Wrapper for $this->key->getPublicKey()
|
||||
*
|
||||
* @param string $type optional
|
||||
*/
|
||||
public function getPublicKey(string $type = 'PKCS8'): PublicKey
|
||||
public function getPublicKey(): PublicKey
|
||||
{
|
||||
return $this->key;
|
||||
}
|
||||
@ -305,4 +310,24 @@ class Identity implements PrivateKey
|
||||
{
|
||||
throw new RuntimeException('ssh-agent does not provide a mechanism to get the private key');
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the comment
|
||||
*/
|
||||
public function withComment($comment = null)
|
||||
{
|
||||
$new = clone $this;
|
||||
$new->comment = $comment;
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the comment
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public function getComment()
|
||||
{
|
||||
return $this->comment;
|
||||
}
|
||||
}
|
||||
|
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