Files
opaque-vx/src/hash.rs
T

76 lines
2.3 KiB
Rust
Raw Normal View History

// SPDX-License-Identifier: MIT OR Apache-2.0
// Copyright (c) VexaHub and contributors.
2023-05-22 23:04:26 -07:00
// Copyright (c) Meta Platforms, Inc. and affiliates.
2020-07-27 15:25:04 -07:00
2020-10-21 18:20:43 -04:00
//! A convenience trait for digest bounds used throughout the library
use digest::block_api::{
BlockSizeUser, BufferKindUser, CoreProxy, FixedOutputCore, SmallBlockSizeUser,
};
2022-01-06 00:10:57 +01:00
use digest::block_buffer::Eager;
use digest::{Digest, FixedOutputReset, HashMarker, OutputSizeUser};
2022-01-06 00:10:57 +01:00
use generic_array::typenum::{IsLess, Le, NonZero, U256};
2025-05-19 22:56:25 +02:00
pub(crate) type OutputSize<H> = <<H as CoreProxy>::Core as OutputSizeUser>::OutputSize;
2022-01-06 00:10:57 +01:00
/// Trait to simplify requirements for [`Hash`].
pub trait ProxyHash:
HashMarker + FixedOutputCore + BufferKindUser<BufferKind = Eager> + OutputSizeUser + Default + Clone
2022-01-06 00:10:57 +01:00
where
<Self as SmallBlockSizeUser>::_BlockSize: IsLess<U256>,
Le<<Self as SmallBlockSizeUser>::_BlockSize, U256>: NonZero,
2022-01-06 00:10:57 +01:00
{
}
impl<
T: HashMarker
+ FixedOutputCore
+ BufferKindUser<BufferKind = Eager>
+ OutputSizeUser
+ Default
+ Clone,
> ProxyHash for T
2022-01-06 00:10:57 +01:00
where
<T as SmallBlockSizeUser>::_BlockSize: IsLess<U256>,
Le<<T as SmallBlockSizeUser>::_BlockSize, U256>: NonZero,
2022-01-06 00:10:57 +01:00
{
}
2020-07-27 15:25:04 -07:00
/// Trait inheriting the requirements from [`Digest`] for compatibility
2023-10-08 21:48:43 +02:00
/// with HKDF and HMAC Associated types could be simplified when they are made
/// as defaults: <https://github.com/rust-lang/rust/issues/29661>
2022-01-06 00:10:57 +01:00
pub trait Hash:
2023-03-05 05:31:07 +01:00
Default
+ HashMarker
+ Digest
2022-01-06 00:10:57 +01:00
+ OutputSizeUser<OutputSize = OutputSize<Self>>
+ BlockSizeUser
+ FixedOutputReset
+ CoreProxy
+ Clone
where
<Self as CoreProxy>::Core: ProxyHash,
<<Self as CoreProxy>::Core as SmallBlockSizeUser>::_BlockSize: IsLess<U256>,
Le<<<Self as CoreProxy>::Core as SmallBlockSizeUser>::_BlockSize, U256>: NonZero,
OutputSize<Self>: generic_array::ArrayLength,
2022-01-06 00:10:57 +01:00
{
}
2020-07-27 15:25:04 -07:00
2022-01-06 00:10:57 +01:00
impl<
T: Default
+ HashMarker
+ Digest
+ OutputSizeUser<OutputSize = OutputSize<Self>>
+ BlockSizeUser
+ FixedOutputReset
+ CoreProxy
+ Clone,
> Hash for T
2022-01-06 00:10:57 +01:00
where
<T as CoreProxy>::Core: ProxyHash,
<<T as CoreProxy>::Core as SmallBlockSizeUser>::_BlockSize: IsLess<U256>,
Le<<<T as CoreProxy>::Core as SmallBlockSizeUser>::_BlockSize, U256>: NonZero,
OutputSize<T>: generic_array::ArrayLength,
2022-01-06 00:10:57 +01:00
{
}