CS adjustments

This commit is contained in:
terrafrost 2024-11-22 17:58:43 -06:00
parent 7070529e79
commit 7c56d2ca07
7 changed files with 11 additions and 16 deletions

View File

@ -129,10 +129,8 @@ abstract class PKCS8 extends PKCS
/** /**
* Returns a SymmetricKey object based on a PBES1 $algo * Returns a SymmetricKey object based on a PBES1 $algo
*
* @return SymmetricKey
*/ */
private static function getPBES1EncryptionObject(string $algo) private static function getPBES1EncryptionObject(string $algo): SymmetricKey
{ {
$algo = preg_match('#^pbeWith(?:MD2|MD5|SHA1|SHA)And(.*?)-CBC$#', $algo, $matches) ? $algo = preg_match('#^pbeWith(?:MD2|MD5|SHA1|SHA)And(.*?)-CBC$#', $algo, $matches) ?
$matches[1] : $matches[1] :
@ -511,7 +509,7 @@ abstract class PKCS8 extends PKCS
* *
* @param bool $enabled * @param bool $enabled
*/ */
public static function setBinaryOutput($enabled) public static function setBinaryOutput($enabled): void
{ {
self::$binary = $enabled; self::$binary = $enabled;
} }
@ -616,7 +614,7 @@ abstract class PKCS8 extends PKCS
$key = ASN1::encodeDER($key, Maps\EncryptedPrivateKeyInfo::MAP); $key = ASN1::encodeDER($key, Maps\EncryptedPrivateKeyInfo::MAP);
if (isset($options['binary']) ? $options['binary'] : self::$binary) { if ($options['binary'] ?? self::$binary) {
return $key; return $key;
} }
@ -625,7 +623,7 @@ abstract class PKCS8 extends PKCS
"-----END ENCRYPTED PRIVATE KEY-----"; "-----END ENCRYPTED PRIVATE KEY-----";
} }
if (isset($options['binary']) ? $options['binary'] : self::$binary) { if ($options['binary'] ?? self::$binary) {
return $key; return $key;
} }
@ -654,7 +652,7 @@ abstract class PKCS8 extends PKCS
$key = ASN1::encodeDER($key, Maps\PublicKeyInfo::MAP); $key = ASN1::encodeDER($key, Maps\PublicKeyInfo::MAP);
if (isset($options['binary']) ? $options['binary'] : self::$binary) { if ($options['binary'] ?? self::$binary) {
return $key; return $key;
} }

View File

@ -31,7 +31,7 @@ abstract class TBSCertList
'type' => ASN1::TYPE_INTEGER, 'type' => ASN1::TYPE_INTEGER,
'mapping' => ['v1', 'v2'], 'mapping' => ['v1', 'v2'],
'optional' => true, 'optional' => true,
'default' => 'v1' 'default' => 'v1',
], ],
'signature' => AlgorithmIdentifier::MAP, 'signature' => AlgorithmIdentifier::MAP,
'issuer' => Name::MAP, 'issuer' => Name::MAP,

View File

