Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

digest: add XofReader::read_vec method #178

Merged
merged 1 commit into from Jun 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion digest/src/lib.rs
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