Skip to main content

Decipher

Struct Decipher 

Source
pub struct Decipher { /* private fields */ }
Expand description

Main AES-CBC Decipher structure.

Usage:

extern crate dumb_crypto;

use::dumb_crypto::aes::BLOCK_SIZE;
use::dumb_crypto::aes_cbc::Decipher;

let iv = [
    0x4c, 0xb4, 0x52, 0xd6, 0x78, 0xca, 0x94, 0x61,
    0x92, 0xcd, 0xc6, 0x91, 0xb7, 0xab, 0x61, 0x76,
];
let key: [u8; 16] = [
    0x69, 0xc2, 0xa9, 0xe6, 0x2b, 0x61, 0x30, 0x60,
    0xc9, 0x79, 0x7b, 0xdc, 0xe4, 0xf6, 0x40, 0x8e,
];
let mut decipher = Decipher::new(iv);
decipher.init(&key).unwrap();

let mut cleartext = decipher.write(&[
    0x98, 0xba, 0x8e, 0x07, 0x5b, 0xcf, 0xa7, 0xb9,
    0x3a, 0xbe, 0x45, 0x3a, 0xb1, 0x84, 0xdc, 0x68,
]).unwrap();
cleartext.append(&mut decipher.flush().unwrap());

Implementations§

Source§

impl Decipher

Source

pub fn new(iv: [u8; 16]) -> Self

Create new instance of AES-CBC Decipher

iv - Initialization Vector (this better be a very random value)

Source

pub fn init(&mut self, key: &[u8]) -> Result<(), AESError>

Initialize instance of AES-CBC Decipher

key - AES Key. Must be either 128, 192, or 256 bits.

Source

pub fn write(&mut self, b: &[u8]) -> Result<Vec<u8>, DecipherError>

Decrypt data

Source

pub fn flush(&mut self) -> Result<Vec<u8>, DecipherError>

Decrypt and return final cleartext data

Auto Trait Implementations§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.