@ -3361,7 +3361,6 @@ class X509
* Returns the list of extensions if there are any and false if not * Returns the list of extensions if there are any and false if not
* *
* @param array $csr optional * @param array $csr optional
* @return mixed
*/ */
public function getRequestedCertificateExtensions(array $csr = null) public function getRequestedCertificateExtensions(array $csr = null)
{ {

View File

@ -3273,7 +3273,7 @@ class SFTP extends SSH2
} }
// if $status isn't SSH_FX_OK it's probably SSH_FX_NO_SUCH_FILE or SSH_FX_PERMISSION_DENIED // if $status isn't SSH_FX_OK it's probably SSH_FX_NO_SUCH_FILE or SSH_FX_PERMISSION_DENIED
list($status) = Strings::unpackSSH2('N', $response); [$status] = Strings::unpackSSH2('N', $response);
if ($status != StatusCode::OK) { if ($status != StatusCode::OK) {
$this->logError($response, $status); $this->logError($response, $status);
return false; return false;

View File

@ -3520,7 +3520,7 @@ class SSH2
private function handleDisconnect($payload) private function handleDisconnect($payload)
{ {
Strings::shift($payload, 1); Strings::shift($payload, 1);
list($reason_code, $message) = Strings::unpackSSH2('Ns', $payload); [$reason_code, $message] = Strings::unpackSSH2('Ns', $payload);
$this->errors[] = 'SSH_MSG_DISCONNECT: ' . self::$disconnect_reasons[$reason_code] . "\r\n$message"; $this->errors[] = 'SSH_MSG_DISCONNECT: ' . self::$disconnect_reasons[$reason_code] . "\r\n$message";
$this->disconnect_helper(NET_SSH2_DISCONNECT_CONNECTION_LOST); $this->disconnect_helper(NET_SSH2_DISCONNECT_CONNECTION_LOST);
throw new ConnectionClosedException('Connection closed by server'); throw new ConnectionClosedException('Connection closed by server');

View File

@ -184,7 +184,7 @@ yGSdZsGMatjn2ld+Ndj3uAYlujyKlqGcAOb53bu+PswH5KXTJJquOJH84UoKraog
$this->assertTrue(boolval($x509->getPublicKey()->getPadding() & RSA::SIGNATURE_PSS)); $this->assertTrue(boolval($x509->getPublicKey()->getPadding() & RSA::SIGNATURE_PSS));
} }
public function testAttributes() public function testAttributes(): void
{ {
$private = RSA::createKey(); $private = RSA::createKey();
$private = $private->withHash('sha256'); $private = $private->withHash('sha256');
@ -205,7 +205,7 @@ yGSdZsGMatjn2ld+Ndj3uAYlujyKlqGcAOb53bu+PswH5KXTJJquOJH84UoKraog
$extensions = [ $extensions = [
['extnId' => 'id-ce-basicConstraints', 'critical' => true, 'extnValue' => ['cA' => false]], ['extnId' => 'id-ce-basicConstraints', 'critical' => true, 'extnValue' => ['cA' => false]],
['extnId' => 'id-ce-keyUsage', 'critical' => true, 'extnValue' => ['digitalSignature', 'keyEncipherment']], ['extnId' => 'id-ce-keyUsage', 'critical' => true, 'extnValue' => ['digitalSignature', 'keyEncipherment']],
['extnId' => 'id-ce-extKeyUsage', 'extnValue' => ['id-kp-serverAuth', 'id-kp-clientAuth']] ['extnId' => 'id-ce-extKeyUsage', 'extnValue' => ['id-kp-serverAuth', 'id-kp-clientAuth']],
]; ];
$subject->setAttribute('pkcs-9-at-extensionRequest', $extensions); $subject->setAttribute('pkcs-9-at-extensionRequest', $extensions);

View File

@ -42,9 +42,7 @@ class SSH2UnitTest extends PhpseclibTestCase
public function testBitmapMasks(): void public function testBitmapMasks(): void
{ {
$reflection = new \ReflectionClass(SSH2::class); $reflection = new \ReflectionClass(SSH2::class);
$masks = array_filter($reflection->getConstants(), function ($k) { $masks = array_filter($reflection->getConstants(), fn ($k) => str_starts_with($k, 'MASK_'), ARRAY_FILTER_USE_KEY);
return str_starts_with($k, 'MASK_');
}, ARRAY_FILTER_USE_KEY);
$bitmap = 0; $bitmap = 0;
foreach ($masks as $mask => $bit) { foreach ($masks as $mask => $bit) {
$this->assertEquals(0, $bitmap & $bit, "Got unexpected mask {$mask}"); $this->assertEquals(0, $bitmap & $bit, "Got unexpected mask {$mask}");