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
//! Fixed size buffer for block processing of data.
#![no_std]
#![doc(
    html_logo_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg",
    html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg",
    html_root_url = "https://docs.rs/block-buffer/0.10.0-pre.3"
)]
#![warn(missing_docs, rust_2018_idioms)]

#[cfg(feature = "block-padding")]
pub use block_padding;
pub use generic_array;

use generic_array::{ArrayLength, GenericArray};

mod buffer;
mod lazy;
mod utils;

pub use buffer::BlockBuffer;
pub use lazy::LazyBlockBuffer;

/// Block on which a `BlockBuffer` operates.
pub type Block<BlockSize> = GenericArray<u8, BlockSize>;
/// Blocks being acted over in parallel.
pub type ParBlock<BlockSize, ParBlocks> = GenericArray<Block<BlockSize>, ParBlocks>;

/// Trait which generalizes digest functionality of buffers.
pub trait DigestBuffer<BlockSize: ArrayLength<u8>>: Default {
    /// Digest data in `input` in blocks of size `BlockSize` using
    /// the `compress` function, which accepts slice of blocks.
    fn digest_blocks(&mut self, input: &[u8], compress: impl FnMut(&[Block<BlockSize>]));

    /// Reset buffer by setting cursor position to zero.
    fn reset(&mut self);
}