diff --git a/pkcs1/src/private_key/other_prime_info.rs b/pkcs1/src/private_key/other_prime_info.rs index c7ecbd3fc..0b4dca45c 100644 --- a/pkcs1/src/private_key/other_prime_info.rs +++ b/pkcs1/src/private_key/other_prime_info.rs @@ -1,6 +1,6 @@ //! PKCS#1 OtherPrimeInfo support. -use der::{asn1::UIntBytes, Decodable, Decoder, Encodable, Sequence}; +use der::{asn1::UIntBytes, Sequence}; /// PKCS#1 OtherPrimeInfo as defined in [RFC 8017 Appendix 1.2]. /// @@ -15,7 +15,7 @@ use der::{asn1::UIntBytes, Decodable, Decoder, Encodable, Sequence}; /// ``` /// /// [RFC 8017 Appendix 1.2]: https://datatracker.ietf.org/doc/html/rfc8017#appendix-A.1.2 -#[derive(Clone)] +#[derive(Clone, Sequence)] #[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] pub struct OtherPrimeInfo<'a> { /// Prime factor `r_i` of `n`, where `i` >= 3. @@ -27,24 +27,3 @@ pub struct OtherPrimeInfo<'a> { /// CRT coefficient: `t_i = (r_1 * r_2 * ... * r_(i-1))^(-1) mod r_i`. pub coefficient: UIntBytes<'a>, } - -impl<'a> Decodable<'a> for OtherPrimeInfo<'a> { - fn decode(decoder: &mut Decoder<'a>) -> der::Result { - decoder.sequence(|decoder| { - Ok(Self { - prime: decoder.decode()?, - exponent: decoder.decode()?, - coefficient: decoder.decode()?, - }) - }) - } -} - -impl<'a> Sequence<'a> for OtherPrimeInfo<'a> { - fn fields(&self, f: F) -> der::Result - where - F: FnOnce(&[&dyn Encodable]) -> der::Result, - { - f(&[&self.prime, &self.exponent, &self.coefficient]) - } -} diff --git a/pkcs1/src/public_key.rs b/pkcs1/src/public_key.rs index d7c039ee0..20f31a59b 100644 --- a/pkcs1/src/public_key.rs +++ b/pkcs1/src/public_key.rs @@ -4,7 +4,7 @@ pub(crate) mod document; use crate::{Error, Result}; -use der::{asn1::UIntBytes, Decodable, Decoder, Encodable, Sequence}; +use der::{asn1::UIntBytes, Decodable, Sequence}; #[cfg(feature = "alloc")] use crate::RsaPublicKeyDocument; @@ -24,7 +24,7 @@ use {crate::LineEnding, alloc::string::String, der::Document}; /// ``` /// /// [RFC 8017 Appendix 1.1]: https://datatracker.ietf.org/doc/html/rfc8017#appendix-A.1.1 -#[derive(Copy, Clone, Debug, Eq, PartialEq)] +#[derive(Copy, Clone, Debug, Eq, PartialEq, Sequence)] pub struct RsaPublicKey<'a> { /// `n`: RSA modulus pub modulus: UIntBytes<'a>, @@ -50,26 +50,6 @@ impl<'a> RsaPublicKey<'a> { } } -impl<'a> Decodable<'a> for RsaPublicKey<'a> { - fn decode(decoder: &mut Decoder<'a>) -> der::Result { - decoder.sequence(|decoder| { - Ok(Self { - modulus: decoder.decode()?, - public_exponent: decoder.decode()?, - }) - }) - } -} - -impl<'a> Sequence<'a> for RsaPublicKey<'a> { - fn fields(&self, f: F) -> der::Result - where - F: FnOnce(&[&dyn Encodable]) -> der::Result, - { - f(&[&self.modulus, &self.public_exponent]) - } -} - impl<'a> TryFrom<&'a [u8]> for RsaPublicKey<'a> { type Error = Error; diff --git a/pkcs5/src/pbes2.rs b/pkcs5/src/pbes2.rs index 4673f7a4e..830793927 100644 --- a/pkcs5/src/pbes2.rs +++ b/pkcs5/src/pbes2.rs @@ -64,7 +64,7 @@ const DES_BLOCK_SIZE: usize = 8; /// ``` /// /// [RFC 8018 Appendix A.4]: https://tools.ietf.org/html/rfc8018#appendix-A.4 -#[derive(Clone, Debug, Eq, PartialEq)] +#[derive(Clone, Debug, Eq, PartialEq, Sequence)] pub struct Parameters<'a> { /// Key derivation function pub kdf: Kdf<'a>, @@ -197,21 +197,6 @@ impl<'a> Parameters<'a> { } } -impl<'a> Decodable<'a> for Parameters<'a> { - fn decode(decoder: &mut Decoder<'a>) -> der::Result { - decoder.any()?.try_into() - } -} - -impl<'a> Sequence<'a> for Parameters<'a> { - fn fields(&self, f: F) -> der::Result - where - F: FnOnce(&[&dyn Encodable]) -> der::Result, - { - f(&[&self.kdf, &self.encryption]) - } -} - impl<'a> TryFrom> for Parameters<'a> { type Error = der::Error; diff --git a/pkcs7/src/encrypted_data_content.rs b/pkcs7/src/encrypted_data_content.rs index 28efa2a51..d7011a696 100644 --- a/pkcs7/src/encrypted_data_content.rs +++ b/pkcs7/src/encrypted_data_content.rs @@ -1,10 +1,7 @@ //! `encrypted-data` content type [RFC 5652 ยง 8](https://datatracker.ietf.org/doc/html/rfc5652#section-8) use crate::enveloped_data_content::EncryptedContentInfo; -use der::{ - Decodable, DecodeValue, Decoder, Encodable, EncodeValue, Encoder, FixedTag, Header, Length, - Sequence, Tag, -}; +use der::{DecodeValue, Decoder, EncodeValue, Encoder, FixedTag, Header, Length, Sequence, Tag}; /// Syntax version of the `encrypted-data` content type. /// @@ -73,7 +70,7 @@ impl EncodeValue for Version { /// - [`version`](EncryptedDataContent::version) is the syntax version number. /// - [`encrypted_content_info`](EncryptedDataContent::encrypted_content_info) is the encrypted content /// information, as in [EncryptedContentInfo]. -#[derive(Copy, Clone, Debug, Eq, PartialEq)] +#[derive(Copy, Clone, Debug, Eq, PartialEq, Sequence)] pub struct EncryptedDataContent<'a> { /// the syntax version number. pub version: Version, @@ -81,23 +78,3 @@ pub struct EncryptedDataContent<'a> { /// the encrypted content information. pub encrypted_content_info: EncryptedContentInfo<'a>, } - -impl<'a> Decodable<'a> for EncryptedDataContent<'a> { - fn decode(decoder: &mut Decoder<'a>) -> der::Result> { - decoder.sequence(|decoder| { - Ok(EncryptedDataContent { - version: decoder.decode()?, - encrypted_content_info: decoder.decode()?, - }) - }) - } -} - -impl<'a> Sequence<'a> for EncryptedDataContent<'a> { - fn fields(&self, f: F) -> der::Result - where - F: FnOnce(&[&dyn Encodable]) -> der::Result, - { - f(&[&self.version, &self.encrypted_content_info]) - } -}