// Copyright (c) Facebook, Inc. and its affiliates. // // This source code is licensed under both the MIT license found in the // LICENSE-MIT file in the root directory of this source tree and the Apache // License, Version 2.0 found in the LICENSE-APACHE file in the root directory // of this source tree. //! A convenience trait for digest bounds used throughout the library use digest::block_buffer::Eager; use digest::core_api::{BlockSizeUser, BufferKindUser, CoreProxy, FixedOutputCore}; use 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 + Default + Clone where ::BlockSize: IsLess, Le<::BlockSize, U256>: NonZero, { } impl + Default + Clone> ProxyHash for T where ::BlockSize: IsLess, Le<::BlockSize, U256>: NonZero, { } /// Trait inheriting the requirements from digest::Digest for compatibility with /// HKDF and HMAC Associated types could be simplified when they are made as /// defaults: pub trait Hash: Default + HashMarker + OutputSizeUser> + BlockSizeUser + FixedOutputReset + CoreProxy + Clone where ::Core: ProxyHash, <::Core as BlockSizeUser>::BlockSize: IsLess, Le<<::Core as BlockSizeUser>::BlockSize, U256>: NonZero, { } impl< T: Default + HashMarker + OutputSizeUser> + BlockSizeUser + FixedOutputReset + CoreProxy + Clone, > Hash for T where ::Core: ProxyHash, <::Core as BlockSizeUser>::BlockSize: IsLess, Le<<::Core as BlockSizeUser>::BlockSize, U256>: NonZero, { }