diff --git a/bignp256/Cargo.toml b/bignp256/Cargo.toml index dc2d53df8..3ed4d1474 100644 --- a/bignp256/Cargo.toml +++ b/bignp256/Cargo.toml @@ -51,7 +51,7 @@ arithmetic = ["dep:primefield", "dep:primeorder", "elliptic-curve/arithmetic"] bits = ["arithmetic", "elliptic-curve/bits"] ecdsa = ["arithmetic", "dep:rfc6979", "dep:signature", "dep:belt-hash"] getrandom = ["elliptic-curve/getrandom"] -pem = ["pkcs8/pem", "sec1/pem"] +pem = ["pkcs8", "pkcs8/pem", "sec1/pem"] pkcs8 = ["dep:pkcs8"] ecdh = ["arithmetic", "elliptic-curve/ecdh", "dep:digest", "dep:hkdf", "dep:hmac", "dep:belt-hash", "alloc"] serde = ["elliptic-curve/serde", "primeorder?/serde"] diff --git a/bignp256/src/public_key.rs b/bignp256/src/public_key.rs index 267bff3dc..2d59b8f20 100644 --- a/bignp256/src/public_key.rs +++ b/bignp256/src/public_key.rs @@ -1,7 +1,9 @@ //! Public key types and traits // TODO(tarcieri): replace with `elliptic_curve::PublicKey` -use crate::{ALGORITHM_OID, AffinePoint, BignP256, NonZeroScalar, ProjectivePoint, Sec1Point}; +#[cfg(feature = "pkcs8")] +use crate::ALGORITHM_OID; +use crate::{AffinePoint, BignP256, NonZeroScalar, ProjectivePoint, Sec1Point}; use core::{fmt::Display, str::FromStr}; use elliptic_curve::{ CurveArithmetic, Error, Group, @@ -9,6 +11,7 @@ use elliptic_curve::{ point::NonIdentity, sec1::{FromSec1Point, ToSec1Point}, }; +#[cfg(feature = "pkcs8")] use pkcs8::{ AssociatedOid, DecodePublicKey, EncodePublicKey, ObjectIdentifier, spki::{AlgorithmIdentifier, AssociatedAlgorithmIdentifier}, diff --git a/bignp256/src/secret_key.rs b/bignp256/src/secret_key.rs index c88a8f0c9..7784dc2b1 100644 --- a/bignp256/src/secret_key.rs +++ b/bignp256/src/secret_key.rs @@ -4,8 +4,11 @@ use core::str::FromStr; use der::{SecretDocument, asn1::OctetStringRef}; -use crate::{ALGORITHM_OID, PublicKey, ScalarValue}; +#[cfg(feature = "pkcs8")] +use crate::ALGORITHM_OID; +use crate::{PublicKey, ScalarValue}; use elliptic_curve::{Error, Generate, array::typenum::Unsigned, zeroize::Zeroizing}; +#[cfg(feature = "pkcs8")] use pkcs8::{ AssociatedOid, DecodePrivateKey, EncodePrivateKey, ObjectIdentifier, spki::{AlgorithmIdentifier, AssociatedAlgorithmIdentifier}, @@ -95,6 +98,7 @@ impl SecretKey { } } +#[cfg(feature = "pkcs8")] impl AssociatedAlgorithmIdentifier for SecretKey { type Params = ObjectIdentifier; const ALGORITHM_IDENTIFIER: AlgorithmIdentifier = AlgorithmIdentifier { @@ -135,6 +139,7 @@ impl Generate for SecretKey { } } +#[cfg(feature = "pkcs8")] impl TryFrom> for SecretKey { type Error = pkcs8::Error; @@ -155,6 +160,7 @@ impl FromStr for SecretKey { } } +#[cfg(feature = "pkcs8")] impl EncodePrivateKey for SecretKey { fn to_pkcs8_der(&self) -> pkcs8::Result { let algorithm_identifier = pkcs8::AlgorithmIdentifierRef {