Enum block_padding::ZeroPadding
source · [−]pub enum ZeroPadding {}
Expand description
Pad block with zeros.
use block_padding::{ZeroPadding, Padding};
let msg = b"test";
let n = msg.len();
let mut buffer = [0xff; 16];
buffer[..n].copy_from_slice(msg);
let padded_msg = ZeroPadding::pad(&mut buffer, n, 8).unwrap();
assert_eq!(padded_msg, b"test\x00\x00\x00\x00");
assert_eq!(ZeroPadding::unpad(&padded_msg).unwrap(), msg);
let padded_msg = ZeroPadding::pad(&mut buffer, n, 2).unwrap();
assert_eq!(padded_msg, b"test");
assert_eq!(ZeroPadding::unpad(&padded_msg).unwrap(), msg);
Note that zero padding may not be reversible if the original message ends with one or more zero bytes.
Trait Implementations
sourceimpl Clone for ZeroPadding
impl Clone for ZeroPadding
sourcefn clone(&self) -> ZeroPadding
fn clone(&self) -> ZeroPadding
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for ZeroPadding
impl Debug for ZeroPadding
sourceimpl Padding for ZeroPadding
impl Padding for ZeroPadding
impl Copy for ZeroPadding
Auto Trait Implementations
impl RefUnwindSafe for ZeroPadding
impl Send for ZeroPadding
impl Sync for ZeroPadding
impl Unpin for ZeroPadding
impl UnwindSafe for ZeroPadding
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more