Struct botan::Cipher[][src]

pub struct Cipher { /* fields omitted */ }

A symmetric cipher

Methods

impl Cipher
[src]

Create a new cipher object in the specified direction

Examples

let aes_gcm = botan::Cipher::new("AES-128/GCM", botan::CipherDirection::Encrypt).unwrap();

Return the name of this algorithm which may or may not exactly match what was provided to new()

Examples

let cipher = botan::Cipher::new("AES-128/GCM", botan::CipherDirection::Encrypt).unwrap();
assert_eq!(cipher.algo_name().unwrap(), "AES-128/GCM(16)");

Return the direction this cipher object is operating in

Examples

let cipher = botan::Cipher::new("AES-128/GCM", botan::CipherDirection::Encrypt).unwrap();
assert_eq!(cipher.direction().unwrap(), botan::CipherDirection::Encrypt);

Query if a particular nonce size is valid for this cipher

Examples

let aes_cbc = botan::Cipher::new("AES-128/CBC", botan::CipherDirection::Encrypt).unwrap();
assert_eq!(aes_cbc.valid_nonce_length(16), Ok(true));
assert_eq!(aes_cbc.valid_nonce_length(1), Ok(false));

For an AEAD, return the tag length of the cipher

Examples

let aes_cbc = botan::Cipher::new("AES-128/CBC", botan::CipherDirection::Encrypt).unwrap();
assert_eq!(aes_cbc.tag_length(), 0);
let aes_gcm = botan::Cipher::new("AES-128/GCM", botan::CipherDirection::Encrypt).unwrap();
assert_eq!(aes_gcm.tag_length(), 16);

Return the default nonce length for the cipher. Some ciphers only support a single nonce size. Others support variable sizes, but some particular size (typically 96 bits) is handled particularly efficiently.

Examples

let aes_gcm = botan::Cipher::new("AES-128/GCM", botan::CipherDirection::Encrypt).unwrap();
assert_eq!(aes_gcm.default_nonce_length(), 12);

Return information about the key lengths supported by this object

Set the key for the cipher

Examples

let aes_gcm = botan::Cipher::new("AES-128/GCM", botan::CipherDirection::Encrypt).unwrap();
aes_gcm.set_key(&vec![0; 16]).unwrap();

Set the associated data for the cipher. This only works for AEAD modes. The key must already be set to set the AD.

Examples

let aes_gcm = botan::Cipher::new("AES-128/GCM", botan::CipherDirection::Encrypt).unwrap();
aes_gcm.set_key(&vec![0; 16]).unwrap();
aes_gcm.set_associated_data(&[1,2,3]).unwrap();

Encrypt or decrypt a message with the provided nonce. The key must already have been set.

Examples

let aes_gcm = botan::Cipher::new("AES-128/GCM", botan::CipherDirection::Encrypt).unwrap();
aes_gcm.set_key(&vec![0; 16]).unwrap();
let nonce = vec![0; aes_gcm.default_nonce_length()];
let msg = vec![0; 48];
let ctext = aes_gcm.process(&nonce, &msg);

Clear all state associated with the key

Trait Implementations

impl Debug for Cipher
[src]

Formats the value using the given formatter. Read more

impl Drop for Cipher
[src]

Executes the destructor for this type. Read more

Auto Trait Implementations

impl !Send for Cipher

impl !Sync for Cipher