3
3
use crate :: { Error , Result } ;
4
4
use der:: {
5
5
asn1:: { AnyRef , ContextSpecificRef , ObjectIdentifier } ,
6
- oid:: AssociatedOid ,
7
6
Decode , DecodeValue , Encode , EncodeValue , FixedTag , Length , Reader , Sequence , Tag , TagMode ,
8
7
TagNumber , Writer ,
9
8
} ;
10
- use spki:: { AlgorithmIdentifier , AlgorithmIdentifierRef } ;
9
+ use spki:: AlgorithmIdentifierRef ;
11
10
12
11
const OID_SHA_1 : ObjectIdentifier = ObjectIdentifier :: new_unwrap ( "1.3.14.3.2.26" ) ;
13
12
const OID_MGF_1 : ObjectIdentifier = ObjectIdentifier :: new_unwrap ( "1.2.840.113549.1.1.8" ) ;
14
13
const OID_PSPECIFIED : ObjectIdentifier = ObjectIdentifier :: new_unwrap ( "1.2.840.113549.1.1.9" ) ;
15
14
15
+ // TODO(tarcieri): make `AlgorithmIdentifier` generic around params; use `OID_SHA_1`
16
+ const SEQ_OID_SHA_1_DER : & [ u8 ] = & [ 0x06 , 0x05 , 0x2b , 0x0e , 0x03 , 0x02 , 0x1a ] ;
17
+
16
18
const SHA_1_AI : AlgorithmIdentifierRef < ' _ > = AlgorithmIdentifierRef {
17
19
oid : OID_SHA_1 ,
18
20
parameters : Some ( AnyRef :: NULL ) ,
@@ -82,7 +84,7 @@ pub struct RsaPssParams<'a> {
82
84
pub hash : AlgorithmIdentifierRef < ' a > ,
83
85
84
86
/// Mask Generation Function (MGF)
85
- pub mask_gen : AlgorithmIdentifier < AlgorithmIdentifierRef < ' a > > ,
87
+ pub mask_gen : AlgorithmIdentifierRef < ' a > ,
86
88
87
89
/// Salt length
88
90
pub salt_len : u8 ,
@@ -95,27 +97,27 @@ impl<'a> RsaPssParams<'a> {
95
97
/// Default RSA PSS Salt length in RsaPssParams
96
98
pub const SALT_LEN_DEFAULT : u8 = 20 ;
97
99
98
- /// Create new RsaPssParams for the provided digest and salt len
99
- pub fn new < D > ( salt_len : u8 ) -> Self
100
- where
101
- D : AssociatedOid ,
102
- {
103
- Self {
104
- hash : AlgorithmIdentifierRef {
105
- oid : D :: OID ,
106
- parameters : Some ( AnyRef :: NULL ) ,
107
- } ,
108
- mask_gen : AlgorithmIdentifier {
109
- oid : OID_MGF_1 ,
110
- parameters : Some ( AlgorithmIdentifierRef {
111
- oid : D :: OID ,
112
- parameters : Some ( AnyRef :: NULL ) ,
113
- } ) ,
114
- } ,
115
- salt_len,
116
- trailer_field : Default :: default ( ) ,
117
- }
118
- }
100
+ // // / Create new RsaPssParams for the provided digest and salt len
101
+ // pub fn new<D>(salt_len: u8) -> Self
102
+ // where
103
+ // D: AssociatedOid,
104
+ // {
105
+ // Self {
106
+ // hash: AlgorithmIdentifierRef {
107
+ // oid: D::OID,
108
+ // parameters: Some(AnyRef::NULL),
109
+ // },
110
+ // mask_gen: AlgorithmIdentifier {
111
+ // oid: OID_MGF_1,
112
+ // parameters: Some(AlgorithmIdentifierRef {
113
+ // oid: D::OID,
114
+ // parameters: Some(AnyRef::NULL),
115
+ // }),
116
+ // },
117
+ // salt_len,
118
+ // trailer_field: Default::default(),
119
+ // }
120
+ // }
119
121
120
122
fn context_specific_hash ( & self ) -> Option < ContextSpecificRef < ' _ , AlgorithmIdentifierRef < ' a > > > {
121
123
if self . hash == SHA_1_AI {
@@ -131,7 +133,7 @@ impl<'a> RsaPssParams<'a> {
131
133
132
134
fn context_specific_mask_gen (
133
135
& self ,
134
- ) -> Option < ContextSpecificRef < ' _ , AlgorithmIdentifier < AlgorithmIdentifierRef < ' a > > > > {
136
+ ) -> Option < ContextSpecificRef < ' _ , AlgorithmIdentifierRef < ' a > > > {
135
137
if self . mask_gen == default_mgf1_sha1 ( ) {
136
138
None
137
139
} else {
@@ -230,10 +232,13 @@ impl<'a> TryFrom<&'a [u8]> for RsaPssParams<'a> {
230
232
}
231
233
232
234
/// Default Mask Generation Function (MGF): SHA-1.
233
- fn default_mgf1_sha1 < ' a > ( ) -> AlgorithmIdentifier < AlgorithmIdentifierRef < ' a > > {
234
- AlgorithmIdentifier :: < AlgorithmIdentifierRef < ' a > > {
235
+ fn default_mgf1_sha1 < ' a > ( ) -> AlgorithmIdentifierRef < ' a > {
236
+ AlgorithmIdentifierRef {
235
237
oid : OID_MGF_1 ,
236
- parameters : Some ( SHA_1_AI ) ,
238
+ parameters : Some (
239
+ AnyRef :: new ( Tag :: Sequence , SEQ_OID_SHA_1_DER )
240
+ . expect ( "error creating default MGF1 params" ) ,
241
+ ) ,
237
242
}
238
243
}
239
244
@@ -258,41 +263,41 @@ pub struct RsaOaepParams<'a> {
258
263
pub hash : AlgorithmIdentifierRef < ' a > ,
259
264
260
265
/// Mask Generation Function (MGF)
261
- pub mask_gen : AlgorithmIdentifier < AlgorithmIdentifierRef < ' a > > ,
266
+ pub mask_gen : AlgorithmIdentifierRef < ' a > ,
262
267
263
268
/// The source (and possibly the value) of the label L
264
269
pub p_source : AlgorithmIdentifierRef < ' a > ,
265
270
}
266
271
267
272
impl < ' a > RsaOaepParams < ' a > {
268
- /// Create new RsaPssParams for the provided digest and default (empty) label
269
- pub fn new < D > ( ) -> Self
270
- where
271
- D : AssociatedOid ,
272
- {
273
- Self :: new_with_label :: < D > ( & [ ] )
274
- }
275
-
276
- /// Create new RsaPssParams for the provided digest and specified label
277
- pub fn new_with_label < D > ( label : & ' a impl AsRef < [ u8 ] > ) -> Self
278
- where
279
- D : AssociatedOid ,
280
- {
281
- Self {
282
- hash : AlgorithmIdentifierRef {
283
- oid : D :: OID ,
284
- parameters : Some ( AnyRef :: NULL ) ,
285
- } ,
286
- mask_gen : AlgorithmIdentifier {
287
- oid : OID_MGF_1 ,
288
- parameters : Some ( AlgorithmIdentifierRef {
289
- oid : D :: OID ,
290
- parameters : Some ( AnyRef :: NULL ) ,
291
- } ) ,
292
- } ,
293
- p_source : pspecicied_algorithm_identifier ( label) ,
294
- }
295
- }
273
+ // // / Create new RsaPssParams for the provided digest and default (empty) label
274
+ // pub fn new<D>() -> Self
275
+ // where
276
+ // D: AssociatedOid,
277
+ // {
278
+ // Self::new_with_label::<D>(&[])
279
+ // }
280
+ //
281
+ // // / Create new RsaPssParams for the provided digest and specified label
282
+ // pub fn new_with_label<D>(label: &'a impl AsRef<[u8]>) -> Self
283
+ // where
284
+ // D: AssociatedOid,
285
+ // {
286
+ // Self {
287
+ // hash: AlgorithmIdentifierRef {
288
+ // oid: D::OID,
289
+ // parameters: Some(AnyRef::NULL),
290
+ // },
291
+ // mask_gen: AlgorithmIdentifier {
292
+ // oid: OID_MGF_1,
293
+ // parameters: Some(AlgorithmIdentifierRef {
294
+ // oid: D::OID,
295
+ // parameters: Some(AnyRef::NULL),
296
+ // }),
297
+ // },
298
+ // p_source: pspecicied_algorithm_identifier(label),
299
+ // }
300
+ // }
296
301
297
302
fn context_specific_hash ( & self ) -> Option < ContextSpecificRef < ' _ , AlgorithmIdentifierRef < ' a > > > {
298
303
if self . hash == SHA_1_AI {
@@ -308,7 +313,7 @@ impl<'a> RsaOaepParams<'a> {
308
313
309
314
fn context_specific_mask_gen (
310
315
& self ,
311
- ) -> Option < ContextSpecificRef < ' _ , AlgorithmIdentifier < AlgorithmIdentifierRef < ' a > > > > {
316
+ ) -> Option < ContextSpecificRef < ' _ , AlgorithmIdentifierRef < ' a > > > {
312
317
if self . mask_gen == default_mgf1_sha1 ( ) {
313
318
None
314
319
} else {
0 commit comments