Skip to content
Merged
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
9 changes: 8 additions & 1 deletion der/src/decodable.rs → der/src/decode.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Trait definition for [`Decode`].

use crate::{DecodeValue, Decoder, FixedTag, Header, Result};
use crate::{Decoder, FixedTag, Header, Result};

/// Decoding trait.
///
Expand Down Expand Up @@ -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<Self>;
}
22 changes: 21 additions & 1 deletion der/src/encodable.rs → der/src/encode.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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<Header>
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<Length>;

/// Encode value (sans [`Tag`]+[`Length`] header) as ASN.1 DER using the
/// provided [`Encoder`].
fn encode_value(&self, encoder: &mut Encoder<'_>) -> Result<()>;
}
10 changes: 4 additions & 6 deletions der/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,34 +336,32 @@ 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;
mod length;
mod ord;
mod str_slice;
mod tag;
mod value;

#[cfg(feature = "alloc")]
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")]
Expand Down
33 changes: 0 additions & 33 deletions der/src/value.rs

This file was deleted.