Struct der_parser::ber::Header

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

BER/DER object header (identifier and length)

Implementations§

source§

impl<'a> Header<'a>

source

pub const fn new( class: Class, constructed: bool, tag: Tag, length: Length ) -> Header<'a>

Build a new BER/DER header from the provided values

source

pub const fn new_simple(tag: Tag) -> Header<'a>

Build a new BER/DER header from the provided tag, with default values for other fields

source

pub fn with_class(self, class: Class) -> Header<'a>

Set the class of this Header

source

pub fn with_constructed(self, constructed: bool) -> Header<'a>

Set the constructed flags of this Header

source

pub fn with_tag(self, tag: Tag) -> Header<'a>

Set the tag of this Header

source

pub fn with_length(self, length: Length) -> Header<'a>

Set the length of this Header

source

pub fn with_raw_tag(self, raw_tag: Option<Cow<'a, [u8]>>) -> Header<'a>

Update header to add reference to raw tag

source

pub const fn class(&self) -> Class

Return the class of this header.

source

pub const fn constructed(&self) -> bool

Return true if this header has the ‘constructed’ flag.

source

pub const fn tag(&self) -> Tag

Return the tag of this header.

source

pub const fn length(&self) -> Length

Return the length of this header.

source

pub fn raw_tag(&self) -> Option<&[u8]>

Return the raw tag encoding, if it was stored in this object

source

pub const fn is_primitive(&self) -> bool

Test if object is primitive

source

pub const fn is_constructed(&self) -> bool

Test if object is constructed

source

pub const fn assert_class(&self, class: Class) -> Result<(), Error>

Return error if class is not the expected class

source

pub const fn assert_tag(&self, tag: Tag) -> Result<(), Error>

Return error if tag is not the expected tag

source

pub const fn assert_primitive(&self) -> Result<(), Error>

Return error if object is not primitive

source

pub const fn assert_constructed(&self) -> Result<(), Error>

Return error if object is primitive

source

pub const fn is_universal(&self) -> bool

Test if object class is Universal

source

pub const fn is_application(&self) -> bool

Test if object class is Application

source

pub const fn is_contextspecific(&self) -> bool

Test if object class is Context-specific

source

pub const fn is_private(&self) -> bool

Test if object class is Private

source

pub const fn assert_definite(&self) -> Result<(), Error>

Return error if object length is definite

source

pub fn parse_ber_content<'i>( &self, i: &'i [u8] ) -> Result<(&'i [u8], &'i [u8]), Err<Error>>

Get the content following a BER header

source

pub fn parse_der_content<'i>( &self, i: &'i [u8] ) -> Result<(&'i [u8], &'i [u8]), Err<Error>>

Get the content following a DER header

Trait Implementations§

source§

impl<'a> Clone for Header<'a>

source§

fn clone(&self) -> Header<'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 Header<'a>

source§

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

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

impl DynTagged for Header<'_>

source§

fn tag(&self) -> Tag

source§

impl From<Tag> for Header<'_>

source§

fn from(tag: Tag) -> Header<'_>

Converts to this type from the input type.
source§

impl<'a> FromBer<'a, Error> for Header<'a>

source§

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

Attempt to parse input bytes into a BER object
source§

impl<'a> FromDer<'a, Error> for Header<'a>

source§

fn from_der(bytes: &'a [u8]) -> Result<(&'a [u8], Header<'a>), Err<Error>>

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

impl<'a> PartialEq<Header<'a>> for Header<'a>

Compare two BER headers. len fields are compared only if both objects have it set (same for raw_tag)

source§

fn eq(&self, other: &Header<'_>) -> 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 ToDer for Header<'_>

source§

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

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

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

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

fn write_der_content( &self, _writer: &mut dyn Write ) -> Result<usize, SerializeError>

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

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

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

fn to_der_vec(&self) -> Result<Vec<u8, Global>, SerializeError>

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

fn to_der_vec_raw(&self) -> Result<Vec<u8, Global>, SerializeError>

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) -> Result<usize, SerializeError>

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

impl<'a> ToStatic for Header<'a>

§

type Owned = Header<'static>

source§

fn to_static(&self) -> <Header<'a> as ToStatic>::Owned

source§

impl Eq for Header<'_>

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for Header<'a>

§

impl<'a> Send for Header<'a>

§

impl<'a> Sync for Header<'a>

§

impl<'a> Unpin for Header<'a>

§

impl<'a> UnwindSafe for Header<'a>

Blanket Implementations§

source§

impl<T> Any for Twhere 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 Twhere T: 'a,

source§

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

source§

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

source§

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

source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.