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>
impl<'data, R: Read<'data>> DepthAwareReader<'data, R>
Sourcepub const DEFAULT_LIMIT: usize = 256
pub const DEFAULT_LIMIT: usize = 256
Default depth limit
Sourcepub fn from_reader(reader: R) -> Self
pub fn from_reader(reader: R) -> Self
Initializes a DepthAwareReader using Self::DEFAULT_LIMIT as a depth limit
Sourcepub fn from_reader_with_limit(reader: R, limit: usize) -> Self
pub fn from_reader_with_limit(reader: R, limit: usize) -> Self
Initializes a DepthAwareReader using a custom depth limit
Sourcepub fn enter(&mut self) -> ReadResult<DepthAwareReaderGuard<'_, 'data, R>>
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: Read<'data>> Read<'data> for DepthAwareReader<'data, R>
Delegate reader impl
impl<'data, R: Read<'data>> Read<'data> for DepthAwareReader<'data, R>
Delegate reader impl
Source§fn peek_byte(&mut self) -> ReadResult<u8>
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<()>
fn advance(&mut self, n: usize) -> ReadResult<()>
Manually advances the data stream by
n bytes. Usually used in tandem with Self::peek_byteSource§fn read_byte(&mut self) -> ReadResult<u8>
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]>>
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 streamSource§fn read_array<const N: usize>(&mut self) -> ReadResult<Cow<'data, [u8; N]>>
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 sliceSource§fn read_till_eof(&mut self) -> ReadResult<Cow<'data, [u8]>>
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> 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