#![deny(clippy::unwrap_used, clippy::todo, unsafe_code, unused_imports)]
#![doc = include_str!("../README.md")]
mod backend;
mod cipher;
#[cfg(feature = "hlist")]
mod cipher_static;
mod key;
pub use cipher::{Aes256Cipher, OpensVersion1};
pub use key::Key;
pub use vitaminc_aead::seal::Cipher;
#[allow(deprecated)]
pub use vitaminc_aead::Aad;
pub use vitaminc_aead::{
decrypt, decrypt_into, encrypt, CipherText, DecodeError, DecryptError, EncryptError, Node,
};
pub use vitaminc_aead::{Context, IntoAad, IntoContext, LocalCipherText, Nonce, Unspecified};
#[doc(inline)]
pub use vitaminc_aead::{Decrypt, Encrypt};
pub type AesCipherText = Node<LocalCipherText>;
pub fn encrypt_with_key<T>(
key: &Key,
plaintext: T,
) -> Result<AesCipherText, EncryptError<Unspecified>>
where
T: Encrypt,
{
let cipher = Aes256Cipher::new(key).map_err(EncryptError::Cipher)?;
encrypt(plaintext, &cipher, ())
}
pub fn decrypt_with_key<T>(
key: &Key,
ciphertext: AesCipherText,
) -> Result<T, DecryptError<DecodeError, Unspecified>>
where
T: Decrypt,
{
let cipher = Aes256Cipher::new(key).map_err(DecryptError::Cipher)?;
decrypt(&cipher, ciphertext, ())
}