pub struct NoPadding;Expand description
Don’t pad the data. Useful for key wrapping.
use block_padding::{NoPadding, Padding};
use block_padding::array::{Array, typenum::U8};
let msg = b"test";
let pos = msg.len();
let mut block: Array::<u8, U8> = [0xff; 8].into();
block[..pos].copy_from_slice(msg);
NoPadding::pad(&mut block, pos);
assert_eq!(&block[..], b"test\xff\xff\xff\xff");
let res = NoPadding::unpad(&block).unwrap();
assert_eq!(res, b"test\xff\xff\xff\xff");Note that even though the passed length of the message is equal to 4,
the size of unpadded message is equal to the block size of 8 bytes.
Also padded message contains “garbage” bytes stored in the block buffer.
Thus NoPadding generally should not be used with data length of which
is not multiple of block size.
Trait Implementations§
Source§impl Padding for NoPadding
impl Padding for NoPadding
Source§fn raw_pad(block: &mut [u8], pos: usize)
fn raw_pad(block: &mut [u8], pos: usize)
Pads
block filled with data up to pos (i.e the message length
stored in block is equal to pos). Read moreSource§fn pad_detached<BlockSize: ArraySize>(data: &[u8]) -> PaddedData<'_, BlockSize>
fn pad_detached<BlockSize: ArraySize>(data: &[u8]) -> PaddedData<'_, BlockSize>
Pad message and return padded tail block. Read more
Source§fn unpad_blocks<BlockSize: ArraySize>(
blocks: &[Array<u8, BlockSize>],
) -> Result<&[u8], Error>
fn unpad_blocks<BlockSize: ArraySize>( blocks: &[Array<u8, BlockSize>], ) -> Result<&[u8], Error>
Unpad data in
blocks and return unpadded byte slice. Read moreimpl Copy for NoPadding
Auto Trait Implementations§
impl Freeze for NoPadding
impl RefUnwindSafe for NoPadding
impl Send for NoPadding
impl Sync for NoPadding
impl Unpin for NoPadding
impl UnwindSafe for NoPadding
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more