From 90b77263839ddb301a537cb996edc02d80eba56e Mon Sep 17 00:00:00 2001 From: Michael Newton Date: Wed, 17 Sep 2025 11:15:31 -0600 Subject: [PATCH 1/2] use less specific argument type None of the other classes use the more specific AsymmetricCryptoAlgorithmIdentifier for their properties, so e.g. return from OneAsymmetricKey::algorithmIdentifier() can't be used without IDE complaints. The switch statement will still weed out incorrect arguments --- .../Signature/SignatureAlgorithmIdentifierFactory.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/CryptoTypes/AlgorithmIdentifier/Signature/SignatureAlgorithmIdentifierFactory.php b/lib/CryptoTypes/AlgorithmIdentifier/Signature/SignatureAlgorithmIdentifierFactory.php index 8c63ff4..121254f 100644 --- a/lib/CryptoTypes/AlgorithmIdentifier/Signature/SignatureAlgorithmIdentifierFactory.php +++ b/lib/CryptoTypes/AlgorithmIdentifier/Signature/SignatureAlgorithmIdentifierFactory.php @@ -6,7 +6,7 @@ use Sop\CryptoTypes\AlgorithmIdentifier\AlgorithmIdentifier; use Sop\CryptoTypes\AlgorithmIdentifier\AlgorithmIdentifierFactory; -use Sop\CryptoTypes\AlgorithmIdentifier\Feature\AsymmetricCryptoAlgorithmIdentifier; +use Sop\CryptoTypes\AlgorithmIdentifier\Feature\AlgorithmIdentifierType; use Sop\CryptoTypes\AlgorithmIdentifier\Feature\HashAlgorithmIdentifier; use Sop\CryptoTypes\AlgorithmIdentifier\Feature\SignatureAlgorithmIdentifier; @@ -50,13 +50,13 @@ abstract class SignatureAlgorithmIdentifierFactory * Get signature algorithm identifier of given asymmetric cryptographic type * utilizing given hash algorithm. * - * @param AsymmetricCryptoAlgorithmIdentifier $crypto_algo Cryptographic algorithm identifier, eg. RSA or EC + * @param AlgorithmIdentifierType $crypto_algo Cryptographic algorithm identifier, eg. RSA or EC * @param HashAlgorithmIdentifier $hash_algo Hash algorithm identifier * * @throws \UnexpectedValueException */ public static function algoForAsymmetricCrypto( - AsymmetricCryptoAlgorithmIdentifier $crypto_algo, + AlgorithmIdentifierType $crypto_algo, HashAlgorithmIdentifier $hash_algo): SignatureAlgorithmIdentifier { switch ($crypto_algo->oid()) { From 1d71ef57d1dc5f979e03c26339116befc73721e4 Mon Sep 17 00:00:00 2001 From: Michael Newton Date: Wed, 17 Sep 2025 11:52:50 -0600 Subject: [PATCH 2/2] use less specific type `PrivateKeyInfo` inherits from `OneAsymmetricKey` with no changes. This call should expect the less specific type since that's what other methods (e.g. `PrivateKeyInfo::fromPEM()`) return --- lib/CryptoTypes/Asymmetric/PrivateKey.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/CryptoTypes/Asymmetric/PrivateKey.php b/lib/CryptoTypes/Asymmetric/PrivateKey.php index c3b4bea..41f0b6d 100644 --- a/lib/CryptoTypes/Asymmetric/PrivateKey.php +++ b/lib/CryptoTypes/Asymmetric/PrivateKey.php @@ -44,11 +44,11 @@ public function privateKeyData(): string } /** - * Get the private key as a PrivateKeyInfo type. + * Get the private key as a OneAsymmetricKey type. */ - public function privateKeyInfo(): PrivateKeyInfo + public function privateKeyInfo(): OneAsymmetricKey { - return PrivateKeyInfo::fromPrivateKey($this); + return OneAsymmetricKey::fromPrivateKey($this); } /** @@ -66,7 +66,7 @@ public static function fromPEM(PEM $pem) case PEM::TYPE_EC_PRIVATE_KEY: return EC\ECPrivateKey::fromDER($pem->data()); case PEM::TYPE_PRIVATE_KEY: - return PrivateKeyInfo::fromDER($pem->data())->privateKey(); + return OneAsymmetricKey::fromDER($pem->data())->privateKey(); } throw new \UnexpectedValueException( 'PEM type ' . $pem->type() . ' is not a valid private key.');