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
4 changes: 2 additions & 2 deletions der/derive/src/choice.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Support for deriving the `Decodable` and `Encodable` traits on enums for
//! Support for deriving the `Decode` and `Encode` traits on enums for
//! the purposes of decoding/encoding ASN.1 `CHOICE` types as mapped to
//! enum variants.

Expand Down Expand Up @@ -94,7 +94,7 @@ impl DeriveChoice {
}
}

impl<#lt_params> ::der::Decodable<#lifetime> for #ident<#lt_params> {
impl<#lt_params> ::der::Decode<#lifetime> for #ident<#lt_params> {
fn decode(decoder: &mut ::der::Decoder<#lifetime>) -> ::der::Result<Self> {
match decoder.peek_tag()? {
#(#decode_body)*
Expand Down
2 changes: 1 addition & 1 deletion der/derive/src/enumerated.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Support for deriving the `Decodable` and `Encodable` traits on enums for
//! Support for deriving the `Decode` and `Encode` traits on enums for
//! the purposes of decoding/encoding ASN.1 `ENUMERATED` types as mapped to
//! enum variants.

Expand Down
8 changes: 4 additions & 4 deletions der/derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,11 @@ use syn::{parse_macro_input, DeriveInput};
/// Derive the [`Choice`][1] trait on an `enum`.
///
/// This custom derive macro can be used to automatically impl the
/// [`Decodable`][2] and [`Encodable`][3] traits along with the
/// [`Decode`][2] and [`Encode`][3] traits along with the
/// [`Choice`][1] supertrait for any enum representing an ASN.1 `CHOICE`.
///
/// The enum must consist entirely of 1-tuple variants wrapping inner
/// types which must also impl the [`Decodable`][2] and [`Encodable`][3]
/// types which must also impl the [`Decode`][2] and [`Encode`][3]
/// traits. It will will also generate [`From`] impls for each of the
/// inner types of the variants into the enum that wraps them.
///
Expand All @@ -173,8 +173,8 @@ use syn::{parse_macro_input, DeriveInput};
/// information about the `#[asn1]` attribute.
///
/// [1]: https://docs.rs/der/latest/der/trait.Choice.html
/// [2]: https://docs.rs/der/latest/der/trait.Decodable.html
/// [3]: https://docs.rs/der/latest/der/trait.Encodable.html
/// [2]: https://docs.rs/der/latest/der/trait.Decode.html
/// [3]: https://docs.rs/der/latest/der/trait.Encode.html
/// [4]: https://docs.rs/der_derive/
#[proc_macro_derive(Choice, attributes(asn1))]
#[proc_macro_error]
Expand Down
2 changes: 1 addition & 1 deletion der/derive/src/sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl DeriveSequence {
impl<#lt_params> ::der::Sequence<#lifetime> for #ident<#lt_params> {
fn fields<F, T>(&self, f: F) -> ::der::Result<T>
where
F: FnOnce(&[&dyn der::Encodable]) -> ::der::Result<T>,
F: FnOnce(&[&dyn der::Encode]) -> ::der::Result<T>,
{
f(&[
#(#encode_body),*
Expand Down
8 changes: 4 additions & 4 deletions der/src/asn1/any.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! ASN.1 `ANY` type.

use crate::{
asn1::*, ByteSlice, Choice, Decodable, DecodeValue, Decoder, DerOrd, EncodeValue, Encoder,
Error, ErrorKind, FixedTag, Header, Length, Result, Tag, Tagged, ValueOrd,
asn1::*, ByteSlice, Choice, Decode, DecodeValue, Decoder, DerOrd, EncodeValue, Encoder, Error,
ErrorKind, FixedTag, Header, Length, Result, Tag, Tagged, ValueOrd,
};
use core::cmp::Ordering;

Expand Down Expand Up @@ -79,7 +79,7 @@ impl<'a> Any<'a> {
/// Attempt to decode an ASN.1 `CONTEXT-SPECIFIC` field.
pub fn context_specific<T>(self) -> Result<ContextSpecific<T>>
where
T: Decodable<'a>,
T: Decode<'a>,
{
self.try_into()
}
Expand Down Expand Up @@ -152,7 +152,7 @@ impl<'a> Choice<'a> for Any<'a> {
}
}

impl<'a> Decodable<'a> for Any<'a> {
impl<'a> Decode<'a> for Any<'a> {
fn decode(decoder: &mut Decoder<'a>) -> Result<Any<'a>> {
let header = Header::decode(decoder)?;
Ok(Self {
Expand Down
2 changes: 1 addition & 1 deletion der/src/asn1/boolean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl TryFrom<Any<'_>> for bool {

#[cfg(test)]
mod tests {
use crate::{Decodable, Encodable};
use crate::{Decode, Encode};

#[test]
fn decode() {
Expand Down
8 changes: 4 additions & 4 deletions der/src/asn1/choice.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
//! ASN.1 `CHOICE` support.

use crate::{Decodable, FixedTag, Tag, Tagged};
use crate::{Decode, FixedTag, Tag, Tagged};

/// ASN.1 `CHOICE` denotes a union of one or more possible alternatives.
///
/// The types MUST have distinct tags.
///
/// This crate models choice as a trait, with a blanket impl for all types
/// which impl `Decodable + FixedTag` (i.e. they are modeled as a `CHOICE`
/// which impl `Decode + FixedTag` (i.e. they are modeled as a `CHOICE`
/// with only one possible variant)
pub trait Choice<'a>: Decodable<'a> + Tagged {
pub trait Choice<'a>: Decode<'a> + Tagged {
/// Is the provided [`Tag`] decodable as a variant of this `CHOICE`?
fn can_decode(tag: Tag) -> bool;
}
Expand All @@ -18,7 +18,7 @@ pub trait Choice<'a>: Decodable<'a> + Tagged {
/// with a single alternative.
impl<'a, T> Choice<'a> for T
where
T: Decodable<'a> + FixedTag,
T: Decode<'a> + FixedTag,
{
fn can_decode(tag: Tag) -> bool {
T::TAG == tag
Expand Down
16 changes: 8 additions & 8 deletions der/src/asn1/context_specific.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Context-specific field.

use crate::{
asn1::Any, Choice, Decodable, DecodeValue, Decoder, DerOrd, Encodable, EncodeValue, Encoder,
Error, Header, Length, Result, Tag, TagMode, TagNumber, Tagged, ValueOrd,
asn1::Any, Choice, Decode, DecodeValue, Decoder, DerOrd, Encode, EncodeValue, Encoder, Error,
Header, Length, Result, Tag, TagMode, TagNumber, Tagged, ValueOrd,
};
use core::cmp::Ordering;

Expand Down Expand Up @@ -44,7 +44,7 @@ impl<T> ContextSpecific<T> {
tag_number: TagNumber,
) -> Result<Option<Self>>
where
T: Decodable<'a>,
T: Decode<'a>,
{
Self::decode_with(decoder, tag_number, |decoder| {
let any = Any::decode(decoder)?;
Expand Down Expand Up @@ -123,16 +123,16 @@ impl<T> ContextSpecific<T> {

impl<'a, T> Choice<'a> for ContextSpecific<T>
where
T: Decodable<'a> + Tagged,
T: Decode<'a> + Tagged,
{
fn can_decode(tag: Tag) -> bool {
tag.is_context_specific()
}
}

impl<'a, T> Decodable<'a> for ContextSpecific<T>
impl<'a, T> Decode<'a> for ContextSpecific<T>
where
T: Decodable<'a>,
T: Decode<'a>,
{
fn decode(decoder: &mut Decoder<'a>) -> Result<Self> {
Any::decode(decoder)?.try_into()
Expand Down Expand Up @@ -172,7 +172,7 @@ where

impl<'a, T> TryFrom<Any<'a>> for ContextSpecific<T>
where
T: Decodable<'a>,
T: Decode<'a>,
{
type Error = Error;

Expand Down Expand Up @@ -259,7 +259,7 @@ where
#[cfg(test)]
mod tests {
use super::ContextSpecific;
use crate::{asn1::BitString, Decodable, Decoder, Encodable, TagMode, TagNumber};
use crate::{asn1::BitString, Decode, Decoder, Encode, TagMode, TagNumber};
use hex_literal::hex;

// Public key data from `pkcs8` crate's `ed25519-pkcs8-v2.der`
Expand Down
2 changes: 1 addition & 1 deletion der/src/asn1/generalized_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ impl TryFrom<GeneralizedTime> for PrimitiveDateTime {
#[cfg(test)]
mod tests {
use super::GeneralizedTime;
use crate::{Decodable, Encodable, Encoder};
use crate::{Decode, Encode, Encoder};
use hex_literal::hex;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion der/src/asn1/ia5_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl<'a> fmt::Debug for Ia5String<'a> {
#[cfg(test)]
mod tests {
use super::Ia5String;
use crate::Decodable;
use crate::Decode;
use hex_literal::hex;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion der/src/asn1/integer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ where

#[cfg(test)]
pub(crate) mod tests {
use crate::{Decodable, Encodable};
use crate::{Decode, Encode};

// Vectors from Section 5.7 of:
// https://luca.ntop.org/Teaching/Appunti/asn1.html
Expand Down
2 changes: 1 addition & 1 deletion der/src/asn1/integer/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ mod tests {
use super::UIntBytes;
use crate::{
asn1::{integer::tests::*, Any},
Decodable, Encodable, Encoder, ErrorKind, Tag,
Decode, Encode, Encoder, ErrorKind, Tag,
};

#[test]
Expand Down
8 changes: 4 additions & 4 deletions der/src/asn1/null.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! ASN.1 `NULL` support.

use crate::{
asn1::Any, ord::OrdIsValueOrd, ByteSlice, DecodeValue, Decoder, Encodable, EncodeValue,
Encoder, Error, ErrorKind, FixedTag, Header, Length, Result, Tag,
asn1::Any, ord::OrdIsValueOrd, ByteSlice, DecodeValue, Decoder, Encode, EncodeValue, Encoder,
Error, ErrorKind, FixedTag, Header, Length, Result, Tag,
};

/// ASN.1 `NULL` type.
Expand Down Expand Up @@ -70,7 +70,7 @@ impl DecodeValue<'_> for () {
}
}

impl Encodable for () {
impl Encode for () {
fn encoded_len(&self) -> Result<Length> {
Null.encoded_len()
}
Expand All @@ -87,7 +87,7 @@ impl FixedTag for () {
#[cfg(test)]
mod tests {
use super::Null;
use crate::{Decodable, Encodable};
use crate::{Decode, Encode};

#[test]
fn decode() {
Expand Down
2 changes: 1 addition & 1 deletion der/src/asn1/oid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl TryFrom<Any<'_>> for ObjectIdentifier {
#[cfg(test)]
mod tests {
use super::ObjectIdentifier;
use crate::{Decodable, Encodable, Length};
use crate::{Decode, Encode, Length};

const EXAMPLE_OID: ObjectIdentifier = ObjectIdentifier::new_unwrap("1.2.840.113549");
const EXAMPLE_OID_BYTES: &[u8; 8] = &[0x06, 0x06, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d];
Expand Down
14 changes: 7 additions & 7 deletions der/src/asn1/optional.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//! ASN.1 `OPTIONAL` as mapped to Rust's `Option` type

use crate::{Choice, Decodable, Decoder, DerOrd, Encodable, Encoder, Length, Result, Tag};
use crate::{Choice, Decode, Decoder, DerOrd, Encode, Encoder, Length, Result, Tag};
use core::cmp::Ordering;

impl<'a, T> Decodable<'a> for Option<T>
impl<'a, T> Decode<'a> for Option<T>
where
T: Choice<'a>, // NOTE: all `Decodable + Tagged` types receive a blanket `Choice` impl
T: Choice<'a>, // NOTE: all `Decode + Tagged` types receive a blanket `Choice` impl
{
fn decode(decoder: &mut Decoder<'a>) -> Result<Option<T>> {
if let Some(byte) = decoder.peek_byte() {
Expand All @@ -18,9 +18,9 @@ where
}
}

impl<T> Encodable for Option<T>
impl<T> Encode for Option<T>
where
T: Encodable,
T: Encode,
{
fn encoded_len(&self) -> Result<Length> {
if let Some(encodable) = self {
Expand Down Expand Up @@ -59,9 +59,9 @@ where
/// A reference to an ASN.1 `OPTIONAL` type, used for encoding only.
pub struct OptionalRef<'a, T>(pub Option<&'a T>);

impl<'a, T> Encodable for OptionalRef<'a, T>
impl<'a, T> Encode for OptionalRef<'a, T>
where
T: Encodable,
T: Encode,
{
fn encoded_len(&self) -> Result<Length> {
if let Some(encodable) = self.0 {
Expand Down
2 changes: 1 addition & 1 deletion der/src/asn1/printable_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ impl<'a> fmt::Debug for PrintableString<'a> {
#[cfg(test)]
mod tests {
use super::PrintableString;
use crate::Decodable;
use crate::Decode;

#[test]
fn parse_bytes() {
Expand Down
14 changes: 7 additions & 7 deletions der/src/asn1/sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@
//! `SEQUENCE`s to Rust structs.

use crate::{
ByteSlice, Decodable, DecodeValue, Decoder, Encodable, EncodeValue, Encoder, FixedTag, Header,
ByteSlice, Decode, DecodeValue, Decoder, Encode, EncodeValue, Encoder, FixedTag, Header,
Length, Result, Tag,
};

/// ASN.1 `SEQUENCE` trait.
///
/// Types which impl this trait receive blanket impls for the [`Decodable`],
/// [`Encodable`], and [`FixedTag`] traits.
pub trait Sequence<'a>: Decodable<'a> {
/// Call the provided function with a slice of [`Encodable`] trait objects
/// Types which impl this trait receive blanket impls for the [`Decode`],
/// [`Encode`], and [`FixedTag`] traits.
pub trait Sequence<'a>: Decode<'a> {
/// Call the provided function with a slice of [`Encode`] trait objects
/// representing the fields of this `SEQUENCE`.
///
/// This method uses a callback because structs with fields which aren't
/// directly [`Encodable`] may need to construct temporary values from
/// directly [`Encode`] may need to construct temporary values from
/// their fields prior to encoding.
fn fields<F, T>(&self, f: F) -> Result<T>
where
F: FnOnce(&[&dyn Encodable]) -> Result<T>;
F: FnOnce(&[&dyn Encode]) -> Result<T>;
}

impl<'a, M> EncodeValue for M
Expand Down
16 changes: 8 additions & 8 deletions der/src/asn1/sequence_of.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! ASN.1 `SEQUENCE OF` support.

use crate::{
arrayvec, ord::iter_cmp, ArrayVec, Decodable, DecodeValue, Decoder, DerOrd, Encodable,
EncodeValue, Encoder, ErrorKind, FixedTag, Header, Length, Result, Tag, ValueOrd,
arrayvec, ord::iter_cmp, ArrayVec, Decode, DecodeValue, Decoder, DerOrd, Encode, EncodeValue,
Encoder, ErrorKind, FixedTag, Header, Length, Result, Tag, ValueOrd,
};
use core::cmp::Ordering;

Expand Down Expand Up @@ -64,7 +64,7 @@ impl<T, const N: usize> Default for SequenceOf<T, N> {

impl<'a, T, const N: usize> DecodeValue<'a> for SequenceOf<T, N>
where
T: Decodable<'a>,
T: Decode<'a>,
{
fn decode_value(decoder: &mut Decoder<'a>, header: Header) -> Result<Self> {
let end_pos = (decoder.position() + header.length)?;
Expand All @@ -84,7 +84,7 @@ where

impl<T, const N: usize> EncodeValue for SequenceOf<T, N>
where
T: Encodable,
T: Encode,
{
fn value_len(&self) -> Result<Length> {
self.iter()
Expand Down Expand Up @@ -132,7 +132,7 @@ impl<'a, T> ExactSizeIterator for SequenceOfIter<'a, T> {}

impl<'a, T, const N: usize> DecodeValue<'a> for [T; N]
where
T: Decodable<'a>,
T: Decode<'a>,
{
fn decode_value(decoder: &mut Decoder<'a>, header: Header) -> Result<Self> {
SequenceOf::decode_value(decoder, header)?
Expand All @@ -143,7 +143,7 @@ where

impl<T, const N: usize> EncodeValue for [T; N]
where
T: Encodable,
T: Encode,
{
fn value_len(&self) -> Result<Length> {
self.iter()
Expand Down Expand Up @@ -176,7 +176,7 @@ where
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
impl<'a, T> DecodeValue<'a> for Vec<T>
where
T: Decodable<'a>,
T: Decode<'a>,
{
fn decode_value(decoder: &mut Decoder<'a>, header: Header) -> Result<Self> {
let end_pos = (decoder.position() + header.length)?;
Expand All @@ -198,7 +198,7 @@ where
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
impl<T> EncodeValue for Vec<T>
where
T: Encodable,
T: Encode,
{
fn value_len(&self) -> Result<Length> {
self.iter()
Expand Down
Loading