@@ -5,6 +5,8 @@ use super::{
5
5
#[ cfg( feature = "mac" ) ]
6
6
use crate :: MacMarker ;
7
7
use crate :: { CollisionResistance , CustomizedInit , HashMarker , VarOutputCustomized } ;
8
+ #[ cfg( feature = "oid" ) ]
9
+ use const_oid:: { AssociatedOid , ObjectIdentifier } ;
8
10
use core:: {
9
11
fmt,
10
12
marker:: PhantomData ,
@@ -16,20 +18,26 @@ use crypto_common::{
16
18
hazmat:: { DeserializeStateError , SerializableState , SerializedState , SubSerializedStateSize } ,
17
19
typenum:: { IsLess , IsLessOrEqual , Le , LeEq , NonZero , Sum , U1 , U256 } ,
18
20
} ;
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
+
19
27
/// Wrapper around [`VariableOutputCore`] which selects output size
20
28
/// at compile time.
21
29
#[ derive( Clone ) ]
22
- pub struct CtVariableCoreWrapper < T , OutSize >
30
+ pub struct CtVariableCoreWrapper < T , OutSize , O = NoOid >
23
31
where
24
32
T : VariableOutputCore ,
25
33
OutSize : ArraySize + IsLessOrEqual < T :: OutputSize > ,
26
34
LeEq < OutSize , T :: OutputSize > : NonZero ,
27
35
{
28
36
inner : T ,
29
- _out : PhantomData < OutSize > ,
37
+ _out : PhantomData < ( OutSize , O ) > ,
30
38
}
31
39
32
- impl < T , OutSize > HashMarker for CtVariableCoreWrapper < T , OutSize >
40
+ impl < T , OutSize , O > HashMarker for CtVariableCoreWrapper < T , OutSize , O >
33
41
where
34
42
T : VariableOutputCore + HashMarker ,
35
43
OutSize : ArraySize + IsLessOrEqual < T :: OutputSize > ,
38
46
}
39
47
40
48
#[ cfg( feature = "mac" ) ]
41
- impl < T , OutSize > MacMarker for CtVariableCoreWrapper < T , OutSize >
49
+ impl < T , OutSize , O > MacMarker for CtVariableCoreWrapper < T , OutSize , O >
42
50
where
43
51
T : VariableOutputCore + MacMarker ,
44
52
OutSize : ArraySize + IsLessOrEqual < T :: OutputSize > ,
55
63
type CollisionResistance = T :: CollisionResistance ;
56
64
}
57
65
58
- impl < T , OutSize > BlockSizeUser for CtVariableCoreWrapper < T , OutSize >
66
+ impl < T , OutSize , O > BlockSizeUser for CtVariableCoreWrapper < T , OutSize , O >
59
67
where
60
68
T : VariableOutputCore ,
61
69
OutSize : ArraySize + IsLessOrEqual < T :: OutputSize > ,
64
72
type BlockSize = T :: BlockSize ;
65
73
}
66
74
67
- impl < T , OutSize > UpdateCore for CtVariableCoreWrapper < T , OutSize >
75
+ impl < T , OutSize , O > UpdateCore for CtVariableCoreWrapper < T , OutSize , O >
68
76
where
69
77
T : VariableOutputCore ,
70
78
OutSize : ArraySize + IsLessOrEqual < T :: OutputSize > ,
76
84
}
77
85
}
78
86
79
- impl < T , OutSize > OutputSizeUser for CtVariableCoreWrapper < T , OutSize >
87
+ impl < T , OutSize , O > OutputSizeUser for CtVariableCoreWrapper < T , OutSize , O >
80
88
where
81
89
T : VariableOutputCore ,
82
90
OutSize : ArraySize + IsLessOrEqual < T :: OutputSize > ,
85
93
type OutputSize = OutSize ;
86
94
}
87
95
88
- impl < T , OutSize > BufferKindUser for CtVariableCoreWrapper < T , OutSize >
96
+ impl < T , OutSize , O > BufferKindUser for CtVariableCoreWrapper < T , OutSize , O >
89
97
where
90
98
T : VariableOutputCore ,
91
99
OutSize : ArraySize + IsLessOrEqual < T :: OutputSize > ,
94
102
type BufferKind = T :: BufferKind ;
95
103
}
96
104
97
- impl < T , OutSize > FixedOutputCore for CtVariableCoreWrapper < T , OutSize >
105
+ impl < T , OutSize , O > FixedOutputCore for CtVariableCoreWrapper < T , OutSize , O >
98
106
where
99
107
T : VariableOutputCore ,
100
108
OutSize : ArraySize + IsLessOrEqual < T :: OutputSize > ,
@@ -117,7 +125,7 @@ where
117
125
}
118
126
}
119
127
120
- impl < T , OutSize > Default for CtVariableCoreWrapper < T , OutSize >
128
+ impl < T , OutSize , O > Default for CtVariableCoreWrapper < T , OutSize , O >
121
129
where
122
130
T : VariableOutputCore ,
123
131
OutSize : ArraySize + IsLessOrEqual < T :: OutputSize > ,
@@ -132,7 +140,7 @@ where
132
140
}
133
141
}
134
142
135
- impl < T , OutSize > CustomizedInit for CtVariableCoreWrapper < T , OutSize >
143
+ impl < T , OutSize , O > CustomizedInit for CtVariableCoreWrapper < T , OutSize , O >
136
144
where
137
145
T : VariableOutputCore + VarOutputCustomized ,
138
146
OutSize : ArraySize + IsLessOrEqual < T :: OutputSize > ,
@@ -147,7 +155,7 @@ where
147
155
}
148
156
}
149
157
150
- impl < T , OutSize > Reset for CtVariableCoreWrapper < T , OutSize >
158
+ impl < T , OutSize , O > Reset for CtVariableCoreWrapper < T , OutSize , O >
151
159
where
152
160
T : VariableOutputCore ,
153
161
OutSize : ArraySize + IsLessOrEqual < T :: OutputSize > ,
@@ -159,7 +167,7 @@ where
159
167
}
160
168
}
161
169
162
- impl < T , OutSize > AlgorithmName for CtVariableCoreWrapper < T , OutSize >
170
+ impl < T , OutSize , O > AlgorithmName for CtVariableCoreWrapper < T , OutSize , O >
163
171
where
164
172
T : VariableOutputCore + AlgorithmName ,
165
173
OutSize : ArraySize + IsLessOrEqual < T :: OutputSize > ,
@@ -172,16 +180,27 @@ where
172
180
}
173
181
}
174
182
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
+
175
194
#[ 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 >
177
196
where
178
197
T : VariableOutputCore + zeroize:: ZeroizeOnDrop ,
179
198
OutSize : ArraySize + IsLessOrEqual < T :: OutputSize > ,
180
199
LeEq < OutSize , T :: OutputSize > : NonZero ,
181
200
{
182
201
}
183
202
184
- impl < T , OutSize > fmt:: Debug for CtVariableCoreWrapper < T , OutSize >
203
+ impl < T , OutSize , O > fmt:: Debug for CtVariableCoreWrapper < T , OutSize , O >
185
204
where
186
205
T : VariableOutputCore + AlgorithmName ,
187
206
OutSize : ArraySize + IsLessOrEqual < T :: OutputSize > ,
@@ -192,10 +211,26 @@ where
192
211
}
193
212
}
194
213
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
+
195
230
type CtVariableCoreWrapperSerializedStateSize < T > =
196
231
Sum < <T as SerializableState >:: SerializedStateSize , U1 > ;
197
232
198
- impl < T , OutSize > SerializableState for CtVariableCoreWrapper < T , OutSize >
233
+ impl < T , OutSize , O > SerializableState for CtVariableCoreWrapper < T , OutSize , O >
199
234
where
200
235
T : VariableOutputCore + SerializableState ,
201
236
OutSize : ArraySize + IsLessOrEqual < T :: OutputSize > ,
0 commit comments