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

Buffer for block processing of data.

Implementations§

source§

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

source

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

Create new buffer from slice.

§Panics

If slice length is not valid for used buffer kind.

source

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

Create new buffer from slice.

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

source

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

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

source

pub fn reset(&mut self)

Reset buffer by setting cursor position to zero.

source

pub fn pad_with_zeros(&mut self) -> Block<Self>

Pad remaining data with zeros and return resulting block.

source

pub fn get_pos(&self) -> usize

Return current cursor position.

source

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

Return slice of data stored inside the buffer.

source

pub fn set(&mut self, buf: Block<Self>, pos: usize)

Set buffer content and cursor position.

§Panics

If pos is bigger or equal to block size.

source

pub fn size(&self) -> usize

Return size of the internal buffer in bytes.

source

pub fn remaining(&self) -> usize

Return number of remaining bytes in the internal buffer.

source§

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

source

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

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.

source

pub fn len64_padding_be( &mut self, data_len: u64, compress: impl FnMut(&Block<Self>) )

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

source

pub fn len64_padding_le( &mut self, data_len: u64, compress: impl FnMut(&Block<Self>) )

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

source

pub fn len128_padding_be( &mut self, data_len: u128, compress: impl FnMut(&Block<Self>) )

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

source

pub fn serialize(&self) -> Block<Self>

Serialize buffer into a byte array.

source

pub fn deserialize(buffer: &Block<Self>) -> Result<Self, Error>

Deserialize buffer from a byte array.

source§

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

source

pub fn serialize(&self) -> Array<u8, Add1<BS>>
where BS: Add<B1>, Add1<BS>: ArraySize,

Serialize buffer into a byte array.

source

pub fn deserialize(buffer: &Array<u8, Add1<BS>>) -> Result<Self, Error>
where BS: Add<B1>, Add1<BS>: ArraySize,

Deserialize buffer from a byte array.

Trait Implementations§

source§

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

§

type BlockSize = BS

Size of the block in bytes.
source§

fn block_size() -> usize

Return block size in bytes.
source§

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

source§

fn clone(&self) -> Self

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
source§

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

source§

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

Formats the value using the given formatter. Read more
source§

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

source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<BS, K> RefUnwindSafe for BlockBuffer<BS, K>
where <BS as ArraySize>::ArrayType<u8>: RefUnwindSafe, <K as Sealed>::Pos: RefUnwindSafe,

§

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

§

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

§

impl<BS, K> Unpin for BlockBuffer<BS, K>
where <BS as ArraySize>::ArrayType<u8>: Unpin, <K as Sealed>::Pos: Unpin,

§

impl<BS, K> UnwindSafe for BlockBuffer<BS, K>
where <BS as ArraySize>::ArrayType<u8>: UnwindSafe, <K as Sealed>::Pos: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where 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 T
where 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 for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where 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 T
where 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.