Struct asn1_rs::TaggedValue

source ·
pub struct TaggedValue<T, E, TagKind, const CLASS: u8, const TAG: u32> { /* private fields */ }
Expand description

Helper object for creating FromBer/FromDer types for TAGGED OPTIONAL types

When parsing ContextSpecific (the most common class), see TaggedExplicit and TaggedImplicit alias types.

§Notes

CLASS must be between 0 and 4. See Class for possible values for the CLASS parameter. Constants from this class can be used, but they must be wrapped in braces due to Rust syntax for generics (see example below).

§Examples

To parse a [APPLICATION 0] EXPLICIT INTEGER object:

use asn1_rs::{Class, Error, Explicit, FromBer, Integer, TaggedValue};

let bytes = &[0x60, 0x03, 0x2, 0x1, 0x2];

// If tagged object is present (and has expected tag), parsing succeeds:
let (_, tagged) =
    TaggedValue::<Integer, Error, Explicit, {Class::APPLICATION}, 0>::from_ber(bytes)
        .unwrap();
assert_eq!(tagged, TaggedValue::explicit(Integer::from(2)));

Implementations§

source§

impl<T, E, TagKind, const CLASS: u8, const TAG: u32> TaggedValue<T, E, TagKind, CLASS, TAG>

source

pub fn into_inner(self) -> T

Consumes the TaggedParser, returning the wrapped value.

source

pub const fn tag(&self) -> Tag

Return the (outer) tag of this object

source

pub const fn class(&self) -> u8

Return the (outer) class of this object

source§

impl<T, E, const CLASS: u8, const TAG: u32> TaggedValue<T, E, Explicit, CLASS, TAG>

source

pub const fn explicit(inner: T) -> Self

Constructs a new EXPLICIT TaggedParser with the provided value

source§

impl<T, E, const CLASS: u8, const TAG: u32> TaggedValue<T, E, Implicit, CLASS, TAG>

source

pub const fn implicit(inner: T) -> Self

Constructs a new IMPLICIT TaggedParser with the provided value

Trait Implementations§

source§

impl<T, E, TagKind, const CLASS: u8, const TAG: u32> AsRef<T> for TaggedValue<T, E, TagKind, CLASS, TAG>

source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<T, E, const CLASS: u8, const TAG: u32> CheckDerConstraints for TaggedValue<T, E, Explicit, CLASS, TAG>

source§

impl<T, E, const CLASS: u8, const TAG: u32> CheckDerConstraints for TaggedValue<T, E, Implicit, CLASS, TAG>

source§

impl<T: Debug, E: Debug, TagKind: Debug, const CLASS: u8, const TAG: u32> Debug for TaggedValue<T, E, TagKind, CLASS, TAG>

source§

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

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

impl<'a, T, E, const CLASS: u8, const TAG: u32> FromDer<'a, E> for TaggedValue<T, E, Explicit, CLASS, TAG>
where T: FromDer<'a, E>, E: From<Error>,

source§

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

Attempt to parse input bytes into a DER object (enforcing constraints)
source§

impl<'a, T, E, const CLASS: u8, const TAG: u32> FromDer<'a, E> for TaggedValue<T, E, Implicit, CLASS, TAG>
where T: TryFrom<Any<'a>, Error = E> + Tagged, E: From<Error>,

source§

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

Attempt to parse input bytes into a DER object (enforcing constraints)
source§

impl<T: PartialEq, E: PartialEq, TagKind: PartialEq, const CLASS: u8, const TAG: u32> PartialEq for TaggedValue<T, E, TagKind, CLASS, TAG>

source§

fn eq(&self, other: &TaggedValue<T, E, TagKind, CLASS, TAG>) -> bool

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

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

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

impl<T, E, TagKind, const CLASS: u8, const TAG: u32> Tagged for TaggedValue<T, E, TagKind, CLASS, TAG>

source§

const TAG: Tag = _

source§

impl<T, E, const CLASS: u8, const TAG: u32> ToDer for TaggedValue<T, E, Explicit, CLASS, TAG>
where T: ToDer,

source§

fn to_der_len(&self) -> Result<usize>

Get the length of the object (including the header), when encoded
source§

fn write_der_header(&self, writer: &mut dyn Write) -> SerializeResult<usize>

Attempt to write the DER header to this writer.
source§

fn write_der_content(&self, writer: &mut dyn Write) -> SerializeResult<usize>

Attempt to write the DER content (all except header) to this writer.
source§

fn to_der_vec(&self) -> SerializeResult<Vec<u8>>

Write the DER encoded representation to a newly allocated Vec<u8>.
source§

fn to_der_vec_raw(&self) -> SerializeResult<Vec<u8>>

Similar to using to_vec, but uses provided values without changes. This can generate an invalid encoding for a DER object.
source§

fn write_der(&self, writer: &mut dyn Write) -> SerializeResult<usize>

Attempt to write the DER encoded representation (header and content) into this writer. Read more
source§

fn write_der_raw(&self, writer: &mut dyn Write) -> SerializeResult<usize>

