pub struct Header<'a> { /* private fields */ }
Expand description
BER/DER object header (identifier and length)
Implementations§
Source§impl<'a> Header<'a>
impl<'a> Header<'a>
Sourcepub const fn new(
class: Class,
constructed: bool,
tag: Tag,
length: Length,
) -> Self
pub const fn new( class: Class, constructed: bool, tag: Tag, length: Length, ) -> Self
Build a new BER/DER header from the provided values
Sourcepub const fn new_simple(tag: Tag) -> Self
pub const fn new_simple(tag: Tag) -> Self
Build a new BER/DER header from the provided tag, with default values for other fields
Sourcepub fn with_class(self, class: Class) -> Self
pub fn with_class(self, class: Class) -> Self
Set the class of this Header
Sourcepub fn with_constructed(self, constructed: bool) -> Self
pub fn with_constructed(self, constructed: bool) -> Self
Set the constructed flags of this Header
Sourcepub fn with_length(self, length: Length) -> Self
pub fn with_length(self, length: Length) -> Self
Set the length of this Header
Sourcepub fn with_raw_tag(self, raw_tag: Option<Cow<'a, [u8]>>) -> Self
pub fn with_raw_tag(self, raw_tag: Option<Cow<'a, [u8]>>) -> Self
Update header to add reference to raw tag
Sourcepub const fn constructed(&self) -> bool
pub const fn constructed(&self) -> bool
Return true if this header has the ‘constructed’ flag.
Sourcepub fn raw_tag(&self) -> Option<&[u8]>
pub fn raw_tag(&self) -> Option<&[u8]>
Return the raw tag encoding, if it was stored in this object
Sourcepub const fn is_primitive(&self) -> bool
pub const fn is_primitive(&self) -> bool
Test if object is primitive
Sourcepub const fn is_constructed(&self) -> bool
pub const fn is_constructed(&self) -> bool
Test if object is constructed
Sourcepub const fn assert_class(&self, class: Class) -> Result<()>
pub const fn assert_class(&self, class: Class) -> Result<()>
Return error if class is not the expected class
Sourcepub const fn assert_tag(&self, tag: Tag) -> Result<()>
pub const fn assert_tag(&self, tag: Tag) -> Result<()>
Return error if tag is not the expected tag
Sourcepub const fn assert_primitive(&self) -> Result<()>
pub const fn assert_primitive(&self) -> Result<()>
Return error if object is not primitive
Sourcepub const fn assert_constructed(&self) -> Result<()>
pub const fn assert_constructed(&self) -> Result<()>
Return error if object is primitive
Sourcepub const fn is_universal(&self) -> bool
pub const fn is_universal(&self) -> bool
Test if object class is Universal
Sourcepub const fn is_application(&self) -> bool
pub const fn is_application(&self) -> bool
Test if object class is Application
Sourcepub const fn is_contextspecific(&self) -> bool
pub const fn is_contextspecific(&self) -> bool
Test if object class is Context-specific
Sourcepub const fn is_private(&self) -> bool
pub const fn is_private(&self) -> bool
Test if object class is Private
Sourcepub const fn assert_definite(&self) -> Result<()>
pub const fn assert_definite(&self) -> Result<()>
Return error if object length is definite
Sourcepub fn parse_ber_content<'i>(&self, i: &'i [u8]) -> ParseResult<'i, &'i [u8]>
pub fn parse_ber_content<'i>(&self, i: &'i [u8]) -> ParseResult<'i, &'i [u8]>
Get the content following a BER header
Sourcepub fn parse_der_content<'i>(&self, i: &'i [u8]) -> ParseResult<'i, &'i [u8]>
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> FromBer<'a> for Header<'a>
impl<'a> FromBer<'a> for Header<'a>
Source§fn from_ber(bytes: &'a [u8]) -> ParseResult<'_, Self>
fn from_ber(bytes: &'a [u8]) -> ParseResult<'_, Self>
Source§impl<'a> FromDer<'a> for Header<'a>
impl<'a> FromDer<'a> for Header<'a>
Source§fn from_der(bytes: &'a [u8]) -> ParseResult<'_, Self>
fn from_der(bytes: &'a [u8]) -> ParseResult<'_, Self>
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
)
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§impl ToDer for Header<'_>
impl ToDer for Header<'_>
Source§fn to_der_len(&self) -> Result<usize>
fn to_der_len(&self) -> Result<usize>
Source§fn write_der_header(&self, writer: &mut dyn Write) -> SerializeResult<usize>
fn write_der_header(&self, writer: &mut dyn Write) -> SerializeResult<usize>
Source§fn write_der_content(&self, _writer: &mut dyn Write) -> SerializeResult<usize>
fn write_der_content(&self, _writer: &mut dyn Write) -> SerializeResult<usize>
Source§fn write_der_raw(&self, writer: &mut dyn Write) -> SerializeResult<usize>
fn write_der_raw(&self, writer: &mut dyn Write) -> SerializeResult<usize>
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>>
fn to_der_vec(&self) -> SerializeResult<Vec<u8>>
Vec<u8>
.Source§fn to_der_vec_raw(&self) -> SerializeResult<Vec<u8>>
fn to_der_vec_raw(&self) -> SerializeResult<Vec<u8>>
to_vec
, but uses provided values without changes.
This can generate an invalid encoding for a DER object.