Skip to content

Commit

Permalink
digest: add XofReader::read_vec method (RustCrypto#178)
Browse files Browse the repository at this point in the history
...gated under the `alloc` feature.

Allocates a `Vec<u8>` to return an individual `XofReader::read`
invocation into.

Unlike `ExtensibleOutput::finalize_vec`, it doesn't consume the reader
and can be called an unlimited number of times.
  • Loading branch information
tarcieri authored Jun 9, 2020
1 parent bf34b4c commit bdc337c
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion digest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,19 @@ pub trait VariableOutput: core::marker::Sized {
/// Trait for describing readers which are used to extract extendable output
/// from XOF (extendable-output function) result.
pub trait XofReader {
/// Read output into the `buffer`. Can be called unlimited number of times.
/// Read output into the `buffer`. Can be called an unlimited number of times.
fn read(&mut self, buffer: &mut [u8]);

/// Read output into a vector of the specified size.
///
/// Can be called an unlimited number of times in combination with `read`.
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
fn read_vec(&mut self, n: usize) -> Vec<u8> {
let mut buf = vec![0u8; n];
self.read(&mut buf);
buf
}
}

/// Trait which describes extendable-output functions (XOF).
Expand Down

0 comments on commit bdc337c

Please sign in to comment.