pub struct OutputReader { /* private fields */ }Expand description
An incremental reader for extended output, returned by
Hasher::finalize_xof.
Shorter BLAKE3 outputs are prefixes of longer ones, and explicitly requesting a short output is equivalent to truncating the default-length output. Note that this is a difference between BLAKE2 and BLAKE3.
§Security notes
Outputs shorter than the default length of 32 bytes (256 bits) provide less security. An N-bit BLAKE3 output is intended to provide N bits of first and second preimage resistance and N/2 bits of collision resistance, for any N up to 256. Longer outputs don’t provide any additional security.
Avoid relying on the secrecy of the output offset, that is, the number of output bytes read or
the arguments to seek or
set_position. Block-Cipher-Based Tree
Hashing by Aldo Gunsing shows that an attacker who knows
both the message and the key (if any) can easily determine the offset of an extended output.
For comparison, AES-CTR has a similar property: if you know the key, you can decrypt a block
from an unknown position in the output stream to recover its block index. Callers with strong
secret keys aren’t affected in practice, but secret offsets are a design
smell in any case.
§Trait implementations
Clonereads the same output from the same position, with an independent cursor.Debugreports the position without disclosing the output or key.Readadvances by the bytes returned, stopping at positionu64::MAX.Seekmoves within the same output, clamping past its end and refusing negative positions and seeks relative to the end.
Implementations§
Source§impl OutputReader
impl OutputReader
Sourcepub fn fill(&mut self, buf: &mut [u8])
pub fn fill(&mut self, buf: &mut [u8])
Fill a buffer with output bytes and advance the position of the
OutputReader. It always fills the entire buffer. Read::read
does the same up to the output’s end, and differs there: it reads
the bytes that are left and after them 0 bytes, where this call
panics (below).
A partial output block is retained for subsequent short reads, so
sequential reads don’t recompute that block. Whole blocks continue
through the vectorized output path. For streaming throughput, prefer
a slice length that’s a multiple of BLOCK_LEN (64 bytes).
The maximum output size of BLAKE3 is 264-1 bytes.
§Panics
If buf asks for bytes past that end (after seeking near it), in
every build: the position cannot count them. Read::read reads
up to the end instead, and then gives 0 bytes.
Sourcepub fn position(&self) -> u64
pub fn position(&self) -> u64
Return the current read position in the output stream. This is
equivalent to Seek::stream_position, except that it doesn’t return
a Result. The position of a new OutputReader starts at 0, and each
call to fill or Read::read moves the position forward by the
number of bytes read.
Sourcepub fn set_position(&mut self, position: u64)
pub fn set_position(&mut self, position: u64)
Seek to a new read position in the output stream. This is equivalent to
calling Seek::seek with SeekFrom::Start, except that it doesn’t
return a Result.
Trait Implementations§
Source§impl Clone for OutputReader
impl Clone for OutputReader
Source§impl Debug for OutputReader
impl Debug for OutputReader
Source§impl Read for OutputReader
impl Read for OutputReader
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error>
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error>
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), Error>
read_buf)Source§fn read_buf_exact(
&mut self,
cursor: BorrowedCursor<'_, u8>,
) -> Result<(), Error>
fn read_buf_exact( &mut self, cursor: BorrowedCursor<'_, u8>, ) -> Result<(), Error>
read_buf)cursor. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read. Read more1.0.0 · Source§fn chain<R>(self, next: R) -> Chain<Self, R> ⓘ
fn chain<R>(self, next: R) -> Chain<Self, R> ⓘ
1.0.0 · Source§fn take(self, limit: u64) -> Take<Self> ⓘwhere
Self: Sized,
fn take(self, limit: u64) -> Take<Self> ⓘwhere
Self: Sized,
limit bytes from it. Read moreSource§fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>where
Self: Sized,
fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>where
Self: Sized,
read_array)Source§impl Seek for OutputReader
impl Seek for OutputReader
Source§fn seek(&mut self, pos: SeekFrom) -> Result<u64, Error>
fn seek(&mut self, pos: SeekFrom) -> Result<u64, Error>
1.55.0 · Source§fn rewind(&mut self) -> Result<(), Error>
fn rewind(&mut self) -> Result<(), Error>
Source§fn stream_len(&mut self) -> Result<u64, Error>
fn stream_len(&mut self) -> Result<u64, Error>
seek_stream_len)