Struct BlockBuffer

pub struct BlockBuffer<BS: BlockSizes, K: BufferKind> { /* private fields */ }

Buffer for block processing of data.

Implementations

impl<BS, K: BufferKind> BlockBuffer<BS, K> where BS: Add<K::Overhead> + BlockSizes, Sum<BS, K::Overhead>: ArraySize,

fn serialize(&self) -> SerializedBuffer<BS, K>

Serialize buffer into a byte array.

fn deserialize(buf: &SerializedBuffer<BS, K>) -> Result<Self, Error>

Deserialize buffer from a byte array.

Errors

If buf does not represent a valid serialization of BlockBuffer.

impl<BS: BlockSizes> BlockBuffer<BS, Eager>

fn digest_pad(&mut self, delim: u8, suffix: &[u8], compress: impl FnMut(&Array<u8, BS>))

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.

fn len64_padding_be(&mut self, data_len: u64, compress: impl FnMut(&Array<u8, BS>))

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

fn len64_padding_le(&mut self, data_len: u64, compress: impl FnMut(&Array<u8, BS>))

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

fn len128_padding_be(&mut self, data_len: u128, compress: impl FnMut(&Array<u8, BS>))

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

impl<BS: BlockSizes, K: BufferKind> BlockBuffer<BS, K>

fn new(buf: &[u8]) -> Self

Create new buffer from slice.

Panics

If slice length is not valid for used buffer kind.

fn try_new(buf: &[u8]) -> Result<Self, Error>

Create new buffer from slice.

Errors

If slice length is not valid for used buffer kind.

fn digest_blocks(&mut self, input: &[u8], compress: impl FnMut(&[Array<u8, BS>]))

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

fn reset(&mut self)

Reset buffer by setting cursor position to zero.

fn pad_with_zeros(&mut self) -> Array<u8, BS>

Pad remaining data with zeros and return resulting block.

fn get_pos(&self) -> usize

Return current cursor position.

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

Return slice of data stored inside the buffer.

fn set(&mut self, buf: Array<u8, BS>, pos: usize)

Set buffer content and cursor position.

Panics

If pos is bigger or equal to block size.

fn size(&self) -> usize

Return size of the internal buffer in bytes.

fn remaining(&self) -> usize

Return number of remaining bytes in the internal buffer.

Trait Implementations

impl<BS: BlockSizes, K: BufferKind> Clone for BlockBuffer<BS, K>

fn clone(&self) -> Self

impl<BS: BlockSizes, K: BufferKind> Debug for BlockBuffer<BS, K>

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

impl<BS: BlockSizes, K: BufferKind> Default for BlockBuffer<BS, K>

fn default() -> Self

impl<BS: BlockSizes, K: BufferKind> Drop for BlockBuffer<BS, K>

fn drop(&mut self)

impl<BS: BlockSizes, K: BufferKind> Zeroize for BlockBuffer<BS, K>

fn zeroize(&mut self)

impl<BS: BlockSizes, K: BufferKind> ZeroizeOnDrop for BlockBuffer<BS, K>

Auto Trait Implementations

impl<BS, K> Freeze for BlockBuffer<BS, K> where MaybeUninit<Array<u8, BS>>: Freeze, <K as Sealed>::Pos: Freeze,

impl<BS, K> RefUnwindSafe for BlockBuffer<BS, K> where MaybeUninit<Array<u8, BS>>: RefUnwindSafe, <K as Sealed>::Pos: RefUnwindSafe,

impl<BS, K> Send for BlockBuffer<BS, K> where MaybeUninit<Array<u8, BS>>: Send, <K as Sealed>::Pos: Send,

impl<BS, K> Sync for BlockBuffer<BS, K> where MaybeUninit<Array<u8, BS>>: Sync, <K as Sealed>::Pos: Sync,

impl<BS, K> Unpin for BlockBuffer<BS, K> where MaybeUninit<Array<u8, BS>>: Unpin, <K as Sealed>::Pos: Unpin,

impl<BS, K> UnsafeUnpin for BlockBuffer<BS, K> where MaybeUninit<Array<u8, BS>>: UnsafeUnpin, <K as Sealed>::Pos: UnsafeUnpin,

impl<BS, K> UnwindSafe for BlockBuffer<BS, K> where MaybeUninit<Array<u8, BS>>: UnwindSafe, <K as Sealed>::Pos: UnwindSafe,

Blanket Implementations

impl<T> Any for BlockBuffer<BS, K> where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for BlockBuffer<BS, K> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for BlockBuffer<BS, K> where T: ?Sized,

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

impl<T> CloneToUninit for BlockBuffer<BS, K> where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for BlockBuffer<BS, K>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> Same for BlockBuffer<BS, K>

type Output = T;

impl<T> ToOwned for BlockBuffer<BS, K> where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T, U> Into<U> for BlockBuffer<BS, K> where U: From<T>,

fn into(self) -> U

Calls U::from(self).

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

impl<T, U> TryFrom<U> for BlockBuffer<BS, K> where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

impl<T, U> TryInto<U> for BlockBuffer<BS, K> where U: TryFrom<T>,

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