diff --git a/digest/CHANGELOG.md b/digest/CHANGELOG.md index 8af2a4d3..237e7887 100644 --- a/digest/CHANGELOG.md +++ b/digest/CHANGELOG.md @@ -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 diff --git a/digest/src/core_api/ct_variable.rs b/digest/src/core_api/ct_variable.rs index 983f610c..eeb9cd55 100644 --- a/digest/src/core_api/ct_variable.rs +++ b/digest/src/core_api/ct_variable.rs @@ -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, @@ -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 +pub struct CtVariableCoreWrapper where T: VariableOutputCore, OutSize: ArraySize + IsLessOrEqual, LeEq: NonZero, { inner: T, - _out: PhantomData<(OutSize, O)>, + _out: PhantomData, } -impl HashMarker for CtVariableCoreWrapper +impl HashMarker for CtVariableCoreWrapper where T: VariableOutputCore + HashMarker, OutSize: ArraySize + IsLessOrEqual, @@ -46,7 +38,7 @@ where } #[cfg(feature = "mac")] -impl MacMarker for CtVariableCoreWrapper +impl MacMarker for CtVariableCoreWrapper where T: VariableOutputCore + MacMarker, OutSize: ArraySize + IsLessOrEqual, @@ -54,7 +46,7 @@ where { } -impl BlockSizeUser for CtVariableCoreWrapper +impl BlockSizeUser for CtVariableCoreWrapper where T: VariableOutputCore, OutSize: ArraySize + IsLessOrEqual, @@ -63,7 +55,7 @@ where type BlockSize = T::BlockSize; } -impl UpdateCore for CtVariableCoreWrapper +impl UpdateCore for CtVariableCoreWrapper where T: VariableOutputCore, OutSize: ArraySize + IsLessOrEqual, @@ -75,7 +67,7 @@ where } } -impl OutputSizeUser for CtVariableCoreWrapper +impl OutputSizeUser for CtVariableCoreWrapper where T: VariableOutputCore, OutSize: ArraySize + IsLessOrEqual, @@ -84,7 +76,7 @@ where type OutputSize = OutSize; } -impl BufferKindUser for CtVariableCoreWrapper +impl BufferKindUser for CtVariableCoreWrapper where T: VariableOutputCore, OutSize: ArraySize + IsLessOrEqual, @@ -93,7 +85,7 @@ where type BufferKind = T::BufferKind; } -impl FixedOutputCore for CtVariableCoreWrapper +impl FixedOutputCore for CtVariableCoreWrapper where T: VariableOutputCore, OutSize: ArraySize + IsLessOrEqual, @@ -116,7 +108,7 @@ where } } -impl Default for CtVariableCoreWrapper +impl Default for CtVariableCoreWrapper where T: VariableOutputCore, OutSize: ArraySize + IsLessOrEqual, @@ -131,7 +123,7 @@ where } } -impl CustomizedInit for CtVariableCoreWrapper +impl CustomizedInit for CtVariableCoreWrapper where T: VariableOutputCore + VarOutputCustomized, OutSize: ArraySize + IsLessOrEqual, @@ -146,7 +138,7 @@ where } } -impl Reset for CtVariableCoreWrapper +impl Reset for CtVariableCoreWrapper where T: VariableOutputCore, OutSize: ArraySize + IsLessOrEqual, @@ -158,7 +150,7 @@ where } } -impl AlgorithmName for CtVariableCoreWrapper +impl AlgorithmName for CtVariableCoreWrapper where T: VariableOutputCore + AlgorithmName, OutSize: ArraySize + IsLessOrEqual, @@ -171,19 +163,8 @@ where } } -#[cfg(feature = "oid")] -impl AssociatedOid for CtVariableCoreWrapper -where - T: VariableOutputCore, - O: AssociatedOid, - OutSize: ArraySize + IsLessOrEqual, - LeEq: NonZero, -{ - const OID: ObjectIdentifier = O::OID; -} - #[cfg(feature = "zeroize")] -impl zeroize::ZeroizeOnDrop for CtVariableCoreWrapper +impl zeroize::ZeroizeOnDrop for CtVariableCoreWrapper where T: VariableOutputCore + zeroize::ZeroizeOnDrop, OutSize: ArraySize + IsLessOrEqual, @@ -191,7 +172,7 @@ where { } -impl fmt::Debug for CtVariableCoreWrapper +impl fmt::Debug for CtVariableCoreWrapper where T: VariableOutputCore + AlgorithmName, OutSize: ArraySize + IsLessOrEqual, @@ -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 = Sum<::SerializedStateSize, U1>; -impl SerializableState for CtVariableCoreWrapper +impl SerializableState for CtVariableCoreWrapper where T: VariableOutputCore + SerializableState, OutSize: ArraySize + IsLessOrEqual, diff --git a/digest/src/core_api/wrapper.rs b/digest/src/core_api/wrapper.rs index 8d4cf641..6cd006fa 100644 --- a/digest/src/core_api/wrapper.rs +++ b/digest/src/core_api/wrapper.rs @@ -21,8 +21,6 @@ use crypto_common::{ #[cfg(feature = "mac")] use crate::MacMarker; -#[cfg(feature = "oid")] -use const_oid::{AssociatedOid, ObjectIdentifier}; /// Wrapper around [`BufferKindUser`]. /// @@ -171,14 +169,6 @@ where } } -#[cfg(feature = "oid")] -impl AssociatedOid for CoreWrapper -where - T: BufferKindUser + AssociatedOid, -{ - const OID: ObjectIdentifier = T::OID; -} - type CoreWrapperSerializedStateSize = Sum::SerializedStateSize, U1>, ::BlockSize>; diff --git a/digest/src/digest.rs b/digest/src/digest.rs index 1de1ea86..ef084928 100644 --- a/digest/src/digest.rs +++ b/digest/src/digest.rs @@ -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. @@ -228,8 +228,8 @@ impl Clone for Box { } /// 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 DynDigestWithOid for T {} diff --git a/digest/src/lib.rs b/digest/src/lib.rs index e323f364..b0febdf1 100644 --- a/digest/src/lib.rs +++ b/digest/src/lib.rs @@ -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")]