logo
pub struct NoPadding;
Expand description

Don’t pad the data. Useful for key wrapping.

use block_padding::{NoPadding, Padding};
use generic_array::{GenericArray, typenum::U8};

let msg = b"test";
let pos = msg.len();
let mut block: GenericArray::<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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Padding type

Pads block filled with data up to pos (i.e length of a message stored in the block is equal to pos). Read more

Unpad data in the block. Read more

Unpad data in the blocks. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Should always be Self

The resulting type after obtaining ownership.

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

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.