diff options
Diffstat (limited to 'src/encrypted_private_key_info.rs')
-rw-r--r-- | src/encrypted_private_key_info.rs | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/src/encrypted_private_key_info.rs b/src/encrypted_private_key_info.rs index 460e3f6..d55949c 100644 --- a/src/encrypted_private_key_info.rs +++ b/src/encrypted_private_key_info.rs @@ -2,7 +2,10 @@ use crate::{Error, Result}; use core::fmt; -use der::{asn1::OctetStringRef, Decode, DecodeValue, Encode, Header, Reader, Sequence}; +use der::{ + asn1::OctetStringRef, Decode, DecodeValue, Encode, EncodeValue, Header, Length, Reader, + Sequence, Writer, +}; use pkcs5::EncryptionScheme; #[cfg(feature = "alloc")] @@ -36,7 +39,6 @@ use der::pem::PemLabel; /// ``` /// /// [RFC 5208 Section 6]: https://tools.ietf.org/html/rfc5208#section-6 -#[cfg_attr(docsrs, doc(cfg(feature = "pkcs5")))] #[derive(Clone, Eq, PartialEq)] pub struct EncryptedPrivateKeyInfo<'a> { /// Algorithm identifier describing a password-based symmetric encryption @@ -51,7 +53,6 @@ impl<'a> EncryptedPrivateKeyInfo<'a> { /// Attempt to decrypt this encrypted private key using the provided /// password to derive an encryption key. #[cfg(feature = "encryption")] - #[cfg_attr(docsrs, doc(cfg(feature = "encryption")))] pub fn decrypt(&self, password: impl AsRef<[u8]>) -> Result<SecretDocument> { Ok(self .encryption_algorithm @@ -62,7 +63,6 @@ impl<'a> EncryptedPrivateKeyInfo<'a> { /// Encrypt the given ASN.1 DER document using a symmetric encryption key /// derived from the provided password. #[cfg(feature = "encryption")] - #[cfg_attr(docsrs, doc(cfg(feature = "encryption")))] pub(crate) fn encrypt( mut rng: impl CryptoRng + RngCore, password: impl AsRef<[u8]>, @@ -81,7 +81,6 @@ impl<'a> EncryptedPrivateKeyInfo<'a> { /// Encrypt this private key using a symmetric encryption key derived /// from the provided password and [`pbes2::Parameters`]. #[cfg(feature = "encryption")] - #[cfg_attr(docsrs, doc(cfg(feature = "encryption")))] pub(crate) fn encrypt_with( pbes2_params: pbes2::Parameters<'a>, password: impl AsRef<[u8]>, @@ -111,18 +110,21 @@ impl<'a> DecodeValue<'a> for EncryptedPrivateKeyInfo<'a> { } } -impl<'a> Sequence<'a> for EncryptedPrivateKeyInfo<'a> { - fn fields<F, T>(&self, f: F) -> der::Result<T> - where - F: FnOnce(&[&dyn Encode]) -> der::Result<T>, - { - f(&[ - &self.encryption_algorithm, - &OctetStringRef::new(self.encrypted_data)?, - ]) +impl EncodeValue for EncryptedPrivateKeyInfo<'_> { + fn value_len(&self) -> der::Result<Length> { + self.encryption_algorithm.encoded_len()? + + OctetStringRef::new(self.encrypted_data)?.encoded_len()? + } + + fn encode_value(&self, writer: &mut impl Writer) -> der::Result<()> { + self.encryption_algorithm.encode(writer)?; + OctetStringRef::new(self.encrypted_data)?.encode(writer)?; + Ok(()) } } +impl<'a> Sequence<'a> for EncryptedPrivateKeyInfo<'a> {} + impl<'a> TryFrom<&'a [u8]> for EncryptedPrivateKeyInfo<'a> { type Error = Error; @@ -140,7 +142,6 @@ impl<'a> fmt::Debug for EncryptedPrivateKeyInfo<'a> { } #[cfg(feature = "alloc")] -#[cfg_attr(docsrs, doc(cfg(all(feature = "alloc", feature = "pkcs5"))))] impl TryFrom<EncryptedPrivateKeyInfo<'_>> for SecretDocument { type Error = Error; @@ -150,7 +151,6 @@ impl TryFrom<EncryptedPrivateKeyInfo<'_>> for SecretDocument { } #[cfg(feature = "alloc")] -#[cfg_attr(docsrs, doc(cfg(all(feature = "alloc", feature = "pkcs5"))))] impl TryFrom<&EncryptedPrivateKeyInfo<'_>> for SecretDocument { type Error = Error; @@ -160,7 +160,6 @@ impl TryFrom<&EncryptedPrivateKeyInfo<'_>> for SecretDocument { } #[cfg(feature = "pem")] -#[cfg_attr(docsrs, doc(cfg(feature = "pem")))] impl PemLabel for EncryptedPrivateKeyInfo<'_> { const PEM_LABEL: &'static str = "ENCRYPTED PRIVATE KEY"; } |