Skip to content

Commit 3d8039a

Browse files
authored
Revert "digest: remove AssociatedOid blanket impls for wrappers (#1857)
This reverts commit c48ea2a (#1810) This bring back `master` in a state that can be consumed with a `[patch.crates-io]` (see #1799 (comment))
1 parent a948995 commit 3d8039a

File tree

5 files changed

+65
-23
lines changed

5 files changed

+65
-23
lines changed

digest/CHANGELOG.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
- `Mac::new`, `Mac::new_from_slice`, and `Mac::generate_key` methods ([#1173])
1818
- `HashReader` and `HashWriter` are moved to the `digest-io` crate ([#1809])
1919
- `io::Write/Read` implementations in favor of the `digest_io::IoWrapper` type ([#1809])
20-
- `AssociatedOid` blanket impls for `CoreWrapper` and `CtVariableCoreWrapper` ([#1810])
21-
- `impl_oid_carrier!` macro ([#1810])
2220

2321
[#1173]: https://github.com/RustCrypto/traits/pull/1173
2422
[#1334]: https://github.com/RustCrypto/traits/pull/1334
2523
[#1759]: https://github.com/RustCrypto/traits/pull/1759
2624
[#1809]: https://github.com/RustCrypto/traits/pull/1809
27-
[#1810]: https://github.com/RustCrypto/traits/pull/1810
2825

2926
## 0.10.7 (2023-05-19)
3027
### Changed

digest/src/core_api/ct_variable.rs

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use super::{
55
#[cfg(feature = "mac")]
66
use crate::MacMarker;
77
use crate::{CollisionResistance, CustomizedInit, HashMarker, VarOutputCustomized};
8+
#[cfg(feature = "oid")]
9+
use const_oid::{AssociatedOid, ObjectIdentifier};
810
use core::{
911
fmt,
1012
marker::PhantomData,
@@ -16,20 +18,26 @@ use crypto_common::{
1618
hazmat::{DeserializeStateError, SerializableState, SerializedState, SubSerializedStateSize},
1719
typenum::{IsLess, IsLessOrEqual, Le, LeEq, NonZero, Sum, U1, U256},
1820
};
21+
22+
/// Dummy type used with [`CtVariableCoreWrapper`] in cases when
23+
/// resulting hash does not have a known OID.
24+
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
25+
pub struct NoOid;
26+
1927
/// Wrapper around [`VariableOutputCore`] which selects output size
2028
/// at compile time.
2129
#[derive(Clone)]
22-
pub struct CtVariableCoreWrapper<T, OutSize>
30+
pub struct CtVariableCoreWrapper<T, OutSize, O = NoOid>
2331
where
2432
T: VariableOutputCore,
2533
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
2634
LeEq<OutSize, T::OutputSize>: NonZero,
2735
{
2836
inner: T,
29-
_out: PhantomData<OutSize>,
37+
_out: PhantomData<(OutSize, O)>,
3038
}
3139

32-
impl<T, OutSize> HashMarker for CtVariableCoreWrapper<T, OutSize>
40+
impl<T, OutSize, O> HashMarker for CtVariableCoreWrapper<T, OutSize, O>
3341
where
3442
T: VariableOutputCore + HashMarker,
3543
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
@@ -38,7 +46,7 @@ where
3846
}
3947

4048
#[cfg(feature = "mac")]
41-
impl<T, OutSize> MacMarker for CtVariableCoreWrapper<T, OutSize>
49+
impl<T, OutSize, O> MacMarker for CtVariableCoreWrapper<T, OutSize, O>
4250
where
4351
T: VariableOutputCore + MacMarker,
4452
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
@@ -55,7 +63,7 @@ where
5563
type CollisionResistance = T::CollisionResistance;
5664
}
5765

58-
impl<T, OutSize> BlockSizeUser for CtVariableCoreWrapper<T, OutSize>
66+
impl<T, OutSize, O> BlockSizeUser for CtVariableCoreWrapper<T, OutSize, O>
5967
where
6068
T: VariableOutputCore,
6169
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
@@ -64,7 +72,7 @@ where
6472
type BlockSize = T::BlockSize;
6573
}
6674

67-
impl<T, OutSize> UpdateCore for CtVariableCoreWrapper<T, OutSize>
75+
impl<T, OutSize, O> UpdateCore for CtVariableCoreWrapper<T, OutSize, O>
6876
where
6977
T: VariableOutputCore,
7078
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
@@ -76,7 +84,7 @@ where
7684
}
7785
}
7886

79-
impl<T, OutSize> OutputSizeUser for CtVariableCoreWrapper<T, OutSize>
87+
impl<T, OutSize, O> OutputSizeUser for CtVariableCoreWrapper<T, OutSize, O>
8088
where
8189
T: VariableOutputCore,
8290
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
@@ -85,7 +93,7 @@ where
8593
type OutputSize = OutSize;
8694
}
8795

88-
impl<T, OutSize> BufferKindUser for CtVariableCoreWrapper<T, OutSize>
96+
impl<T, OutSize, O> BufferKindUser for CtVariableCoreWrapper<T, OutSize, O>
8997
where
9098
T: VariableOutputCore,
9199
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
@@ -94,7 +102,7 @@ where
94102
type BufferKind = T::BufferKind;
95103
}
96104

97-
impl<T, OutSize> FixedOutputCore for CtVariableCoreWrapper<T, OutSize>
105+
impl<T, OutSize, O> FixedOutputCore for CtVariableCoreWrapper<T, OutSize, O>
98106
where
99107
T: VariableOutputCore,
100108
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
@@ -117,7 +125,7 @@ where
117125
}
118126
}
119127

120-
impl<T, OutSize> Default for CtVariableCoreWrapper<T, OutSize>
128+
impl<T, OutSize, O> Default for CtVariableCoreWrapper<T, OutSize, O>
121129
where
122130
T: VariableOutputCore,
123131
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
@@ -132,7 +140,7 @@ where
132140
}
133141
}
134142

135-
impl<T, OutSize> CustomizedInit for CtVariableCoreWrapper<T, OutSize>
143+
impl<T, OutSize, O> CustomizedInit for CtVariableCoreWrapper<T, OutSize, O>
136144
where
137145
T: VariableOutputCore + VarOutputCustomized,
138146
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
@@ -147,7 +155,7 @@ where
147155
}
148156
}
149157

150-
impl<T, OutSize> Reset for CtVariableCoreWrapper<T, OutSize>
158+
impl<T, OutSize, O> Reset for CtVariableCoreWrapper<T, OutSize, O>
151159
where
152160
T: VariableOutputCore,
153161
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
@@ -159,7 +167,7 @@ where
159167
}
160168
}
161169

162-
impl<T, OutSize> AlgorithmName for CtVariableCoreWrapper<T, OutSize>
170+
impl<T, OutSize, O> AlgorithmName for CtVariableCoreWrapper<T, OutSize, O>
163171
where
164172
T: VariableOutputCore + AlgorithmName,
165173
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
@@ -172,16 +180,27 @@ where
172180
}
173181
}
174182

183+
#[cfg(feature = "oid")]
184+
impl<T, OutSize, O> AssociatedOid for CtVariableCoreWrapper<T, OutSize, O>
185+
where
186+
T: VariableOutputCore,
187+
O: AssociatedOid,
188+
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
189+
LeEq<OutSize, T::OutputSize>: NonZero,
190+
{
191+
const OID: ObjectIdentifier = O::OID;
192+
}
193+
175194
#[cfg(feature = "zeroize")]
176-
impl<T, OutSize> zeroize::ZeroizeOnDrop for CtVariableCoreWrapper<T, OutSize>
195+
impl<T, OutSize, O> zeroize::ZeroizeOnDrop for CtVariableCoreWrapper<T, OutSize, O>
177196
where
178197
T: VariableOutputCore + zeroize::ZeroizeOnDrop,
179198
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
180199
LeEq<OutSize, T::OutputSize>: NonZero,
181200
{
182201
}
183202

184-
impl<T, OutSize> fmt::Debug for CtVariableCoreWrapper<T, OutSize>
203+
impl<T, OutSize, O> fmt::Debug for CtVariableCoreWrapper<T, OutSize, O>
185204
where
186205
T: VariableOutputCore + AlgorithmName,
187206
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
@@ -192,10 +211,26 @@ where
192211
}
193212
}
194213

