diff --git a/digest/src/block_api.rs b/digest/src/block_api.rs index c0ec6cb2..56dda9cb 100644 --- a/digest/src/block_api.rs +++ b/digest/src/block_api.rs @@ -3,7 +3,7 @@ //! Usage of traits in this module in user code is discouraged. Instead use //! core algorithm wrapped by the wrapper types, which implement the //! higher-level traits. -use crate::InvalidOutputSize; +use crate::{Digest, HashMarker, InvalidOutputSize}; pub use block_buffer::{Eager, Lazy}; pub use crypto_common::{AlgorithmName, Block, BlockSizeUser, OutputSizeUser, Reset}; @@ -30,6 +30,32 @@ pub trait BufferKindUser: BlockSizeUser { type BufferKind: BufferKind; } +/// Trait implemented by eager hashes which expose their block-level core. +pub trait EagerHash: BlockSizeUser + Digest { + /// Block-level core type of the hash. + type Core: HashMarker + + UpdateCore + + FixedOutputCore + + BlockSizeUser::BlockSize> + + BufferKindUser + + Default + + Clone; +} + +impl EagerHash for T +where + T: CoreProxy + BlockSizeUser + Digest, + ::Core: HashMarker + + UpdateCore + + FixedOutputCore + + BlockSizeUser::BlockSize> + + BufferKindUser + + Default + + Clone, +{ + type Core = T::Core; +} + /// Core trait for hash functions with fixed output size. pub trait FixedOutputCore: UpdateCore + BufferKindUser + OutputSizeUser { /// Finalize state using remaining data stored in the provided block buffer,