Skip to main content

DepthAwareReader

Struct DepthAwareReader 

Source
pub struct DepthAwareReader<'data, R: Read<'data>> { /* private fields */ }
Expand description

Depth-aware wrapper around a Read implementation. If you care about billion-laughs attacks, then you should use it.

Implementations§

Source§

impl<'data, R: Read<'data>> DepthAwareReader<'data, R>

Source

pub const DEFAULT_LIMIT: usize = 256

Default depth limit

Source

pub fn from_reader(reader: R) -> Self

Initializes a DepthAwareReader using Self::DEFAULT_LIMIT as a depth limit

Source

pub fn from_reader_with_limit(reader: R, limit: usize) -> Self

Initializes a DepthAwareReader using a custom depth limit

Source

pub fn enter(&mut self) -> ReadResult<DepthAwareReaderGuard<'_, 'data, R>>

Increments the current depth, checks if it didn’t exceed the limit and returns a Guard that exits this depth when dropped

Trait Implementations§

Source§

impl<'data, R: Debug + Read<'data>> Debug for DepthAwareReader<'data, R>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'data, R: Read<'data>> Read<'data> for DepthAwareReader<'data, R>

Delegate reader impl

Source§

fn peek_byte(&mut self) -> ReadResult<u8>

Peek a single byte over the data stream, without advancing it.
Source§

fn advance(&mut self, n: usize) -> ReadResult<()>

Manually advances the data stream by n bytes. Usually used in tandem with Self::peek_byte
Source§

fn read_byte(&mut self) -> ReadResult<u8>

Read a single byte from the data stream
Source§

fn read_slice<'a>(&'a mut self, len: usize) -> ReadResult<Cow<'data, [u8]>>

Read a byte slice from the data stream of length len Errors out if n is bigger than the remaining data stream
Source§

fn read_array<const N: usize>(&mut self) -> ReadResult<Cow<'data, [u8; N]>>

Read a byte array from the data stream of len N Basically behaves the same as Self::read_slice but with a sized slice
Source§

fn read_till_eof(&mut self) -> ReadResult<Cow<'data, [u8]>>

Reads the data stream till EOF

Auto Trait Implementations§

§

impl<'data, R> Freeze for DepthAwareReader<'data, R>
where R: Freeze,

§

impl<'data, R> RefUnwindSafe for DepthAwareReader<'data, R>
where R: RefUnwindSafe,

§

impl<'data, R> Send for DepthAwareReader<'data, R>
where R: Send,

§

impl<'data, R> Sync for DepthAwareReader<'data, R>
where R: Sync,

§

impl<'data, R> Unpin for DepthAwareReader<'data, R>
where R: Unpin,

§

impl<'data, R> UnsafeUnpin for DepthAwareReader<'data, R>
where R: UnsafeUnpin,

§

impl<'data, R> UnwindSafe for DepthAwareReader<'data, R>
where R: UnwindSafe,

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