diff --git a/digest/CHANGELOG.md b/digest/CHANGELOG.md index 237e7887b..431816c5e 100644 --- a/digest/CHANGELOG.md +++ b/digest/CHANGELOG.md @@ -17,14 +17,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `Mac::new`, `Mac::new_from_slice`, and `Mac::generate_key` methods ([#1173]) - `HashReader` and `HashWriter` are moved to the `digest-io` crate ([#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 d8ad3e8ca..93ff2f96a 100644 --- a/digest/src/core_api/ct_variable.rs +++ b/digest/src/core_api/ct_variable.rs @@ -5,6 +5,8 @@ use super::{ #[cfg(feature = "mac")] use crate::MacMarker; use crate::{CollisionResistance, CustomizedInit, HashMarker, VarOutputCustomized}; +#[cfg(feature = "oid")] +use const_oid::{AssociatedOid, ObjectIdentifier}; use core::{ fmt, marker::PhantomData, @@ -16,20 +18,26 @@ 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, + _out: PhantomData<(OutSize, O)>, } -impl HashMarker for CtVariableCoreWrapper +impl HashMarker for CtVariableCoreWrapper where T: VariableOutputCore + HashMarker, OutSize: ArraySize + IsLessOrEqual, @@ -38,7 +46,7 @@ where } #[cfg(feature = "mac")] -impl MacMarker for CtVariableCoreWrapper +impl MacMarker for CtVariableCoreWrapper where T: VariableOutputCore + MacMarker, OutSize: ArraySize + IsLessOrEqual, @@ -55,7 +63,7 @@ where type CollisionResistance = T::CollisionResistance; } -impl BlockSizeUser for CtVariableCoreWrapper +impl BlockSizeUser for CtVariableCoreWrapper where T: VariableOutputCore, OutSize: ArraySize + IsLessOrEqual, @@ -64,7 +72,7 @@ where type BlockSize = T::BlockSize; } -impl UpdateCore for CtVariableCoreWrapper +impl UpdateCore for CtVariableCoreWrapper where T: VariableOutputCore, OutSize: ArraySize + IsLessOrEqual, @@ -76,7 +84,7 @@ where } } -impl OutputSizeUser for CtVariableCoreWrapper +impl OutputSizeUser for CtVariableCoreWrapper where T: VariableOutputCore, OutSize: ArraySize + IsLessOrEqual, @@ -85,7 +93,7 @@ where type OutputSize = OutSize; } -impl BufferKindUser for CtVariableCoreWrapper +impl BufferKindUser for CtVariableCoreWrapper where T: VariableOutputCore, OutSize: ArraySize + IsLessOrEqual, @@ -94,7 +102,7 @@ where type BufferKind = T::BufferKind; } -impl FixedOutputCore for CtVariableCoreWrapper +impl FixedOutputCore for CtVariableCoreWrapper where T: VariableOutputCore, OutSize: ArraySize + IsLessOrEqual, @@ -117,7 +125,7 @@ where } } -impl Default for CtVariableCoreWrapper +impl Default for CtVariableCoreWrapper where T: VariableOutputCore, OutSize: ArraySize + IsLessOrEqual, @@ -132,7 +140,7 @@ where } } -impl CustomizedInit for CtVariableCoreWrapper +impl CustomizedInit for CtVariableCoreWrapper where T: VariableOutputCore + VarOutputCustomized, OutSize: ArraySize + IsLessOrEqual, @@ -147,7 +155,7 @@ where } } -impl Reset for CtVariableCoreWrapper +impl Reset for CtVariableCoreWrapper where T: VariableOutputCore, OutSize: ArraySize + IsLessOrEqual, @@ -159,7 +167,7 @@ where } } -impl AlgorithmName for CtVariableCoreWrapper +impl AlgorithmName for CtVariableCoreWrapper where T: VariableOutputCore + AlgorithmName, OutSize: ArraySize + IsLessOrEqual, @@ -172,8 +180,19 @@ 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, @@ -181,7 +200,7 @@ where { } -impl fmt::Debug for CtVariableCoreWrapper +impl fmt::Debug for CtVariableCoreWrapper where T: VariableOutputCore + AlgorithmName, OutSize: ArraySize + IsLessOrEqual, @@ -192,10 +211,26 @@ 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 242871772..c7368d8a2 100644 --- a/digest/src/core_api/wrapper.rs +++ b/digest/src/core_api/wrapper.rs @@ -21,6 +21,8 @@ use crypto_common::{ #[cfg(feature = "mac")] use crate::MacMarker; +#[cfg(feature = "oid")] +use const_oid::{AssociatedOid, ObjectIdentifier}; /// Wrapper around [`BufferKindUser`]. /// @@ -173,6 +175,14 @@ 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 ef084928a..1de1ea86d 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 = "oid")] +#[cfg(feature = "const-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 = "oid")] +#[cfg(feature = "const-oid")] pub trait DynDigestWithOid: DynDigest + DynAssociatedOid {} -#[cfg(feature = "oid")] +#[cfg(feature = "const-oid")] impl DynDigestWithOid for T {} diff --git a/digest/src/lib.rs b/digest/src/lib.rs index de2a784b6..e8cb7b141 100644 --- a/digest/src/lib.rs +++ b/digest/src/lib.rs @@ -63,7 +63,7 @@ pub use block_buffer; pub use const_oid; pub use crypto_common; -#[cfg(feature = "oid")] +#[cfg(feature = "const-oid")] pub use crate::digest::DynDigestWithOid; pub use crate::digest::{Digest, DynDigest, HashMarker}; #[cfg(feature = "mac")]