1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use crate::aead::Aead;
use aead::{AeadCore as BaseAeadCore, AeadInPlace as BaseAeadInPlace, NewAead as BaseNewAead};
use generic_array::typenum;
#[doc(hidden)]
#[derive(Clone)]
pub struct EmptyAeadImpl;
impl BaseAeadCore for EmptyAeadImpl {
type NonceSize = typenum::U128;
type TagSize = typenum::U0;
type CiphertextOverhead = typenum::U0;
}
impl BaseAeadInPlace for EmptyAeadImpl {
fn encrypt_in_place_detached(
&self,
_: &aead::Nonce<Self>,
_: &[u8],
_: &mut [u8],
) -> Result<aead::Tag<Self>, aead::Error> {
panic!("Cannot encrypt with an export-only encryption context!");
}
fn decrypt_in_place_detached(
&self,
_: &aead::Nonce<Self>,
_: &[u8],
_: &mut [u8],
_: &aead::Tag<Self>,
) -> Result<(), aead::Error> {
panic!("Cannot decrypt with an export-only encryption context!");
}
}
impl BaseNewAead for EmptyAeadImpl {
type KeySize = typenum::U0;
fn new(_: &aead::Key<Self>) -> Self {
EmptyAeadImpl
}
}
pub struct ExportOnlyAead;
impl Aead for ExportOnlyAead {
type AeadImpl = EmptyAeadImpl;
const AEAD_ID: u16 = 0xFFFF;
}