MCPcopy Create free account
hub / github.com/RustCrypto/utils / test_eager_digest

Function test_eager_digest

block-buffer/tests/mod.rs:16–48  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

14
15#[test]
16fn test_eager_digest() {
17 let mut buf = EagerBuffer::<U4>::default();
18 let inputs = [
19 &b"01234567"[..],
20 &b"89"[..],
21 &b"abcdefghij"[..],
22 &b"klmnopqrs"[..],
23 &b"tuv"[..],
24 &b"wx"[..],
25 ];
26 let exp_blocks = [
27 (0, &[b"0123", b"4567"][..]),
28 (2, &[b"89ab"][..]),
29 (2, &[b"cdef", b"ghij"][..]),
30 (3, &[b"klmn", b"opqr"][..]),
31 (4, &[b"stuv"][..]),
32 ];
33 let exp_poses = [0, 2, 0, 1, 0, 2];
34
35 let mut n = 0;
36 for (i, input) in inputs.iter().enumerate() {
37 buf.digest_blocks(input, |b| {
38 let (j, exp) = exp_blocks[n];
39 n += 1;
40 assert_eq!(i, j);
41 assert_eq!(b.len(), exp.len());
42 assert!(b.iter().zip(exp.iter()).all(|v| v.0[..] == v.1[..]));
43 });
44 assert_eq!(exp_poses[i], buf.get_pos());
45 }
46 assert_eq!(buf.pad_with_zeros()[..], b"wx\0\0"[..]);
47 assert_eq!(buf.get_pos(), 0);
48}
49
50#[test]
51fn test_lazy_digest() {

Callers

nothing calls this directly

Calls 2

defaultFunction · 0.85
digest_blocksMethod · 0.80

Tested by

no test coverage detected