From 6895ed0c683b7d5cb4f686dc56f7f91ec9212b82 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Fri, 25 Mar 2022 08:45:08 -0600 Subject: [PATCH] der: rename `decodable`/`encodable` modules => `decode`/`encode` Followup to #523, which renamed the traits but not the modules they're defined in. Additionally factors the `DecodeValue`/`EncodeValue` traits into these modules (originally defined in the `value` module, which is removed in this PR). --- der/src/{decodable.rs => decode.rs} | 9 +++++++- der/src/{encodable.rs => encode.rs} | 22 ++++++++++++++++++- der/src/lib.rs | 10 ++++----- der/src/value.rs | 33 ----------------------------- 4 files changed, 33 insertions(+), 41 deletions(-) rename der/src/{decodable.rs => decode.rs} (75%) rename der/src/{encodable.rs => encode.rs} (76%) delete mode 100644 der/src/value.rs diff --git a/der/src/decodable.rs b/der/src/decode.rs similarity index 75% rename from der/src/decodable.rs rename to der/src/decode.rs index 12e8f392a..61ee2fe5c 100644 --- a/der/src/decodable.rs +++ b/der/src/decode.rs @@ -1,6 +1,6 @@ //! Trait definition for [`Decode`]. -use crate::{DecodeValue, Decoder, FixedTag, Header, Result}; +use crate::{Decoder, FixedTag, Header, Result}; /// Decoding trait. /// @@ -34,3 +34,10 @@ where T::decode_value(decoder, header) } } + +/// Decode the value part of a Tag-Length-Value encoded field, sans the [`Tag`] +/// and [`Length`]. +pub trait DecodeValue<'a>: Sized { + /// Attempt to decode this message using the provided [`Decoder`]. + fn decode_value(decoder: &mut Decoder<'a>, header: Header) -> Result; +} diff --git a/der/src/encodable.rs b/der/src/encode.rs similarity index 76% rename from der/src/encodable.rs rename to der/src/encode.rs index fa0dffeab..e16649544 100644 --- a/der/src/encodable.rs +++ b/der/src/encode.rs @@ -1,6 +1,6 @@ //! Trait definition for [`Encode`]. -use crate::{EncodeValue, Encoder, Length, Result, Tagged}; +use crate::{Encoder, Header, Length, Result, Tagged}; #[cfg(feature = "alloc")] use {crate::ErrorKind, alloc::vec::Vec, core::iter}; @@ -70,3 +70,23 @@ where self.encode_value(encoder) } } + +/// Encode the value part of a Tag-Length-Value encoded field, sans the [`Tag`] +/// and [`Length`]. +pub trait EncodeValue { + /// Get the [`Header`] used to encode this value. + fn header(&self) -> Result
+ where + Self: Tagged, + { + Header::new(self.tag(), self.value_len()?) + } + + /// Compute the length of this value (sans [`Tag`]+[`Length`] header) when + /// encoded as ASN.1 DER. + fn value_len(&self) -> Result; + + /// Encode value (sans [`Tag`]+[`Length`] header) as ASN.1 DER using the + /// provided [`Encoder`]. + fn encode_value(&self, encoder: &mut Encoder<'_>) -> Result<()>; +} diff --git a/der/src/lib.rs b/der/src/lib.rs index 9d542f471..212332ddd 100644 --- a/der/src/lib.rs +++ b/der/src/lib.rs @@ -336,9 +336,9 @@ pub mod asn1; pub(crate) mod arrayvec; mod byte_slice; mod datetime; -mod decodable; +mod decode; mod decoder; -mod encodable; +mod encode; mod encoder; mod error; mod header; @@ -346,7 +346,6 @@ mod length; mod ord; mod str_slice; mod tag; -mod value; #[cfg(feature = "alloc")] mod document; @@ -354,16 +353,15 @@ mod document; pub use crate::{ asn1::{Any, Choice, Sequence}, datetime::DateTime, - decodable::Decode, + decode::{Decode, DecodeValue}, decoder::Decoder, - encodable::Encode, + encode::{Encode, EncodeValue}, encoder::Encoder, error::{Error, ErrorKind, Result}, header::Header, length::Length, ord::{DerOrd, ValueOrd}, tag::{Class, FixedTag, Tag, TagMode, TagNumber, Tagged}, - value::{DecodeValue, EncodeValue}, }; #[cfg(feature = "alloc")] diff --git a/der/src/value.rs b/der/src/value.rs deleted file mode 100644 index 6986da4b7..000000000 --- a/der/src/value.rs +++ /dev/null @@ -1,33 +0,0 @@ -//! Value traits - -use crate::{Decoder, Encoder, Header, Length, Result, Tagged}; - -#[cfg(doc)] -use crate::Tag; - -/// Decode the value part of a Tag-Length-Value encoded field, sans the [`Tag`] -/// and [`Length`]. -pub trait DecodeValue<'a>: Sized { - /// Attempt to decode this message using the provided [`Decoder`]. - fn decode_value(decoder: &mut Decoder<'a>, header: Header) -> Result; -} - -/// Encode the value part of a Tag-Length-Value encoded field, sans the [`Tag`] -/// and [`Length`]. -pub trait EncodeValue { - /// Get the [`Header`] used to encode this value. - fn header(&self) -> Result
- where - Self: Tagged, - { - Header::new(self.tag(), self.value_len()?) - } - - /// Compute the length of this value (sans [`Tag`]+[`Length`] header) when - /// encoded as ASN.1 DER. - fn value_len(&self) -> Result; - - /// Encode value (sans [`Tag`]+[`Length`] header) as ASN.1 DER using the - /// provided [`Encoder`]. - fn encode_value(&self, encoder: &mut Encoder<'_>) -> Result<()>; -}