1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//! Extendable-output function (XOF) trait.
/// Extendable-output function producing an arbitrary number of bytes.
///
/// This trait intentionally has no `std::io::Read` dependency; it is usable in
/// `no_std` environments.
///
/// # Examples
///
/// ```rust
/// # use rscrypto::traits::Xof;
/// # #[derive(Clone)]
/// # struct MyXof(u8);
/// # impl MyXof {
/// # fn xof(data: &[u8]) -> Self {
/// # Self(data.iter().fold(0u8, |acc, &b| acc.wrapping_add(b)))
/// # }
/// # }
/// # impl Xof for MyXof {
/// # fn squeeze(&mut self, out: &mut [u8]) {
/// # for b in out.iter_mut() { *b = self.0; self.0 = self.0.wrapping_add(1); }
/// # }
/// # }
///
/// let mut xof = MyXof::xof(b"hello world");
/// let mut out = [0u8; 64];
/// xof.squeeze(&mut out);
/// assert_ne!(out, [0u8; 64]);
/// ```