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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 DownExpand 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
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 DownExpand 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
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 DownExpand 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
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 DownExpand 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
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 DownExpand 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
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 DownExpand 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
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 DownExpand 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
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 DownExpand 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