use seal_crypto_wrapper::error::Result;
use seal_crypto_wrapper::prelude::*;
fn main() -> Result<()> {
let algorithm = AeadAlgorithm::build().aes256_gcm();
println!("Selected aead algorithm: {:?}", algorithm);
let cipher = algorithm.into_wrapper();
println!("Got aead cipher wrapper.");
let key = cipher.generate_typed_key()?;
println!("Generated key.");
let nonce = vec![0u8; cipher.nonce_size()];
println!("Created nonce.");
let plaintext = b"This is a secret message.";
let aad = b"Authenticated but not encrypted data.";
println!("Plaintext: {:?}", String::from_utf8_lossy(plaintext));
println!("AAD: {:?}", String::from_utf8_lossy(aad));
let ciphertext = cipher.encrypt(plaintext, &key, &nonce, Some(aad))?;
println!("Encrypted plaintext.");
let decrypted_plaintext = cipher.decrypt(&ciphertext, &key, &nonce, Some(aad))?;
println!("Decrypted ciphertext.");
assert_eq!(plaintext.as_ref(), decrypted_plaintext.as_slice());
println!("Successfully verified that the decrypted plaintext matches the original!");
Ok(())
}