vitaminc_aead/encrypt/mod.rs
1use crate::{cipher::Cipher, Aad, IntoAad};
2pub mod impls;
3
4/// A type that knows how to encrypt itself by driving a [`Cipher`].
5///
6/// Analogous to serde's `Serialize`. Implementations only need to provide
7/// [`encrypt_with_aad`](Encrypt::encrypt_with_aad); [`encrypt`](Encrypt::encrypt)
8/// is a convenience that supplies empty associated data.
9pub trait Encrypt {
10 /// Encrypt `self` with no associated data.
11 fn encrypt<C>(self, cipher: C) -> Result<C::Ok, C::Error>
12 where
13 Self: Sized,
14 C: Cipher,
15 {
16 self.encrypt_with_aad(cipher, Aad::empty())
17 }
18
19 /// Encrypt `self` with the supplied associated data.
20 ///
21 /// This is the method implementations should provide — `encrypt` is just a
22 /// convenience wrapper around it.
23 fn encrypt_with_aad<'a, C, A>(self, cipher: C, aad: A) -> Result<C::Ok, C::Error>
24 where
25 C: Cipher,
26 A: IntoAad<'a>;
27}