From 5bd941f03f977085c0eefbb6ff243461d1efe4af Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Fri, 21 Apr 2023 22:13:53 +1000 Subject: [PATCH] Fix feature `alloc` and `pem` in `pkcs1` (#1013) Avoid pulling in dep `pkcs8` or `zeroize` just because feature `alloc`/`pem`/`std` is enabled. Also removes unused dependency `zeeroize` and replace it with a feature. Signed-off-by: Jiahao XU --- Cargo.lock | 1 - pkcs1/Cargo.toml | 6 +++--- pkcs1/src/traits.rs | 10 +++++----- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e809d920f..e49dd820f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -977,7 +977,6 @@ dependencies = [ "pkcs8", "spki", "tempfile", - "zeroize", ] [[package]] diff --git a/pkcs1/Cargo.toml b/pkcs1/Cargo.toml index fd6da093b..d79186d0d 100644 --- a/pkcs1/Cargo.toml +++ b/pkcs1/Cargo.toml @@ -20,7 +20,6 @@ spki = { version = "0.7" } # optional dependencies pkcs8 = { version = "0.10", optional = true, default-features = false } -zeroize = { version = "1", optional = true, default-features = false } [dev-dependencies] const-oid = { version = "0.9", features = ["db"] } # TODO: path = "../const-oid" @@ -28,8 +27,9 @@ hex-literal = "0.4" tempfile = "3" [features] -alloc = ["der/alloc", "pkcs8/alloc", "zeroize/alloc"] -pem = ["alloc", "der/pem", "pkcs8/pem"] +zeroize = ["der/zeroize"] +alloc = ["der/alloc", "zeroize", "pkcs8?/alloc"] +pem = ["alloc", "der/pem", "pkcs8?/pem"] std = ["der/std", "alloc"] [package.metadata.docs.rs] diff --git a/pkcs1/src/traits.rs b/pkcs1/src/traits.rs index f8934ddd1..fda603e25 100644 --- a/pkcs1/src/traits.rs +++ b/pkcs1/src/traits.rs @@ -3,10 +3,7 @@ use crate::Result; #[cfg(feature = "alloc")] -use { - crate::{RsaPrivateKey, RsaPublicKey}, - der::SecretDocument, -}; +use der::{Document, SecretDocument}; #[cfg(feature = "pem")] use { @@ -24,8 +21,11 @@ use { #[cfg(feature = "std")] use std::path::Path; +#[cfg(all(feature = "alloc", feature = "pem"))] +use crate::{RsaPrivateKey, RsaPublicKey}; + #[cfg(all(feature = "alloc", feature = "pkcs8"))] -use der::{Decode, Document}; +use der::Decode; /// Parse an [`RsaPrivateKey`] from a PKCS#1-encoded document. pub trait DecodeRsaPrivateKey: Sized {