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
sourceimpl<'a, S: Source + 'a> Content<'a, S>
impl<'a, S: Source + 'a> Content<'a, S>
sourcepub fn is_primitive(&self) -> bool
pub fn is_primitive(&self) -> bool
Returns whether this value is a primitive value.
sourcepub fn is_constructed(&self) -> bool
pub fn is_constructed(&self) -> bool
Returns whether this value is a constructed value.
sourcepub fn as_primitive(
&mut self
) -> Result<&mut Primitive<'a, S>, DecodeError<S::Error>>
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.
sourcepub fn as_constructed(
&mut self
) -> Result<&mut Constructed<'a, S>, DecodeError<S::Error>>
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.
sourcepub fn content_err(&self, err: impl Into<ContentError>) -> DecodeError<S::Error>
pub fn content_err(&self, err: impl Into<ContentError>) -> DecodeError<S::Error>
Produces a content error at the current source position.
sourceimpl<'a, S: Source + 'a> Content<'a, S>
impl<'a, S: Source + 'a> Content<'a, S>
sourcepub fn to_u8(&mut self) -> Result<u8, DecodeError<S::Error>>
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.
sourcepub fn skip_u8_if(&mut self, expected: u8) -> Result<(), DecodeError<S::Error>>
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.
sourcepub fn to_u16(&mut self) -> Result<u16, DecodeError<S::Error>>
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.
sourcepub fn to_u32(&mut self) -> Result<u32, DecodeError<S::Error>>
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.
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more