From 970aacfaea00a18e84b78f9e616954c02d0cacb2 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Wed, 17 Jan 2024 15:09:20 +0000 Subject: [PATCH] ecdsa: gate `pkcs8::Encode*Key` impls under `alloc`+`pkcs8` (#783) ...rather than `pem`, as these can be used to encode DER without having full `pem` support enabled. Closes #721 --- ecdsa/src/signing.rs | 10 +++++----- ecdsa/src/verifying.rs | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ecdsa/src/signing.rs b/ecdsa/src/signing.rs index 5a551627..6d5d7f61 100644 --- a/ecdsa/src/signing.rs +++ b/ecdsa/src/signing.rs @@ -25,10 +25,7 @@ use signature::{ use {crate::der, core::ops::Add, elliptic_curve::FieldBytesSize}; #[cfg(feature = "pem")] -use { - core::str::FromStr, - elliptic_curve::pkcs8::{DecodePrivateKey, EncodePrivateKey, SecretDocument}, -}; +use {core::str::FromStr, elliptic_curve::pkcs8::DecodePrivateKey}; #[cfg(feature = "pkcs8")] use crate::elliptic_curve::{ @@ -45,6 +42,9 @@ use crate::elliptic_curve::{ #[cfg(feature = "verifying")] use {crate::VerifyingKey, elliptic_curve::PublicKey, signature::KeypairRef}; +#[cfg(all(feature = "alloc", feature = "pkcs8"))] +use elliptic_curve::pkcs8::{EncodePrivateKey, SecretDocument}; + /// ECDSA secret key used for signing. Generic over prime order elliptic curves /// (e.g. NIST P-curves) /// @@ -567,7 +567,7 @@ where } } -#[cfg(feature = "pem")] +#[cfg(all(feature = "alloc", feature = "pkcs8"))] impl EncodePrivateKey for SigningKey where C: AssociatedOid + PrimeCurve + CurveArithmetic, diff --git a/ecdsa/src/verifying.rs b/ecdsa/src/verifying.rs index eabdb6d8..8c9520c9 100644 --- a/ecdsa/src/verifying.rs +++ b/ecdsa/src/verifying.rs @@ -24,10 +24,7 @@ use alloc::boxed::Box; use {crate::der, core::ops::Add}; #[cfg(feature = "pem")] -use { - core::str::FromStr, - elliptic_curve::pkcs8::{DecodePublicKey, EncodePublicKey}, -}; +use {core::str::FromStr, elliptic_curve::pkcs8::DecodePublicKey}; #[cfg(feature = "pkcs8")] use elliptic_curve::pkcs8::{ @@ -45,6 +42,9 @@ use { sha2::{Sha224, Sha256, Sha384, Sha512}, }; +#[cfg(all(feature = "alloc", feature = "pkcs8"))] +use elliptic_curve::pkcs8::EncodePublicKey; + #[cfg(all(feature = "pem", feature = "serde"))] use serdect::serde::{de, ser, Deserialize, Serialize}; @@ -425,7 +425,7 @@ where } } -#[cfg(feature = "pem")] +#[cfg(all(feature = "alloc", feature = "pkcs8"))] impl EncodePublicKey for VerifyingKey where C: PrimeCurve + AssociatedOid + CurveArithmetic + PointCompression,