use crate::{Digest, HashMarker, InvalidOutputSize};
pub use block_buffer::{Eager, Lazy};
pub use common::{AlgorithmName, Block, BlockSizeUser, OutputSizeUser, Reset};
use block_buffer::{BlockBuffer, BlockSizes, BufferKind};
use common::Output;
mod ct_variable;
pub use ct_variable::CtOutWrapper;
pub type Buffer<S> =
BlockBuffer<<S as BlockSizeUser>::BlockSize, <S as BufferKindUser>::BufferKind>;
pub trait UpdateCore: BlockSizeUser {
fn update_blocks(&mut self, blocks: &[Block<Self>]);
}
pub trait SmallBlockSizeUser:
BlockSizeUser<BlockSize = <Self as SmallBlockSizeUser>::_BlockSize>
{
type _BlockSize: BlockSizes;
}
impl<T: BlockSizeUser> SmallBlockSizeUser for T
where
T::BlockSize: BlockSizes,
{
type _BlockSize = T::BlockSize;
}
pub trait BufferKindUser: SmallBlockSizeUser {
type BufferKind: BufferKind;
}
pub trait EagerHash: SmallBlockSizeUser + Digest + Clone {
type Core: HashMarker
+ UpdateCore
+ FixedOutputCore
+ SmallBlockSizeUser<_BlockSize = <Self as SmallBlockSizeUser>::_BlockSize>
+ BufferKindUser<BufferKind = Eager>
+ Default
+ Clone;
}
impl<T> EagerHash for T
where
T: CoreProxy + SmallBlockSizeUser + Digest + Clone,
<T as CoreProxy>::Core: HashMarker
+ UpdateCore
+ FixedOutputCore
+ SmallBlockSizeUser<_BlockSize = <T as SmallBlockSizeUser>::_BlockSize>
+ BufferKindUser<BufferKind = Eager>
+ Default
+ Clone,
{
type Core = T::Core;
}
pub trait FixedOutputCore: UpdateCore + BufferKindUser + OutputSizeUser {
fn finalize_fixed_core(&mut self, buffer: &mut Buffer<Self>, out: &mut Output<Self>);
}
pub trait ExtendableOutputCore: UpdateCore + BufferKindUser {
type ReaderCore: XofReaderCore;
fn finalize_xof_core(&mut self, buffer: &mut Buffer<Self>) -> Self::ReaderCore;
}
pub trait XofReaderCore: BlockSizeUser {
fn read_block(&mut self) -> Block<Self>;
}
pub trait VariableOutputCore: UpdateCore + OutputSizeUser + BufferKindUser + Sized {
const TRUNC_SIDE: TruncSide;
fn new(output_size: usize) -> Result<Self, InvalidOutputSize>;
fn finalize_variable_core(&mut self, buffer: &mut Buffer<Self>, out: &mut Output<Self>);
}
pub trait VariableOutputCoreCustomized: VariableOutputCore {
fn new_customized(customization: &[u8], output_size: usize) -> Self;
}
#[derive(Copy, Clone, Debug)]
pub enum TruncSide {
Left,
Right,
}
pub trait CoreProxy {
type Core: BufferKindUser;
fn compose(core: Self::Core, buffer: Buffer<Self::Core>) -> Self;
fn decompose(self) -> (Self::Core, Buffer<Self::Core>);
}