use {
crate::{BlockEncrypt, CompressionFn},
docext::docext,
};
#[docext]
#[derive(Debug)]
pub struct DaviesMeyer<Enc, Step> {
enc: Enc,
step: Step,
}
pub trait DaviesMeyerStep {
type State;
fn step(&self, prev: Self::State, new: Self::State) -> Self::State;
}
impl<Enc, Step> DaviesMeyer<Enc, Step> {
pub fn new(enc: Enc, step: Step) -> Self {
Self { enc, step }
}
}
impl<Enc: BlockEncrypt, Step: DaviesMeyerStep<State = Enc::EncryptionBlock>> CompressionFn
for DaviesMeyer<Enc, Step>
where
Enc::EncryptionBlock: Clone,
{
type Block = Enc::EncryptionKey;
type State = Enc::EncryptionBlock;
fn compress(&self, state: Self::State, block: Self::Block) -> Self::State {
self.step
.step(state.clone(), self.enc.encrypt(state, block))
}
}