From e3efed5803cd6cba874fdbe151ff71977e2ece52 Mon Sep 17 00:00:00 2001 From: Arthur Gautier Date: Wed, 5 Aug 2026 20:49:05 +0000 Subject: [PATCH] cms: remove the direct dependency on `std` `cms` has a strong dependency on `liballoc`, this replaces the various `std::vec` with `alloc::vec` and drops the std feature. The `std` feature is kept only to forward the feature to `der`, `spki`, and `x509-cert` crates. --- cms/src/builder/kari.rs | 2 ++ cms/src/enveloped_data.rs | 8 ++++---- cms/src/lib.rs | 3 --- cms/src/revocation.rs | 6 +++--- cms/src/signed_data.rs | 11 +++++------ 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/cms/src/builder/kari.rs b/cms/src/builder/kari.rs index 92debb725..a60eed7c6 100644 --- a/cms/src/builder/kari.rs +++ b/cms/src/builder/kari.rs @@ -395,6 +395,8 @@ where #[cfg(test)] mod tests { + extern crate std; + use std::eprintln; use super::*; diff --git a/cms/src/enveloped_data.rs b/cms/src/enveloped_data.rs index 8a0a3c12b..fd46820d2 100644 --- a/cms/src/enveloped_data.rs +++ b/cms/src/enveloped_data.rs @@ -5,6 +5,7 @@ use crate::content_info::CmsVersion; use crate::revocation::RevocationInfoChoices; use crate::signed_data::CertificateSet; +use alloc::vec; use core::cmp::Ordering; use der::asn1::{BitString, GeneralizedTime, ObjectIdentifier, OctetString, SetOfVec}; use der::{Any, Choice, Sequence, ValueOrd}; @@ -88,11 +89,10 @@ pub struct OriginatorInfo { pub struct RecipientInfos(pub SetOfVec); impl_newtype!(RecipientInfos, SetOfVec); -#[cfg(feature = "std")] -impl TryFrom> for RecipientInfos { +impl TryFrom> for RecipientInfos { type Error = der::Error; - fn try_from(vec: std::vec::Vec) -> der::Result { + fn try_from(vec: vec::Vec) -> der::Result { Ok(RecipientInfos(SetOfVec::try_from(vec)?)) } } @@ -268,7 +268,7 @@ pub struct OriginatorPublicKey { /// ``` /// /// [RFC 5652 Section 6.2.2]: https://www.rfc-editor.org/rfc/rfc5652#section-6.2.2 -pub type RecipientEncryptedKeys = alloc::vec::Vec; +pub type RecipientEncryptedKeys = vec::Vec; /// The `RecipientEncryptedKey` type is defined in [RFC 5652 Section 6.2.2]. /// diff --git a/cms/src/lib.rs b/cms/src/lib.rs index 86e769c96..53749543d 100644 --- a/cms/src/lib.rs +++ b/cms/src/lib.rs @@ -24,9 +24,6 @@ extern crate alloc; -#[cfg(feature = "std")] -extern crate std; - pub mod attr; pub mod authenticated_data; pub mod authenveloped_data; diff --git a/cms/src/revocation.rs b/cms/src/revocation.rs index 5f61c87b0..e0b584772 100644 --- a/cms/src/revocation.rs +++ b/cms/src/revocation.rs @@ -1,4 +1,5 @@ //! Revocation-related types +use alloc::vec; use core::cmp::Ordering; use der::asn1::SetOfVec; @@ -47,11 +48,10 @@ impl ValueOrd for RevocationInfoChoice { } } -#[cfg(feature = "std")] -impl TryFrom> for RevocationInfoChoices { +impl TryFrom> for RevocationInfoChoices { type Error = der::Error; - fn try_from(vec: std::vec::Vec) -> der::Result { + fn try_from(vec: vec::Vec) -> der::Result { Ok(RevocationInfoChoices(SetOfVec::try_from(vec)?)) } } diff --git a/cms/src/signed_data.rs b/cms/src/signed_data.rs index ea53c83dc..0a7f84743 100644 --- a/cms/src/signed_data.rs +++ b/cms/src/signed_data.rs @@ -4,6 +4,7 @@ use crate::cert::{CertificateChoices, IssuerAndSerialNumber}; use crate::content_info::CmsVersion; use crate::revocation::RevocationInfoChoices; +use alloc::vec; use core::cmp::Ordering; use der::asn1::{ObjectIdentifier, OctetString, SetOfVec}; use der::{Any, Choice, DerOrd, Sequence, ValueOrd}; @@ -59,11 +60,10 @@ pub type DigestAlgorithmIdentifiers = SetOfVec; pub struct CertificateSet(pub SetOfVec); impl_newtype!(CertificateSet, SetOfVec); -#[cfg(feature = "std")] -impl TryFrom> for CertificateSet { +impl TryFrom> for CertificateSet { type Error = der::Error; - fn try_from(vec: std::vec::Vec) -> der::Result { + fn try_from(vec: vec::Vec) -> der::Result { Ok(CertificateSet(SetOfVec::try_from(vec)?)) } } @@ -79,11 +79,10 @@ impl TryFrom> for CertificateSet { pub struct SignerInfos(pub SetOfVec); impl_newtype!(SignerInfos, SetOfVec); -#[cfg(feature = "std")] -impl TryFrom> for SignerInfos { +impl TryFrom> for SignerInfos { type Error = der::Error; - fn try_from(vec: std::vec::Vec) -> der::Result { + fn try_from(vec: vec::Vec) -> der::Result { Ok(SignerInfos(SetOfVec::try_from(vec)?)) } }