use crate::aead::Aead;
use aead::{
AeadCore as BaseAeadCore, AeadInPlace as BaseAeadInPlace, KeyInit as BaseKeyInit,
KeySizeUser as BaseKeySizeUser,
};
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 BaseKeySizeUser for EmptyAeadImpl {
type KeySize = typenum::U0;
}
impl BaseKeyInit for EmptyAeadImpl {
fn new(_: &aead::Key<Self>) -> Self {
EmptyAeadImpl
}
}
pub struct ExportOnlyAead;
impl Aead for ExportOnlyAead {
type AeadImpl = EmptyAeadImpl;
const AEAD_ID: u16 = 0xFFFF;
}