Skip to main content

Cipher

Struct Cipher 

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

Main AES-CBC Cipher structure.

Usage:

extern crate dumb_crypto;

use::dumb_crypto::aes::BLOCK_SIZE;
use::dumb_crypto::aes_cbc::Cipher;

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 cipher = Cipher::new(iv);
cipher.init(&key).unwrap();

let mut ciphertext = cipher.write("aes-cbc with iv".as_bytes()).unwrap();
ciphertext.append(&mut cipher.flush().unwrap());

Implementations§

Source§

impl Cipher

Source

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

Create new instance of AES-CBC Cipher

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 Cipher

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

Source

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

Encrypt data

Source

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

Encrypt and return final cipher block

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.