Struct asn1_rs::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, ) -> Self

Build a new BER/DER header from the provided values

source

pub const fn new_simple(tag: Tag) -> Self

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

source

pub fn with_class(self, class: Class) -> Self

Set the class of this Header

source

pub fn with_constructed(self, constructed: bool) -> Self

Set the constructed flags of this Header

source

pub fn with_tag(self, tag: Tag) -> Self

Set the tag of this Header

source

pub fn with_length(self, length: Length) -> Self

Set the length of this Header

source

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

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<()>

Return error if class is not the expected class

source

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

Return error if tag is not the expected tag

source

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

Return error if object is not primitive

source

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

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<()>

Return error if object length is definite

source

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

Get the content following a BER header

source

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

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

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) -> Self

Converts to this type from the input type.
source§

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

source§

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

Attempt to parse input bytes into a BER object
source§

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

source§

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

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

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>

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

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§

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

§

type Owned = Header<'static>

source§

fn to_static(&self) -> Self::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§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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,

§

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

§

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.