vitaminc_aead/
cipher.rs

1use crate::{aad::IntoAad, LocalCipherText};
2
3/// An error that provides **no information** about the failure.
4/// It is crucial when returning an error from a cipher operation
5/// that does not reveal any details about the failure as this can lead to side channel attacks.
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub struct Unspecified;
8
9impl std::fmt::Display for Unspecified {
10    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
11        write!(f, "Unspecified error")
12    }
13}
14
15impl std::error::Error for Unspecified {}
16
17pub trait Cipher {
18    fn encrypt_slice<'a, A>(
19        &self,
20        plaintext: &'a [u8],
21        aad: A,
22    ) -> Result<LocalCipherText, Unspecified>
23    where
24        A: IntoAad<'a>;
25
26    fn encrypt_vec<'a, A>(
27        &self,
28        plaintext: Vec<u8>,
29        aad: A,
30    ) -> Result<LocalCipherText, Unspecified>
31    where
32        A: IntoAad<'a>;
33
34    fn decrypt_vec<'a, A>(
35        &self,
36        ciphertext: LocalCipherText,
37        aad: A,
38    ) -> Result<Vec<u8>, Unspecified>
39    where
40        A: IntoAad<'a>;
41}