pub struct Header { /* private fields */ }Expand description
ASN.1 DER headers: tag + length component of TLV-encoded values
§Examples
use der::{Decode, Header, Length, Reader, SliceReader, Tag};
let mut reader = SliceReader::new(&[0x04, 0x02, 0x31, 0x32]).unwrap();
let header = Header::decode(&mut reader).expect("valid header");
assert_eq!(header, Header::new(Tag::OctetString, Length::new(2)));
assert_eq!(reader.read_slice(2u8.into()).unwrap(), b"12");use der::{Encode, Header, Length, Tag};
let header = Header::new(Tag::Sequence, Length::new(256));
// Header of 256-byte SEQUENCE is 4-byte long
assert_eq!(header.encoded_len(), Ok(Length::new(4)));Implementations§
Source§impl Header
impl Header
Sourcepub fn is_constructed(&self) -> bool
pub fn is_constructed(&self) -> bool
True if the Tag of this header has its constructed bit set.
Sourcepub fn with_length(&self, length: Length) -> Self
pub fn with_length(&self, length: Length) -> Self
Copy of header with adjusted length.
Trait Implementations§
Source§impl<'a> Decode<'a> for Header
impl<'a> Decode<'a> for Header
Source§impl Encode for Header
impl Encode for Header
Source§fn encoded_len(&self) -> Result<Length>
fn encoded_len(&self) -> Result<Length>
Compute the length of this TLV object in bytes when encoded as ASN.1 DER. Read more
Source§fn encode_to_slice<'a>(&self, buf: &'a mut [u8]) -> Result<&'a [u8]>
fn encode_to_slice<'a>(&self, buf: &'a mut [u8]) -> Result<&'a [u8]>
Encode this TLV object to the provided byte slice, returning a sub-slice
containing the encoded message. Read more
impl Copy for Header
impl Eq for Header
impl StructuralPartialEq for Header
Auto Trait Implementations§
impl Freeze for Header
impl RefUnwindSafe for Header
impl Send for Header
impl Sync for Header
impl Unpin for Header
impl UnsafeUnpin for Header
impl UnwindSafe for Header
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more