Header

Struct 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 duplicate 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> 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> 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 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

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 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>, SerializeError>

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

fn to_der_vec_raw(&self) -> Result<Vec<u8>, 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 ToStatic for Header<'_>

Source§

type Owned = Header<'static>

Source§

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

Source§

impl Eq for Header<'_>

Auto Trait Implementations§

§

impl<'a> Freeze for Header<'a>

§

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 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

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

Source§

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.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 48 bytes