Skip to content

Commit c48ea2a

Browse files
authored
digest: remove AssociatedOid blanket impls for wrappers (#1810)
Together with #1799 users would need to implement `AssociatedOid` manually for created newtypes. Also replaces `feature = "const-oid"` with `feature = "oid"`.
1 parent 0397384 commit c48ea2a

File tree

5 files changed

+24
-66
lines changed

5 files changed

+24
-66
lines changed

digest/CHANGELOG.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
### Removed
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])
19-
- Removed `io::Write/Read` implementations in favor of the `digest_io::IoWrapper` type ([#1809])
19+
- `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])
2022

2123
[#1173]: https://github.com/RustCrypto/traits/pull/1173
2224
[#1334]: https://github.com/RustCrypto/traits/pull/1334
2325
[#1759]: https://github.com/RustCrypto/traits/pull/1759
2426
[#1809]: https://github.com/RustCrypto/traits/pull/1809
27+
[#1810]: https://github.com/RustCrypto/traits/pull/1810
2528

2629
## 0.10.7 (2023-05-19)
2730
### Changed

digest/src/core_api/ct_variable.rs

+16-51
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ use super::{
55
#[cfg(feature = "mac")]
66
use crate::MacMarker;
77
use crate::{CustomizedInit, HashMarker, VarOutputCustomized};
8-
#[cfg(feature = "oid")]
9-
use const_oid::{AssociatedOid, ObjectIdentifier};
108
use core::{
119
fmt,
1210
marker::PhantomData,
@@ -18,26 +16,20 @@ use crypto_common::{
1816
hazmat::{DeserializeStateError, SerializableState, SerializedState, SubSerializedStateSize},
1917
typenum::{IsLess, IsLessOrEqual, Le, LeEq, NonZero, Sum, U1, U256},
2018
};
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-
2719
/// Wrapper around [`VariableOutputCore`] which selects output size
2820
/// at compile time.
2921
#[derive(Clone)]
30-
pub struct CtVariableCoreWrapper<T, OutSize, O = NoOid>
22+
pub struct CtVariableCoreWrapper<T, OutSize>
3123
where
3224
T: VariableOutputCore,
3325
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
3426
LeEq<OutSize, T::OutputSize>: NonZero,
3527
{
3628
inner: T,
37-
_out: PhantomData<(OutSize, O)>,
29+
_out: PhantomData<OutSize>,
3830
}
3931

40-
impl<T, OutSize, O> HashMarker for CtVariableCoreWrapper<T, OutSize, O>
32+
impl<T, OutSize> HashMarker for CtVariableCoreWrapper<T, OutSize>
4133
where
4234
T: VariableOutputCore + HashMarker,
4335
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
@@ -46,15 +38,15 @@ where
4638
}
4739

4840
#[cfg(feature = "mac")]
49-
impl<T, OutSize, O> MacMarker for CtVariableCoreWrapper<T, OutSize, O>
41+
impl<T, OutSize> MacMarker for CtVariableCoreWrapper<T, OutSize>
5042
where
5143
T: VariableOutputCore + MacMarker,
5244
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
5345
LeEq<OutSize, T::OutputSize>: NonZero,
5446
{
5547
}
5648

57-
impl<T, OutSize, O> BlockSizeUser for CtVariableCoreWrapper<T, OutSize, O>
49+
impl<T, OutSize> BlockSizeUser for CtVariableCoreWrapper<T, OutSize>
5850
where
5951
T: VariableOutputCore,
6052
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
@@ -63,7 +55,7 @@ where
6355
type BlockSize = T::BlockSize;
6456
}
6557

66-
impl<T, OutSize, O> UpdateCore for CtVariableCoreWrapper<T, OutSize, O>
58+
impl<T, OutSize> UpdateCore for CtVariableCoreWrapper<T, OutSize>
6759
where
6860
T: VariableOutputCore,
6961
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
@@ -75,7 +67,7 @@ where
7567
}
7668
}
7769

78-
impl<T, OutSize, O> OutputSizeUser for CtVariableCoreWrapper<T, OutSize, O>
70+
impl<T, OutSize> OutputSizeUser for CtVariableCoreWrapper<T, OutSize>
7971
where
8072
T: VariableOutputCore,
8173
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
@@ -84,7 +76,7 @@ where
8476
type OutputSize = OutSize;
8577
}
8678

87-
impl<T, OutSize, O> BufferKindUser for CtVariableCoreWrapper<T, OutSize, O>
79+
impl<T, OutSize> BufferKindUser for CtVariableCoreWrapper<T, OutSize>
8880
where
8981
T: VariableOutputCore,
9082
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
@@ -93,7 +85,7 @@ where
9385
type BufferKind = T::BufferKind;
9486
}
9587

96-
impl<T, OutSize, O> FixedOutputCore for CtVariableCoreWrapper<T, OutSize, O>
88+
impl<T, OutSize> FixedOutputCore for CtVariableCoreWrapper<T, OutSize>
9789
where
9890
T: VariableOutputCore,
9991
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
@@ -116,7 +108,7 @@ where
116108
}
117109
}
118110

119-
impl<T, OutSize, O> Default for CtVariableCoreWrapper<T, OutSize, O>
111+
impl<T, OutSize> Default for CtVariableCoreWrapper<T, OutSize>
120112
where
121113
T: VariableOutputCore,
122114
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
@@ -131,7 +123,7 @@ where
131123
}
132124
}
133125

134-
impl<T, OutSize, O> CustomizedInit for CtVariableCoreWrapper<T, OutSize, O>
126+
impl<T, OutSize> CustomizedInit for CtVariableCoreWrapper<T, OutSize>
135127
where
136128
T: VariableOutputCore + VarOutputCustomized,
137129
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
@@ -146,7 +138,7 @@ where
146138
}
147139
}
148140

149-
impl<T, OutSize, O> Reset for CtVariableCoreWrapper<T, OutSize, O>
141+
impl<T, OutSize> Reset for CtVariableCoreWrapper<T, OutSize>
150142
where
151143
T: VariableOutputCore,
152144
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
@@ -158,7 +150,7 @@ where
158150
}
159151
}
160152

161-
impl<T, OutSize, O> AlgorithmName for CtVariableCoreWrapper<T, OutSize, O>
153+
impl<T, OutSize> AlgorithmName for CtVariableCoreWrapper<T, OutSize>
162154
where
163155
T: VariableOutputCore + AlgorithmName,
164156
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
@@ -171,27 +163,16 @@ where
171163
}
172164
}
173165

174-
#[cfg(feature = "oid")]
175-
impl<T, OutSize, O> AssociatedOid for CtVariableCoreWrapper<T, OutSize, O>
176-
where
177-
T: VariableOutputCore,
178-
O: AssociatedOid,
179-
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
180-
LeEq<OutSize, T::OutputSize>: NonZero,
181-
{
182-
const OID: ObjectIdentifier = O::OID;
183-
}
184-
185166
#[cfg(feature = "zeroize")]
186-
impl<T, OutSize, O> zeroize::ZeroizeOnDrop for CtVariableCoreWrapper<T, OutSize, O>
167+
impl<T, OutSize> zeroize::ZeroizeOnDrop for CtVariableCoreWrapper<T, OutSize>
187168
where
188169
T: VariableOutputCore + zeroize::ZeroizeOnDrop,
189170
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
190171
LeEq<OutSize, T::OutputSize>: NonZero,
191172
{
192173
}
193174

194-
impl<T, OutSize, O> fmt::Debug for CtVariableCoreWrapper<T, OutSize, O>
175+
impl<T, OutSize> fmt::Debug for CtVariableCoreWrapper<T, OutSize>
195176
where
196177
T: VariableOutputCore + AlgorithmName,
197178
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
@@ -202,26 +183,10 @@ where
202183
}
203184
}
204185

205-
/// Implement dummy type with hidden docs which is used to "carry" hasher
206-
/// OID for [`CtVariableCoreWrapper`].
207-
#[macro_export]
208-
macro_rules! impl_oid_carrier {
209-
($name:ident, $oid:literal) => {
210-
#[doc(hidden)]
211-
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
212-
pub struct $name;
213-
214-
#[cfg(feature = "oid")]
215-
impl AssociatedOid for $name {
216-
const OID: ObjectIdentifier = ObjectIdentifier::new_unwrap($oid);
217-
}
218-
};
219-
}
220-
221186
type CtVariableCoreWrapperSerializedStateSize<T> =
222187
Sum<<T as SerializableState>::SerializedStateSize, U1>;
223188

224-
impl<T, OutSize, O> SerializableState for CtVariableCoreWrapper<T, OutSize, O>
189+
impl<T, OutSize> SerializableState for CtVariableCoreWrapper<T, OutSize>
225190
where
226191
T: VariableOutputCore + SerializableState,
227192
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,

digest/src/core_api/wrapper.rs

-10
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ use crypto_common::{
2121

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

2725
/// Wrapper around [`BufferKindUser`].
2826
///
@@ -171,14 +169,6 @@ where
171169
}
172170
}
173171

174-
#[cfg(feature = "oid")]
175-
impl<T> AssociatedOid for CoreWrapper<T>
176-
where
177-
T: BufferKindUser + AssociatedOid,
178-
{
179-
const OID: ObjectIdentifier = T::OID;
180-
}
181-
182172
type CoreWrapperSerializedStateSize<T> =
183173
Sum<Sum<<T as SerializableState>::SerializedStateSize, U1>, <T as BlockSizeUser>::BlockSize>;
184174

digest/src/digest.rs

+3-3
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 = "const-oid")]
6+
#[cfg(feature = "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 = "const-oid")]
231+
#[cfg(feature = "oid")]
232232
pub trait DynDigestWithOid: DynDigest + DynAssociatedOid {}
233233

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

digest/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub use block_buffer;
6262
pub use const_oid;
6363
pub use crypto_common;
6464

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

0 commit comments

Comments
 (0)