askar_crypto/encrypt/
mod.rs1use crate::{buffer::ResizeBuffer, error::Error, generic_array::ArrayLength};
4
5#[cfg(feature = "getrandom")]
6use crate::generic_array::GenericArray;
7
8#[cfg(feature = "crypto_box")]
9#[cfg_attr(docsrs, doc(cfg(feature = "crypto_box")))]
10pub mod crypto_box;
11
12pub trait KeyAeadInPlace {
14 fn encrypt_in_place(
17 &self,
18 buffer: &mut dyn ResizeBuffer,
19 nonce: &[u8],
20 aad: &[u8],
21 ) -> Result<usize, Error>;
22
23 fn decrypt_in_place(
25 &self,
26 buffer: &mut dyn ResizeBuffer,
27 nonce: &[u8],
28 aad: &[u8],
29 ) -> Result<(), Error>;
30
31 fn aead_params(&self) -> KeyAeadParams;
33
34 fn aead_padding(&self, _msg_len: usize) -> usize {
36 0
37 }
38}
39
40pub trait KeyAeadMeta {
42 type NonceSize: ArrayLength<u8>;
44 type TagSize: ArrayLength<u8>;
46
47 #[cfg(feature = "getrandom")]
49 fn random_nonce() -> GenericArray<u8, Self::NonceSize> {
50 let mut nonce = GenericArray::default();
51 crate::random::fill_random(nonce.as_mut_slice());
52 nonce
53 }
54}
55
56#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
58pub struct KeyAeadParams {
59 pub nonce_length: usize,
61 pub tag_length: usize,
63}