Struct der::asn1::Any

source ·
pub struct Any<'a> { /* private fields */ }
Expand description

ASN.1 ANY: represents any explicitly tagged ASN.1 value.

Technically ANY hasn’t been a recommended part of ASN.1 since the X.209 revision from 1988. It was deprecated and replaced by Information Object Classes in X.680 in 1994, and X.690 no longer refers to it whatsoever.

Nevertheless, this crate defines an Any type as it remains a familiar and useful concept which is still extensively used in things like PKI-related RFCs.

Implementations§

source§

impl<'a> Any<'a>

source

pub const NULL: Self = _

Any representation of the ASN.1 NULL type.

source

pub fn new(tag: Tag, bytes: &'a [u8]) -> Result<Self>

Create a new Any from the provided Tag and byte slice.

source

pub fn value(self) -> &'a [u8]

Get the raw value for this Any type as a byte slice.

source

pub fn decode_into<T>(self) -> Result<T>
where T: DecodeValue<'a> + FixedTag,

Attempt to decode this Any type into the inner value.

source

pub fn is_null(self) -> bool

Is this value an ASN.1 NULL value?

source

pub fn bit_string(self) -> Result<BitString<'a>>

Attempt to decode an ASN.1 BIT STRING.

source

pub fn context_specific<T>(self) -> Result<ContextSpecific<T>>
where T: Decodable<'a>,

Attempt to decode an ASN.1 CONTEXT-SPECIFIC field.

source

pub fn generalized_time(self) -> Result<GeneralizedTime>

Attempt to decode an ASN.1 GeneralizedTime.

source

pub fn ia5_string(self) -> Result<Ia5String<'a>>

Attempt to decode an ASN.1 IA5String.

source

pub fn octet_string(self) -> Result<OctetString<'a>>

Attempt to decode an ASN.1 OCTET STRING.

source

pub fn oid(self) -> Result<ObjectIdentifier>

Attempt to decode an ASN.1 OBJECT IDENTIFIER.

source

pub fn optional<T>(self) -> Result<Option<T>>
where T: Choice<'a> + TryFrom<Self, Error = Error>,

Attempt to decode an ASN.1 OPTIONAL value.

source

pub fn printable_string(self) -> Result<PrintableString<'a>>

Attempt to decode an ASN.1 PrintableString.

source

pub fn sequence<F, T>(self, f: F) -> Result<T>
where F: FnOnce(&mut Decoder<'a>) -> Result<T>,

Attempt to decode this value an ASN.1 SEQUENCE, creating a new nested Decoder and calling the provided argument with it.

source

pub fn utc_time(self) -> Result<UtcTime>

Attempt to decode an ASN.1 UTCTime.

source

pub fn utf8_string(self) -> Result<Utf8String<'a>>

Attempt to decode an ASN.1 UTF8String.

Trait Implementations§

source§

impl<'a> Choice<'a> for Any<'a>

source§

fn can_decode(_: Tag) -> bool

Is the provided Tag decodable as a variant of this CHOICE?
source§

impl<'a> Clone for Any<'a>

source§

fn clone(&self) -> Any<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a> Debug for Any<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a> Decodable<'a> for Any<'a>

source§

fn decode(decoder: &mut Decoder<'a>) -> Result<Any<'a>>

Attempt to decode this message using the provided decoder.
source§

fn from_der(bytes: &'a [u8]) -> Result<Self>

Parse Self from the provided DER-encoded byte slice.
source§

impl EncodeValue for Any<'_>

source§

fn value_len(&self) -> Result<Length>

Compute the length of this value (sans Tag+Length header) when encoded as ASN.1 DER.
source§

fn encode_value(&self, encoder: &mut Encoder<'_>) -> Result<()>

Encode value (sans Tag+Length header) as ASN.1 DER using the provided Encoder.
source§

fn header(&self) -> Result<Header>
where Self: Tagged,

Get the Header used to encode this value.
source§

impl<'a> From<&'a ObjectIdentifier> for Any<'a>

source§

fn from(oid: &'a ObjectIdentifier) -> Any<'a>

Converts to this type from the input type.
source§

impl<'a> From<()> for Any<'a>

source§

fn from(_: ()) -> Any<'a>

Converts to this type from the input type.
source§

impl<'a> From<Ia5String<'a>> for Any<'a>

source§

fn from(printable_string: Ia5String<'a>) -> Any<'a>

Converts to this type from the input type.
source§

impl<'a> From<Null> for Any<'a>

source§

fn from(_: Null) -> Any<'a>

Converts to this type from the input type.
source§

impl<'a> From<OctetString<'a>> for Any<'a>

source§

fn from(octet_string: OctetString<'a>) -> Any<'a>

Converts to this type from the input type.
source§

impl<'a> From<PrintableString<'a>> for Any<'a>

source§

fn from(printable_string: PrintableString<'a>) -> Any<'a>

Converts to this type from the input type.
source§

impl<'a> From<Utf8String<'a>> for Any<'a>

source§

fn from(printable_string: Utf8String<'a>) -> Any<'a>

Converts to this type from the input type.
source§

impl From<bool> for Any<'static>

source§

fn from(value: bool) -> Any<'static>

Converts to this type from the input type.
source§

impl<'a> Ord for Any<'a>

source§

fn cmp(&self, other: &Any<'a>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl<'a> PartialEq for Any<'a>

source§

fn eq(&self, other: &Any<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> PartialOrd for Any<'a>

source§

fn partial_cmp(&self, other: &Any<'a>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Tagged for Any<'_>

source§

fn tag(&self) -> Tag

Get the ASN.1 tag that this type is encoded with.
source§

impl<'a> TryFrom<&'a [u8]> for Any<'a>

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(bytes: &'a [u8]) -> Result<Any<'a>>

Performs the conversion.
source§

impl TryFrom<Any<'_>> for ()

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(any: Any<'_>) -> Result<()>

Performs the conversion.
source§

impl TryFrom<Any<'_>> for GeneralizedTime

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(any: Any<'_>) -> Result<GeneralizedTime>

Performs the conversion.
source§

impl TryFrom<Any<'_>> for Null

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(any: Any<'_>) -> Result<Null>

Performs the conversion.
source§

impl TryFrom<Any<'_>> for ObjectIdentifier

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(any: Any<'_>) -> Result<ObjectIdentifier>

Performs the conversion.
source§

impl TryFrom<Any<'_>> for UtcTime

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(any: Any<'_>) -> Result<UtcTime>

Performs the conversion.
source§

impl TryFrom<Any<'_>> for bool

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(any: Any<'_>) -> Result<bool>

Performs the conversion.
source§

impl TryFrom<Any<'_>> for i128

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(any: Any<'_>) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<Any<'_>> for i16

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(any: Any<'_>) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<Any<'_>> for i32

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(any: Any<'_>) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<Any<'_>> for i64

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(any: Any<'_>) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<Any<'_>> for i8

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(any: Any<'_>) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<Any<'_>> for u128

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(any: Any<'_>) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<Any<'_>> for u16

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(any: Any<'_>) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<Any<'_>> for u32

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(any: Any<'_>) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<Any<'_>> for u64

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(any: Any<'_>) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<Any<'_>> for u8

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(any: Any<'_>) -> Result<Self>

Performs the conversion.
source§

impl<'a> TryFrom<Any<'a>> for &'a str

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(any: Any<'a>) -> Result<&'a str>

Performs the conversion.
source§

impl<'a> TryFrom<Any<'a>> for BitString<'a>

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(any: Any<'a>) -> Result<BitString<'a>>

Performs the conversion.
source§

impl<'a, T> TryFrom<Any<'a>> for ContextSpecific<T>
where T: Decodable<'a>,

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(any: Any<'a>) -> Result<ContextSpecific<T>>

Performs the conversion.
source§

impl<'a> TryFrom<Any<'a>> for Ia5String<'a>

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(any: Any<'a>) -> Result<Ia5String<'a>>

Performs the conversion.
source§

impl<'a> TryFrom<Any<'a>> for OctetString<'a>

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(any: Any<'a>) -> Result<OctetString<'a>>

Performs the conversion.
source§

impl<'a> TryFrom<Any<'a>> for PrintableString<'a>

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(any: Any<'a>) -> Result<PrintableString<'a>>

Performs the conversion.
source§

impl<'a> TryFrom<Any<'a>> for UIntBytes<'a>

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(any: Any<'a>) -> Result<UIntBytes<'a>>

Performs the conversion.
source§

impl<'a> TryFrom<Any<'a>> for Utf8String<'a>

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(any: Any<'a>) -> Result<Utf8String<'a>>

Performs the conversion.
source§

impl ValueOrd for Any<'_>

source§

fn value_cmp(&self, other: &Self) -> Result<Ordering>

Return an Ordering between value portion of TLV-encoded self and other when serialized as ASN.1 DER.
source§

impl<'a> Copy for Any<'a>

source§

impl<'a> Eq for Any<'a>

source§

impl<'a> StructuralPartialEq for Any<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Any<'a>

§

impl<'a> RefUnwindSafe for Any<'a>

§

impl<'a> Send for Any<'a>

§

impl<'a> Sync for Any<'a>

§

impl<'a> Unpin for Any<'a>

§

impl<'a> UnwindSafe for Any<'a>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> CloneToUninit for T
where T: Copy,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> DerOrd for T

source§

fn der_cmp(&self, other: &T) -> Result<Ordering, Error>

Return an Ordering between self and other when serialized as ASN.1 DER.
source§

impl<T> Encodable for T
where T: EncodeValue + Tagged,

source§

fn encoded_len(&self) -> Result<Length, Error>

Compute the length of this value in bytes when encoded as ASN.1 DER.

source§

fn encode(&self, encoder: &mut Encoder<'_>) -> Result<(), Error>

Encode this value as ASN.1 DER using the provided Encoder.

source§

fn encode_to_slice<'a>(&self, buf: &'a mut [u8]) -> Result<&'a [u8]>

Encode this value to the provided byte slice, returning a sub-slice containing the encoded message.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.