Struct botan::BlockCipher [−][src]
pub struct BlockCipher { /* fields omitted */ }
A raw block cipher interface (ie ECB mode)
Warning: you almost certainly want an AEAD cipher mode instead
Methods
impl BlockCipher
[src]
impl BlockCipher
pub fn new(name: &str) -> Result<BlockCipher>
[src]
pub fn new(name: &str) -> Result<BlockCipher>
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]
pub fn block_size(&self) -> Result<usize>
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]
pub fn algo_name(&self) -> Result<String>
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]
pub fn key_spec(&self) -> Result<KeySpec>
Return information about the key lengths supported by this object
pub fn set_key(&self, key: &[u8]) -> Result<()>
[src]
pub fn set_key(&self, key: &[u8]) -> Result<()>
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]
pub fn encrypt_blocks(&self, input: &[u8]) -> Result<Vec<u8>>
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 decrypt_blocks(&self, input: &[u8]) -> Result<Vec<u8>>
[src]
pub fn decrypt_blocks(&self, input: &[u8]) -> Result<Vec<u8>>
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 clear(&self) -> Result<()>
[src]
pub fn clear(&self) -> Result<()>
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 Debug for BlockCipher
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl Drop for BlockCipher
[src]
impl Drop for BlockCipher
Auto Trait Implementations
impl !Send for BlockCipher
impl !Send for BlockCipher
impl !Sync for BlockCipher
impl !Sync for BlockCipher