Skip to main content

BerReader

Struct BerReader 

Source
pub struct BerReader<'a> { /* private fields */ }
Expand description

A BER reader that decodes TLV elements from a byte slice.

Implementations§

Source§

impl<'a> BerReader<'a>

Source

pub fn new(buf: &'a [u8]) -> Self

Creates a new reader over the given buffer.

Source

pub fn pos(&self) -> usize

Returns the current read position.

Source

pub fn remaining(&self) -> usize

Returns the remaining unread bytes.

Source

pub fn is_empty(&self) -> bool

Returns true if all bytes have been consumed.

Source

pub fn peek_tag(&self) -> Result<(u8, Class, bool), SleError>

Peeks at the next tag without advancing the position. Returns (tag_number, class, constructed).

Source

pub fn read_tag(&mut self) -> Result<(u8, Class, bool), SleError>

Reads and validates a tag, returning its components.

Source

pub fn read_length(&mut self) -> Result<usize, SleError>

Reads a length field.

Source

pub fn read_raw(&mut self, len: usize) -> Result<&'a [u8], SleError>

Reads raw bytes of the given length.

Source

pub fn read_bool(&mut self) -> Result<bool, SleError>

Reads an ASN.1 BOOLEAN.

Source

pub fn read_integer(&mut self) -> Result<i64, SleError>

Reads an ASN.1 INTEGER as i64.

Source

pub fn read_octet_string(&mut self) -> Result<&'a [u8], SleError>

Reads an ASN.1 OCTET STRING, returning the raw bytes.

Source

pub fn read_enum(&mut self) -> Result<i64, SleError>

Reads an ASN.1 ENUMERATED as i64.

Source

pub fn read_null(&mut self) -> Result<(), SleError>

Reads an ASN.1 NULL.

Source

pub fn read_sequence(&mut self) -> Result<usize, SleError>

Reads a SEQUENCE tag+length, returning the content length. The caller should then read the contained elements.

Source

pub fn read_context_tag(&mut self) -> Result<(u8, usize), SleError>

Reads a context-tagged wrapper, returning the tag number and content length.

Source

pub fn sub_reader(&mut self, len: usize) -> Result<BerReader<'a>, SleError>

Creates a sub-reader limited to len bytes from the current position, advancing past them.

Auto Trait Implementations§

§

impl<'a> Freeze for BerReader<'a>

§

impl<'a> RefUnwindSafe for BerReader<'a>

§

impl<'a> Send for BerReader<'a>

§

impl<'a> Sync for BerReader<'a>

§

impl<'a> Unpin for BerReader<'a>

§

impl<'a> UnsafeUnpin for BerReader<'a>

§

impl<'a> UnwindSafe for BerReader<'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<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> 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> Same for T

Source§

type Output = T

Should always be Self
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.