Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 2 additions & 23 deletions pkcs1/src/private_key/other_prime_info.rs
Original file line number Diff line number Diff line change
@@ -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].
///
Expand All @@ -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.
Expand All @@ -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<Self> {
decoder.sequence(|decoder| {
Ok(Self {
prime: decoder.decode()?,
exponent: decoder.decode()?,
coefficient: decoder.decode()?,
})
})
}
}

impl<'a> Sequence<'a> for OtherPrimeInfo<'a> {
fn fields<F, T>(&self, f: F) -> der::Result<T>
where
F: FnOnce(&[&dyn Encodable]) -> der::Result<T>,
{
f(&[&self.prime, &self.exponent, &self.coefficient])
}
}
24 changes: 2 additions & 22 deletions pkcs1/src/public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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>,
Expand All @@ -50,26 +50,6 @@ impl<'a> RsaPublicKey<'a> {
}
}

impl<'a> Decodable<'a> for RsaPublicKey<'a> {
fn decode(decoder: &mut Decoder<'a>) -> der::Result<Self> {
decoder.sequence(|decoder| {
Ok(Self {
modulus: decoder.decode()?,
public_exponent: decoder.decode()?,
})
})
}
}

impl<'a> Sequence<'a> for RsaPublicKey<'a> {
fn fields<F, T>(&self, f: F) -> der::Result<T>
where
F: FnOnce(&[&dyn Encodable]) -> der::Result<T>,
{
f(&[&self.modulus, &self.public_exponent])
}
}

impl<'a> TryFrom<&'a [u8]> for RsaPublicKey<'a> {
type Error = Error;

Expand Down
17 changes: 1 addition & 16 deletions pkcs5/src/pbes2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down Expand Up @@ -197,21 +197,6 @@ impl<'a> Parameters<'a> {
}
}

impl<'a> Decodable<'a> for Parameters<'a> {
fn decode(decoder: &mut Decoder<'a>) -> der::Result<Self> {
decoder.any()?.try_into()
}
}

impl<'a> Sequence<'a> for Parameters<'a> {
fn fields<F, T>(&self, f: F) -> der::Result<T>
where
F: FnOnce(&[&dyn Encodable]) -> der::Result<T>,
{
f(&[&self.kdf, &self.encryption])
}
}

impl<'a> TryFrom<Any<'a>> for Parameters<'a> {
type Error = der::Error;

Expand Down
27 changes: 2 additions & 25 deletions pkcs7/src/encrypted_data_content.rs
Original file line number Diff line number Diff line change
@@ -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.
///
Expand Down Expand Up @@ -73,31 +70,11 @@ 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,

/// 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<EncryptedDataContent<'a>> {
decoder.sequence(|decoder| {
Ok(EncryptedDataContent {
version: decoder.decode()?,
encrypted_content_info: decoder.decode()?,
})
})
}
}

impl<'a> Sequence<'a> for EncryptedDataContent<'a> {
fn fields<F, T>(&self, f: F) -> der::Result<T>
where
F: FnOnce(&[&dyn Encodable]) -> der::Result<T>,
{
f(&[&self.version, &self.encrypted_content_info])
}
}