Crate block_buffer
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();
Modules
Structs
- BlockBuffer Buffer for block processing of data.
-
Eager
Eager block buffer kind, which guarantees that buffer position
always lies in the range of
0..BlockSize. - Error Block buffer error.
-
Lazy
Lazy block buffer kind, which guarantees that buffer position
always lies in the range of
0..=BlockSize. - ReadBuffer Buffer for reading block-generated data.
Traits
-
BlockSizes
Trait implemented for supported block sizes, i.e. for types from
U1toU255. - BufferKind Trait for buffer kinds.
Type Aliases
- EagerBuffer Eager block buffer.
- LazyBuffer Lazy block buffer.
-
SerializedBuffer
BlockBufferserialized as a byte array. -
SerializedBufferSize
Size of serialized
BlockBufferin bytes.