Similar to using to_der, but uses provided values without changes. This can generate an invalid encoding for a DER object.
source§

impl<T, E, const CLASS: u8, const TAG: u32> ToDer for TaggedValue<T, E, Implicit, CLASS, TAG>
where T: ToDer,

source§

fn to_der_len(&self) -> Result<usize>

Get the length of the object (including the header), when encoded
source§

fn write_der(&self, writer: &mut dyn Write) -> SerializeResult<usize>

Attempt to write the DER encoded representation (header and content) into this writer. Read more
source§

fn write_der_header(&self, writer: &mut dyn Write) -> SerializeResult<usize>

Attempt to write the DER header to this writer.
source§

fn write_der_content(&self, writer: &mut dyn Write) -> SerializeResult<usize>

Attempt to write the DER content (all except header) to this writer.
source§

fn to_der_vec(&self) -> SerializeResult<Vec<u8>>

Write the DER encoded representation to a newly allocated Vec<u8>.
source§

fn to_der_vec_raw(&self) -> SerializeResult<Vec<u8>>

Similar to using to_vec, but uses provided values without changes. This can generate an invalid encoding for a DER object.
source§

fn write_der_raw(&self, writer: &mut dyn Write) -> SerializeResult<usize>

Similar to using to_der, but uses provided values without changes. This can generate an invalid encoding for a DER object.
source§

impl<'a, 'b, T, E, const CLASS: u8, const TAG: u32> TryFrom<&'b Any<'a>> for TaggedValue<T, E, Explicit, CLASS, TAG>
where T: FromBer<'a, E>, E: From<Error>,

§

type Error = E

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

fn try_from(any: &'b Any<'a>) -> Result<Self, E>

Performs the conversion.
source§

impl<'a, 'b, E, T, const CLASS: u8, const TAG: u32> TryFrom<&'b Any<'a>> for TaggedValue<T, E, Implicit, CLASS, TAG>
where T: TryFrom<Any<'a>, Error = E> + Tagged, E: From<Error>,

§

type Error = E

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

fn try_from(any: &'b Any<'a>) -> Result<Self, E>

Performs the conversion.
source§

impl<'a, T, E, const CLASS: u8, const TAG: u32> TryFrom<Any<'a>> for TaggedValue<T, E, Explicit, CLASS, TAG>
where T: FromBer<'a, E>, E: From<Error>,

§

type Error = E

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

fn try_from(any: Any<'a>) -> Result<Self, E>

Performs the conversion.
source§

impl<'a, T, E, const CLASS: u8, const TAG: u32> TryFrom<Any<'a>> for TaggedValue<T, E, Implicit, CLASS, TAG>
where T: TryFrom<Any<'a>, Error = E> + Tagged, E: From<Error>,

§

type Error = E

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

fn try_from(any: Any<'a>) -> Result<Self, E>

Performs the conversion.
source§

impl<T: Eq, E: Eq, TagKind: Eq, const CLASS: u8, const TAG: u32> Eq for TaggedValue<T, E, TagKind, CLASS, TAG>

source§

impl<T, E, TagKind, const CLASS: u8, const TAG: u32> StructuralPartialEq for TaggedValue<T, E, TagKind, CLASS, TAG>

Auto Trait Implementations§

§

impl<T, E, TagKind, const CLASS: u8, const TAG: u32> Freeze for TaggedValue<T, E, TagKind, CLASS, TAG>
where T: Freeze,

§

impl<T, E, TagKind, const CLASS: u8, const TAG: u32> RefUnwindSafe for TaggedValue<T, E, TagKind, CLASS, TAG>
where T: RefUnwindSafe, TagKind: RefUnwindSafe, E: RefUnwindSafe,

§

impl<T, E, TagKind, const CLASS: u8, const TAG: u32> Send for TaggedValue<T, E, TagKind, CLASS, TAG>
where T: Send, TagKind: Send, E: Send,

§

impl<T, E, TagKind, const CLASS: u8, const TAG: u32> Sync for TaggedValue<T, E, TagKind, CLASS, TAG>
where T: Sync, TagKind: Sync, E: Sync,

§

impl<T, E, TagKind, const CLASS: u8, const TAG: u32> Unpin for TaggedValue<T, E, TagKind, CLASS, TAG>
where T: Unpin, TagKind: Unpin, E: Unpin,

§

impl<T, E, TagKind, const CLASS: u8, const TAG: u32> UnwindSafe for TaggedValue<T, E, TagKind, CLASS, TAG>
where T: UnwindSafe, TagKind: UnwindSafe, E: UnwindSafe,

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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> Choice for T
where T: Tagged,

source§

fn can_decode(tag: Tag) -> bool

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

impl<T> DynTagged for T
where T: Tagged,

source§

fn tag(&self) -> Tag

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<'a, T, E> FromBer<'a, E> for T
where T: TryFrom<Any<'a>, Error = E>, E: From<Error>,

source§

fn from_ber(bytes: &'a [u8]) -> Result<(&'a [u8], T), Err<E>>

Attempt to parse input bytes into a BER object
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.