214+
/// Implement dummy type with hidden docs which is used to "carry" hasher
215+
/// OID for [`CtVariableCoreWrapper`].
216+
#[macro_export]
217+
macro_rules! impl_oid_carrier {
218+
($name:ident, $oid:literal) => {
219+
#[doc(hidden)]
220+
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
221+
pub struct $name;
222+
223+
#[cfg(feature = "oid")]
224+
impl AssociatedOid for $name {
225+
const OID: ObjectIdentifier = ObjectIdentifier::new_unwrap($oid);
226+
}
227+
};
228+
}
229+
195230
type CtVariableCoreWrapperSerializedStateSize<T> =
196231
Sum<<T as SerializableState>::SerializedStateSize, U1>;
197232

198-
impl<T, OutSize> SerializableState for CtVariableCoreWrapper<T, OutSize>
233+
impl<T, OutSize, O> SerializableState for CtVariableCoreWrapper<T, OutSize, O>
199234
where
200235
T: VariableOutputCore + SerializableState,
201236
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,

digest/src/core_api/wrapper.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ use crypto_common::{
2121

2222
#[cfg(feature = "mac")]
2323
use crate::MacMarker;
24+
#[cfg(feature = "oid")]
25+
use const_oid::{AssociatedOid, ObjectIdentifier};
2426

2527
/// Wrapper around [`BufferKindUser`].
2628
///
@@ -173,6 +175,14 @@ where
173175
}
174176
}
175177

178+
#[cfg(feature = "oid")]
179+
impl<T> AssociatedOid for CoreWrapper<T>
180+
where
181+
T: BufferKindUser + AssociatedOid,
182+
{
183+
const OID: ObjectIdentifier = T::OID;
184+
}
185+
176186
type CoreWrapperSerializedStateSize<T> =
177187
Sum<Sum<<T as SerializableState>::SerializedStateSize, U1>, <T as BlockSizeUser>::BlockSize>;
178188

digest/src/digest.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crypto_common::{Output, OutputSizeUser, typenum::Unsigned};
33

44
#[cfg(feature = "alloc")]
55
use alloc::boxed::Box;
6-
#[cfg(feature = "oid")]
6+
#[cfg(feature = "const-oid")]
77
use const_oid::DynAssociatedOid;
88

99
/// Marker trait for cryptographic hash functions.
@@ -228,8 +228,8 @@ impl Clone for Box<dyn DynDigest> {
228228
}
229229

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

234-
#[cfg(feature = "oid")]
234+
#[cfg(feature = "const-oid")]
235235
impl<T: DynDigest + DynAssociatedOid> DynDigestWithOid for T {}

digest/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub use block_buffer;
6363
pub use const_oid;
6464
pub use crypto_common;
6565

66-
#[cfg(feature = "oid")]
66+
#[cfg(feature = "const-oid")]
6767
pub use crate::digest::DynDigestWithOid;
6868
pub use crate::digest::{Digest, DynDigest, HashMarker};
6969
#[cfg(feature = "mac")]

0 commit comments

Comments
 (0)