Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion digest/src/block_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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 = <Self as BlockSizeUser>::BlockSize>
+ BufferKindUser<BufferKind = Eager>
+ Default
+ Clone;
}

impl<T> EagerHash for T
where
T: CoreProxy + BlockSizeUser + Digest,
<T as CoreProxy>::Core: HashMarker
+ UpdateCore
+ FixedOutputCore
+ BlockSizeUser<BlockSize = <Self as BlockSizeUser>::BlockSize>
+ BufferKindUser<BufferKind = Eager>
+ 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,
Expand Down