Struct botan::BlockCipher [−][src]
A raw block cipher interface (ie ECB mode)
Warning: you almost certainly want an AEAD cipher mode instead
Implementations
impl BlockCipher
[src]
pub fn new(name: &str) -> Result<BlockCipher>
[src]
Create a new block cipher instance, failing if the cipher is unknown
Examples
let cipher = botan::BlockCipher::new("AES-128"); assert!(cipher.is_ok()); let no_such_cipher = botan::BlockCipher::new("SuperCipher9000"); assert!(no_such_cipher.is_err());
pub fn block_size(&self) -> Result<usize>
[src]
Return the block size of the cipher, in bytes
Examples
let cipher = botan::BlockCipher::new("AES-128").unwrap(); assert_eq!(cipher.block_size().unwrap(), 16);
pub fn algo_name(&self) -> Result<String>
[src]
Return the name of this algorithm which may or may not exactly match what was provided to new()
Examples
let cipher = botan::BlockCipher::new("AES-128").unwrap(); assert_eq!(cipher.algo_name().unwrap(), "AES-128");
pub fn key_spec(&self) -> Result<KeySpec>
[src]
Return information about the key lengths supported by this object
pub fn set_key(&self, key: &[u8]) -> Result<()>
[src]
Set the key for the cipher.
Errors
Fails if the key is not a valid length for the cipher
Examples
let cipher = botan::BlockCipher::new("AES-128").unwrap(); assert!(cipher.set_key(&vec![0; 32]).is_err()); assert!(cipher.set_key(&vec![0; 16]).is_ok());
pub fn encrypt_blocks(&self, input: &[u8]) -> Result<Vec<u8>>
[src]
Encrypt some blocks of data
Errors
Fails if the input is not a multiple of the block size, or if the key was not set on the object.
Examples
let cipher = botan::BlockCipher::new("AES-128").unwrap(); // Key is not set assert!(cipher.encrypt_blocks(&vec![0; 16]).is_err()); assert!(cipher.set_key(&vec![0; 16]).is_ok()); // Not a multiple of block size assert!(cipher.encrypt_blocks(&vec![0; 17]).is_err()); // Key is set and multiple of block size - ok assert!(cipher.encrypt_blocks(&vec![0; 16]).is_ok());
pub fn encrypt_in_place(&self, buf: &mut [u8]) -> Result<()>
[src]
Encrypt in place
pub fn decrypt_blocks(&self, input: &[u8]) -> Result<Vec<u8>>
[src]
Decrypt some blocks of data
Errors
Fails if the input is not a multiple of the block size, or if the key was not set on the object.
Examples
let cipher = botan::BlockCipher::new("AES-128").unwrap(); // Key is not set assert!(cipher.decrypt_blocks(&vec![0; 16]).is_err()); assert!(cipher.set_key(&vec![0; 16]).is_ok()); // Not a multiple of block size assert!(cipher.decrypt_blocks(&vec![0; 17]).is_err()); // Key is set and multiple of block size - ok assert!(cipher.decrypt_blocks(&vec![0; 16]).is_ok());
pub fn decrypt_in_place(&self, buf: &mut [u8]) -> Result<()>
[src]
Decrypt in place
pub fn clear(&self) -> Result<()>
[src]
Clear the key set on the cipher from memory. After this, the object is un-keyed and must be re-keyed before use.
Examples
let cipher = botan::BlockCipher::new("AES-128").unwrap(); assert!(cipher.set_key(&vec![0; 16]).is_ok()); assert!(cipher.encrypt_blocks(&vec![0; 16]).is_ok()); assert!(cipher.clear().is_ok()); assert!(cipher.encrypt_blocks(&vec![0; 16]).is_err());
Trait Implementations
impl Debug for BlockCipher
[src]
impl Drop for BlockCipher
[src]
Auto Trait Implementations
impl RefUnwindSafe for BlockCipher
impl !Send for BlockCipher
impl !Sync for BlockCipher
impl Unpin for BlockCipher
impl UnwindSafe for BlockCipher
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,