// SPDX-License-Identifier: MIT OR Apache-2.0 // Copyright (c) VexaHub and contributors. // Copyright (c) Meta Platforms, Inc. and affiliates. //! A convenience trait for digest bounds used throughout the library use digest::block_api::{ BlockSizeUser, BufferKindUser, CoreProxy, FixedOutputCore, SmallBlockSizeUser, }; use digest::block_buffer::Eager; use digest::{Digest, FixedOutputReset, HashMarker, OutputSizeUser}; use generic_array::typenum::{IsLess, Le, NonZero, U256}; pub(crate) type OutputSize = <::Core as OutputSizeUser>::OutputSize; /// Trait to simplify requirements for [`Hash`]. pub trait ProxyHash: HashMarker + FixedOutputCore + BufferKindUser + OutputSizeUser + Default + Clone where ::_BlockSize: IsLess, Le<::_BlockSize, U256>: NonZero, { } impl< T: HashMarker + FixedOutputCore + BufferKindUser + OutputSizeUser + Default + Clone, > ProxyHash for T where ::_BlockSize: IsLess, Le<::_BlockSize, U256>: NonZero, { } /// Trait inheriting the requirements from [`Digest`] for compatibility /// with HKDF and HMAC Associated types could be simplified when they are made /// as defaults: pub trait Hash: Default + HashMarker + Digest + OutputSizeUser> + BlockSizeUser + FixedOutputReset + CoreProxy + Clone where ::Core: ProxyHash, <::Core as SmallBlockSizeUser>::_BlockSize: IsLess, Le<<::Core as SmallBlockSizeUser>::_BlockSize, U256>: NonZero, OutputSize: generic_array::ArrayLength, { } impl< T: Default + HashMarker + Digest + OutputSizeUser> + BlockSizeUser + FixedOutputReset + CoreProxy + Clone, > Hash for T where ::Core: ProxyHash, <::Core as SmallBlockSizeUser>::_BlockSize: IsLess, Le<<::Core as SmallBlockSizeUser>::_BlockSize, U256>: NonZero, OutputSize: generic_array::ArrayLength, { }