extern crate keybob;
mod derivation {
use keybob::{Key, KeyType};
#[test]
fn basic_128() {
let k1 = Key::from_pw(KeyType::Aes128, "123456789", "spacekookie");
let k2 = Key::from_pw(KeyType::Aes128, "123456789", "spacekookie");
assert_eq!(k1, k2);
}
#[test]
fn basic_256() {
let k1 = Key::from_pw(KeyType::Aes256, "123456789", "spacekookie");
let k2 = Key::from_pw(KeyType::Aes256, "123456789", "spacekookie");
assert_eq!(k1, k2);
}
#[test]
fn colliding_pw_128() {
let k1 = Key::from_pw(KeyType::Aes128, "123456789", "spacekookie");
let k2 = Key::from_pw(KeyType::Aes128, "123456789", "bob");
assert!(k1 != k2);
}
#[test]
fn colliding_pw_256() {
let k1 = Key::from_pw(KeyType::Aes256, "123456789", "spacekookie");
let k2 = Key::from_pw(KeyType::Aes256, "123456789", "bob");
assert!(k1 != k2);
}
}
mod workflow {
use keybob::{Key, KeyType};
extern crate miscreant;
#[test]
fn miscreant() {
use workflow::miscreant::aead::{Aes256Siv, Algorithm};
let key = Key::new(KeyType::Aes256);
let mut aes: Aes256Siv = Aes256Siv::new(key.as_slice());
let iv = Key::new(KeyType::Aes256);
let nonce = Key::new(KeyType::Aes256);
let data_in = "This is a message!";
let encrypted = aes.seal(nonce.as_slice(), iv.as_slice(), data_in.as_bytes());
let decrypted = aes
.open(nonce.as_slice(), iv.as_slice(), encrypted.as_slice())
.unwrap();
let data_out = ::std::str::from_utf8(&decrypted.as_slice()).unwrap();
assert_eq!(data_in, data_out);
}
#[test]
fn printers() {
let k1 = Key::from_pw(KeyType::Aes128, "192837465", "jane");
assert_eq!(&format!("{:?}", k1), "Key: type: Aes128 – \"Mvd0jg==\"");
}
}