Skip to content

digest: remove AssociatedOid blanket impls for wrappers #1810

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion digest/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Removed
- `Mac::new`, `Mac::new_from_slice`, and `Mac::generate_key` methods ([#1173])
- `HashReader` and `HashWriter` are moved to the `digest-io` crate ([#1809])
- Removed `io::Write/Read` implementations in favor of the `digest_io::IoWrapper` type ([#1809])
- `io::Write/Read` implementations in favor of the `digest_io::IoWrapper` type ([#1809])
- `AssociatedOid` blanket impls for `CoreWrapper` and `CtVariableCoreWrapper` ([#1810])
- `impl_oid_carrier!` macro ([#1810])

[#1173]: https://github.com/RustCrypto/traits/pull/1173
[#1334]: https://github.com/RustCrypto/traits/pull/1334
[#1759]: https://github.com/RustCrypto/traits/pull/1759
[#1809]: https://github.com/RustCrypto/traits/pull/1809
[#1810]: https://github.com/RustCrypto/traits/pull/1810

## 0.10.7 (2023-05-19)
### Changed
Expand Down
67 changes: 16 additions & 51 deletions digest/src/core_api/ct_variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ use super::{
#[cfg(feature = "mac")]
use crate::MacMarker;
use crate::{CustomizedInit, HashMarker, VarOutputCustomized};
#[cfg(feature = "oid")]
use const_oid::{AssociatedOid, ObjectIdentifier};
use core::{
fmt,
marker::PhantomData,
Expand All @@ -18,26 +16,20 @@ use crypto_common::{
hazmat::{DeserializeStateError, SerializableState, SerializedState, SubSerializedStateSize},
typenum::{IsLess, IsLessOrEqual, Le, LeEq, NonZero, Sum, U1, U256},
};

/// Dummy type used with [`CtVariableCoreWrapper`] in cases when
/// resulting hash does not have a known OID.
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub struct NoOid;

/// Wrapper around [`VariableOutputCore`] which selects output size
/// at compile time.
#[derive(Clone)]
pub struct CtVariableCoreWrapper<T, OutSize, O = NoOid>
pub struct CtVariableCoreWrapper<T, OutSize>
where
T: VariableOutputCore,
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
LeEq<OutSize, T::OutputSize>: NonZero,
{
inner: T,
_out: PhantomData<(OutSize, O)>,
_out: PhantomData<OutSize>,
}

impl<T, OutSize, O> HashMarker for CtVariableCoreWrapper<T, OutSize, O>
impl<T, OutSize> HashMarker for CtVariableCoreWrapper<T, OutSize>
where
T: VariableOutputCore + HashMarker,
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
Expand All @@ -46,15 +38,15 @@ where
}

#[cfg(feature = "mac")]
impl<T, OutSize, O> MacMarker for CtVariableCoreWrapper<T, OutSize, O>
impl<T, OutSize> MacMarker for CtVariableCoreWrapper<T, OutSize>
where
T: VariableOutputCore + MacMarker,
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
LeEq<OutSize, T::OutputSize>: NonZero,
{
}

impl<T, OutSize, O> BlockSizeUser for CtVariableCoreWrapper<T, OutSize, O>
impl<T, OutSize> BlockSizeUser for CtVariableCoreWrapper<T, OutSize>
where
T: VariableOutputCore,
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
Expand All @@ -63,7 +55,7 @@ where
type BlockSize = T::BlockSize;
}

impl<T, OutSize, O> UpdateCore for CtVariableCoreWrapper<T, OutSize, O>
impl<T, OutSize> UpdateCore for CtVariableCoreWrapper<T, OutSize>
where
T: VariableOutputCore,
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
Expand All @@ -75,7 +67,7 @@ where
}
}

impl<T, OutSize, O> OutputSizeUser for CtVariableCoreWrapper<T, OutSize, O>
impl<T, OutSize> OutputSizeUser for CtVariableCoreWrapper<T, OutSize>
where
T: VariableOutputCore,
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
Expand All @@ -84,7 +76,7 @@ where
type OutputSize = OutSize;
}

impl<T, OutSize, O> BufferKindUser for CtVariableCoreWrapper<T, OutSize, O>
impl<T, OutSize> BufferKindUser for CtVariableCoreWrapper<T, OutSize>
where
T: VariableOutputCore,
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
Expand All @@ -93,7 +85,7 @@ where
type BufferKind = T::BufferKind;
}

impl<T, OutSize, O> FixedOutputCore for CtVariableCoreWrapper<T, OutSize, O>
impl<T, OutSize> FixedOutputCore for CtVariableCoreWrapper<T, OutSize>
where
T: VariableOutputCore,
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
Expand All @@ -116,7 +108,7 @@ where
}
}

impl<T, OutSize, O> Default for CtVariableCoreWrapper<T, OutSize, O>
impl<T, OutSize> Default for CtVariableCoreWrapper<T, OutSize>
where
T: VariableOutputCore,
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
Expand All @@ -131,7 +123,7 @@ where
}
}

impl<T, OutSize, O> CustomizedInit for CtVariableCoreWrapper<T, OutSize, O>
impl<T, OutSize> CustomizedInit for CtVariableCoreWrapper<T, OutSize>
where
T: VariableOutputCore + VarOutputCustomized,
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
Expand All @@ -146,7 +138,7 @@ where
}
}

impl<T, OutSize, O> Reset for CtVariableCoreWrapper<T, OutSize, O>
impl<T, OutSize> Reset for CtVariableCoreWrapper<T, OutSize>
where
T: VariableOutputCore,
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
Expand All @@ -158,7 +150,7 @@ where
}
}

impl<T, OutSize, O> AlgorithmName for CtVariableCoreWrapper<T, OutSize, O>
impl<T, OutSize> AlgorithmName for CtVariableCoreWrapper<T, OutSize>
where
T: VariableOutputCore + AlgorithmName,
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
Expand All @@ -171,27 +163,16 @@ where
}
}

#[cfg(feature = "oid")]
impl<T, OutSize, O> AssociatedOid for CtVariableCoreWrapper<T, OutSize, O>
where
T: VariableOutputCore,
O: AssociatedOid,
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
LeEq<OutSize, T::OutputSize>: NonZero,
{
const OID: ObjectIdentifier = O::OID;
}

#[cfg(feature = "zeroize")]
impl<T, OutSize, O> zeroize::ZeroizeOnDrop for CtVariableCoreWrapper<T, OutSize, O>
impl<T, OutSize> zeroize::ZeroizeOnDrop for CtVariableCoreWrapper<T, OutSize>
where
T: VariableOutputCore + zeroize::ZeroizeOnDrop,
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
LeEq<OutSize, T::OutputSize>: NonZero,
{
}

impl<T, OutSize, O> fmt::Debug for CtVariableCoreWrapper<T, OutSize, O>
impl<T, OutSize> fmt::Debug for CtVariableCoreWrapper<T, OutSize>
where
T: VariableOutputCore + AlgorithmName,
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
Expand All @@ -202,26 +183,10 @@ where
}
}

/// Implement dummy type with hidden docs which is used to "carry" hasher
/// OID for [`CtVariableCoreWrapper`].
#[macro_export]
macro_rules! impl_oid_carrier {
($name:ident, $oid:literal) => {
#[doc(hidden)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub struct $name;

#[cfg(feature = "oid")]
impl AssociatedOid for $name {
const OID: ObjectIdentifier = ObjectIdentifier::new_unwrap($oid);
}
};
}

type CtVariableCoreWrapperSerializedStateSize<T> =
Sum<<T as SerializableState>::SerializedStateSize, U1>;

impl<T, OutSize, O> SerializableState for CtVariableCoreWrapper<T, OutSize, O>
impl<T, OutSize> SerializableState for CtVariableCoreWrapper<T, OutSize>
where
T: VariableOutputCore + SerializableState,
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
Expand Down
10 changes: 0 additions & 10 deletions digest/src/core_api/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ use crypto_common::{

#[cfg(feature = "mac")]
use crate::MacMarker;
#[cfg(feature = "oid")]
use const_oid::{AssociatedOid, ObjectIdentifier};

/// Wrapper around [`BufferKindUser`].
///
Expand Down Expand Up @@ -171,14 +169,6 @@ where
}
}

