Skip to content

Commit bdc337c

Browse files
authored
digest: add XofReader::read_vec method (#178)
...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.
1 parent bf34b4c commit bdc337c

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

digest/src/lib.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,19 @@ pub trait VariableOutput: core::marker::Sized {
114114
/// Trait for describing readers which are used to extract extendable output
115115
/// from XOF (extendable-output function) result.
116116
pub trait XofReader {
117-
/// Read output into the `buffer`. Can be called unlimited number of times.
117+
/// Read output into the `buffer`. Can be called an unlimited number of times.
118118
fn read(&mut self, buffer: &mut [u8]);
119+
120+
/// Read output into a vector of the specified size.
121+
///
122+
/// Can be called an unlimited number of times in combination with `read`.
123+
#[cfg(feature = "alloc")]
124+
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
125+
fn read_vec(&mut self, n: usize) -> Vec<u8> {
126+
let mut buf = vec![0u8; n];
127+
self.read(&mut buf);
128+
buf
129+
}
119130
}
120131

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

0 commit comments

Comments
 (0)