pub struct BlockBuffer<BlockSize, Kind>where
    BlockSize: ArrayLength<u8> + IsLess<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>, B0>, B0>>,
    <BlockSize as IsLess<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>, B0>, B0>>>::Output: NonZero,
    Kind: BufferKind,{ /* private fields */ }
Expand description

Buffer for block processing of data.

Implementations§

§

impl<BlockSize, Kind> BlockBuffer<BlockSize, Kind>where BlockSize: ArrayLength<u8> + IsLess<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>, B0>, B0>>, <BlockSize as IsLess<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>, B0>, B0>>>::Output: NonZero, Kind: BufferKind,

pub fn new(buf: &[u8]) -> BlockBuffer<BlockSize, Kind>

Create new buffer from slice.

Panics

If slice length is not valid for used buffer kind.

pub fn try_new(buf: &[u8]) -> Result<BlockBuffer<BlockSize, Kind>, Error>

Create new buffer from slice.

Returns an error if slice length is not valid for used buffer kind.

pub fn digest_blocks( &mut self, input: &[u8], compress: impl FnMut(&[GenericArray<u8, BlockSize>]) )

Digest data in input in blocks of size BlockSize using the compress function, which accepts slice of blocks.

pub fn reset(&mut self)

Reset buffer by setting cursor position to zero.

pub fn pad_with_zeros(&mut self) -> &mut GenericArray<u8, BlockSize>

Pad remaining data with zeros and return resulting block.

pub fn get_pos(&self) -> usize

Return current cursor position.

pub fn get_data(&self) -> &[u8]

Return slice of data stored inside the buffer.

pub fn set(&mut self, buf: GenericArray<u8, BlockSize>, pos: usize)

Set buffer content and cursor position.

Panics

If pos is bigger or equal to block size.

pub fn size(&self) -> usize

Return size of the internal buffer in bytes.

pub fn remaining(&self) -> usize

Return number of remaining bytes in the internal buffer.

§

impl<BlockSize> BlockBuffer<BlockSize, Eager>where BlockSize: ArrayLength<u8> + IsLess<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>, B0>, B0>>, <BlockSize as IsLess<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>, B0>, B0>>>::Output: NonZero,

pub fn set_data( &mut self, data: &mut [u8], process_blocks: impl FnMut(&mut [GenericArray<u8, BlockSize>]) )

Set data to generated blocks.

pub fn digest_pad( &mut self, delim: u8, suffix: &[u8], compress: impl FnMut(&GenericArray<u8, BlockSize>) )

Compress remaining data after padding it with delim, zeros and the suffix bytes. If there is not enough unused space, compress will be called twice.

Panics

If suffix length is bigger than block size.

pub fn len64_padding_be( &mut self, data_len: u64, compress: impl FnMut(&GenericArray<u8, BlockSize>) )

Pad message with 0x80, zeros and 64-bit message length using big-endian byte order.

pub fn len64_padding_le( &mut self, data_len: u64, compress: impl FnMut(&GenericArray<u8, BlockSize>) )

Pad message with 0x80, zeros and 64-bit message length using little-endian byte order.

pub fn len128_padding_be( &mut self, data_len: u128, compress: impl FnMut(&GenericArray<u8, BlockSize>) )

Pad message with 0x80, zeros and 128-bit message length using big-endian byte order.

Trait Implementations§

§

impl<BlockSize, Kind> Clone for BlockBuffer<BlockSize, Kind>where BlockSize: ArrayLength<u8> + IsLess<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>, B0>, B0>>, <BlockSize as IsLess<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>, B0>, B0>>>::Output: NonZero, Kind: BufferKind,

§

fn clone(&self) -> BlockBuffer<BlockSize, Kind>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl<BlockSize, Kind> Debug for BlockBuffer<BlockSize, Kind>where BlockSize: Debug + ArrayLength<u8> + IsLess<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>, B0>, B0>>, Kind: Debug + BufferKind, <BlockSize as IsLess<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>, B0>, B0>>>::Output: NonZero,

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl<BlockSize, Kind> Default for BlockBuffer<BlockSize, Kind>where BlockSize: ArrayLength<u8> + IsLess<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>, B0>, B0>>, <BlockSize as IsLess<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>, B0>, B0>>>::Output: NonZero, Kind: BufferKind,

§

fn default() -> BlockBuffer<BlockSize, Kind>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<BlockSize, Kind> RefUnwindSafe for BlockBuffer<BlockSize, Kind>where Kind: RefUnwindSafe, <BlockSize as ArrayLength<u8>>::ArrayType: RefUnwindSafe,

§

impl<BlockSize, Kind> Send for BlockBuffer<BlockSize, Kind>where Kind: Send,

§

impl<BlockSize, Kind> Sync for BlockBuffer<BlockSize, Kind>where Kind: Sync,

§

impl<BlockSize, Kind> Unpin for BlockBuffer<BlockSize, Kind>where Kind: Unpin, <BlockSize as ArrayLength<u8>>::ArrayType: Unpin,

§

impl<BlockSize, Kind> UnwindSafe for BlockBuffer<BlockSize, Kind>where Kind: UnwindSafe, <BlockSize as ArrayLength<u8>>::ArrayType: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.