#[cfg(feature = "oid")]
impl<T> AssociatedOid for CoreWrapper<T>
where
T: BufferKindUser + AssociatedOid,
{
const OID: ObjectIdentifier = T::OID;
}

type CoreWrapperSerializedStateSize<T> =
Sum<Sum<<T as SerializableState>::SerializedStateSize, U1>, <T as BlockSizeUser>::BlockSize>;

Expand Down
6 changes: 3 additions & 3 deletions digest/src/digest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crypto_common::{Output, OutputSizeUser, typenum::Unsigned};

#[cfg(feature = "alloc")]
use alloc::boxed::Box;
#[cfg(feature = "const-oid")]
#[cfg(feature = "oid")]
use const_oid::DynAssociatedOid;

/// Marker trait for cryptographic hash functions.
Expand Down Expand Up @@ -228,8 +228,8 @@ impl Clone for Box<dyn DynDigest> {
}

/// Convenience wrapper trait around [DynDigest] and [DynAssociatedOid].
#[cfg(feature = "const-oid")]
#[cfg(feature = "oid")]
pub trait DynDigestWithOid: DynDigest + DynAssociatedOid {}

#[cfg(feature = "const-oid")]
#[cfg(feature = "oid")]
impl<T: DynDigest + DynAssociatedOid> DynDigestWithOid for T {}
2 changes: 1 addition & 1 deletion digest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub use block_buffer;
pub use const_oid;
pub use crypto_common;

#[cfg(feature = "const-oid")]
#[cfg(feature = "oid")]
pub use crate::digest::DynDigestWithOid;
pub use crate::digest::{Digest, DynDigest, HashMarker};
#[cfg(feature = "mac")]
Expand Down