@@ -2124,6 +2124,7 @@ EVPKeyPointer::ParseKeyResult EVPKeyPointer::TryParsePrivateKey(
21242124 ERR_GET_REASON (err) == PEM_R_BAD_PASSWORD_READ && !had_passphrase) {
21252125 return ParseKeyResult (PKParseError::NEED_PASSPHRASE);
21262126 }
2127+
21272128 return ParseKeyResult (PKParseError::FAILED, err);
21282129 }
21292130 if (!pkey) return ParseKeyResult (PKParseError::FAILED);
@@ -2195,11 +2196,8 @@ Result<BIOPointer, bool> EVPKeyPointer::writePrivateKey(
21952196 // PKCS1 is only permitted for RSA keys.
21962197 if (id () != EVP_PKEY_RSA) return Result<BIOPointer, bool >(false );
21972198
2198- #if OPENSSL_VERSION_MAJOR >= 3
2199- const RSA* rsa = EVP_PKEY_get0_RSA (get ());
2200- #else
2201- RSA* rsa = EVP_PKEY_get0_RSA (get ());
2202- #endif
2199+ OSSL3_CONST RSA* rsa = EVP_PKEY_get0_RSA (get ());
2200+
22032201 switch (config.format ) {
22042202 case PKFormatType::PEM: {
22052203 err = PEM_write_bio_RSAPrivateKey (
@@ -2246,11 +2244,8 @@ Result<BIOPointer, bool> EVPKeyPointer::writePrivateKey(
22462244 // SEC1 is only permitted for EC keys
22472245 if (id () != EVP_PKEY_EC) return Result<BIOPointer, bool >(false );
22482246
2249- #if OPENSSL_VERSION_MAJOR >= 3
2250- const EC_KEY* ec = EVP_PKEY_get0_EC_KEY (get ());
2251- #else
2252- EC_KEY* ec = EVP_PKEY_get0_EC_KEY (get ());
2253- #endif
2247+ OSSL3_CONST EC_KEY* ec = EVP_PKEY_get0_EC_KEY (get ());
2248+
22542249 switch (config.format ) {
22552250 case PKFormatType::PEM: {
22562251 err = PEM_write_bio_ECPrivateKey (
@@ -2399,6 +2394,15 @@ EVPKeyPointer::operator Dsa() const {
23992394 return Dsa (dsa);
24002395}
24012396
2397+ EVPKeyPointer::operator Ec () const {
2398+ int type = id ();
2399+ if (type != EVP_PKEY_EC) return {};
2400+
2401+ OSSL3_CONST EC_KEY* ec = EVP_PKEY_get0_EC_KEY (get ());
2402+ if (ec == nullptr ) return {};
2403+ return Ec (ec);
2404+ }
2405+
24022406bool EVPKeyPointer::validateDsaParameters () const {
24032407 if (!pkey_) return false ;
24042408 /* Validate DSA2 parameters from FIPS 186-4 */
0 commit comments