Enum bcder::decode::Content

source ·
pub enum Content<'a, S: 'a> {
    Primitive(Primitive<'a, S>),
    Constructed(Constructed<'a, S>),
}
Expand description

The content octets of a BER-encoded value.

A value is either primitive, containing actual octets of an actual value, or constructed, in which case its content contains additional BER encoded values. This enum is useful for cases where a certain type may be encoded as either a primitive value or a complex constructed value.

Note that this type represents the content octets only, i.e., it does not contain the tag of the value.

Variants§

§

Primitive(Primitive<'a, S>)

The value is a primitive value.

§

Constructed(Constructed<'a, S>)

The value is a constructed value.

Implementations§

source§

impl<'a, S: Source + 'a> Content<'a, S>

source

pub fn mode(&self) -> Mode

Returns the encoding mode used by the value.

source

pub fn is_primitive(&self) -> bool

Returns whether this value is a primitive value.

source

pub fn is_constructed(&self) -> bool

Returns whether this value is a constructed value.

source

pub fn as_primitive( &mut self ) -> Result<&mut Primitive<'a, S>, DecodeError<S::Error>>

Converts a reference into into one to a primitive value or errors out.

source

pub fn as_constructed( &mut self ) -> Result<&mut Constructed<'a, S>, DecodeError<S::Error>>

Converts a reference into on to a constructed value or errors out.

source

pub fn content_err(&self, err: impl Into<ContentError>) -> DecodeError<S::Error>

Produces a content error at the current source position.

source§

impl<'a, S: Source + 'a> Content<'a, S>

source

pub fn to_u8(&mut self) -> Result<u8, DecodeError<S::Error>>

Converts content into a u8.

If the content is not primitive or does not contain a single BER encoded INTEGER value between 0 and 256, returns a malformed error.

source

pub fn skip_u8_if(&mut self, expected: u8) -> Result<(), DecodeError<S::Error>>

Skips over the content if it contains an INTEGER of value expected.

The content needs to be primitive and contain a validly encoded integer of value expected or else a malformed error will be returned.

source

pub fn to_u16(&mut self) -> Result<u16, DecodeError<S::Error>>

Converts content into a u16.

If the content is not primitive or does not contain a single BER encoded INTEGER value between 0 and 2^16-1, returns a malformed error.

source

pub fn to_u32(&mut self) -> Result<u32, DecodeError<S::Error>>

Converts content into a u32.

If the content is not primitive or does not contain a single BER encoded INTEGER value between 0 and 2^32-1, returns a malformed error.

source

pub fn to_u64(&mut self) -> Result<u64, DecodeError<S::Error>>

Converts content into a u64.

If the content is not primitive or does not contain a single BER encoded INTEGER value between 0 and 2^64-1, returns a malformed error.

source

pub fn to_null(&mut self) -> Result<(), DecodeError<S::Error>>

Converts the content into a NULL value.

If the content isn’t primitive and contains a single BER encoded NULL value (i.e., nothing), returns a malformed error.

Auto Trait Implementations§

§

impl<'a, S> RefUnwindSafe for Content<'a, S>
where S: RefUnwindSafe,

§

impl<'a, S> Send for Content<'a, S>
where S: Send,

§

impl<'a, S> Sync for Content<'a, S>
where S: Sync,

§

impl<'a, S> Unpin for Content<'a, S>

§

impl<'a, S> !UnwindSafe for Content<'a, S>

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> 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.