Crate block_buffer

source
Expand description

Fixed size buffer for block processing of data.

§Examples

use block_buffer::{EagerBuffer, array::typenum::U4};

let mut buf = EagerBuffer::<U4>::default();

let mut accum = Vec::new();
let msg1: &[u8] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
let msg2: &[u8] = &[10, 11, 12];

buf.digest_blocks(msg1, |blocks| accum.extend_from_slice(blocks));
buf.digest_blocks(msg2, |blocks| accum.extend_from_slice(blocks));

assert_eq!(accum.len(), 3);
assert_eq!(accum[0], [0, 1, 2, 3]);
assert_eq!(accum[1], [4, 5, 6, 7]);
assert_eq!(accum[2], [8, 9, 10, 11]);

let padded_block = buf.pad_with_zeros();
assert_eq!(padded_block, [12, 0, 0, 0]);

Note that block size used with buffers MUST be bigger than zero and smaller than 256. You will get a compilation error with an invalid block size:

use block_buffer::{EagerBuffer, array::typenum::U0};
let buf = EagerBuffer::<U0>::default();
use block_buffer::{EagerBuffer, array::typenum::U256};
let buf = EagerBuffer::<U256>::default();

Re-exports§

Structs§

  • Buffer for block processing of data.
  • Eager block buffer kind, which guarantees that buffer position always lies in the range of 0..BlockSize.
  • Block buffer error.
  • Lazy block buffer kind, which guarantees that buffer position always lies in the range of 0..=BlockSize.
  • Buffer for reading block-generated data.

Traits§

Type Aliases§