@@ -2,11 +2,12 @@ use num_bigint::traits::ModInverse;
2
2
use num_bigint:: Sign :: Plus ;
3
3
use num_bigint:: { BigInt , BigUint } ;
4
4
use num_traits:: { FromPrimitive , One } ;
5
- use rand:: { rngs:: ThreadRng , Rng } ;
5
+ use rand:: { rngs:: StdRng , Rng } ;
6
6
#[ cfg( feature = "serde" ) ]
7
7
use serde_crate:: { Deserialize , Serialize } ;
8
- use std :: ops:: Deref ;
8
+ use core :: ops:: Deref ;
9
9
use zeroize:: Zeroize ;
10
+ use alloc:: vec:: Vec ;
10
11
11
12
use crate :: algorithms:: generate_multi_prime_key;
12
13
use crate :: errors:: { Error , Result } ;
@@ -247,6 +248,7 @@ impl RSAPublicKey {
247
248
/// let der_bytes = base64::decode(&der_encoded).expect("failed to decode base64 content");
248
249
/// let public_key = RSAPublicKey::from_pkcs1(&der_bytes).expect("failed to parse key");
249
250
/// ```
251
+ #[ cfg( feature = "std" ) ]
250
252
pub fn from_pkcs1 ( der : & [ u8 ] ) -> Result < RSAPublicKey > {
251
253
crate :: parse:: parse_public_key_pkcs1 ( der)
252
254
}
@@ -281,6 +283,7 @@ impl RSAPublicKey {
281
283
/// let der_bytes = base64::decode(&der_encoded).expect("failed to decode base64 content");
282
284
/// let public_key = RSAPublicKey::from_pkcs8(&der_bytes).expect("failed to parse key");
283
285
/// ```
286
+ #[ cfg( feature = "std" ) ]
284
287
pub fn from_pkcs8 ( der : & [ u8 ] ) -> Result < RSAPublicKey > {
285
288
crate :: parse:: parse_public_key_pkcs8 ( der)
286
289
}
@@ -393,6 +396,7 @@ impl RSAPrivateKey {
393
396
/// let der_bytes = base64::decode(&der_encoded).expect("failed to decode base64 content");
394
397
/// let private_key = RSAPrivateKey::from_pkcs1(&der_bytes).expect("failed to parse key");
395
398
/// ```
399
+ #[ cfg( feature = "std" ) ]
396
400
pub fn from_pkcs1 ( der : & [ u8 ] ) -> Result < RSAPrivateKey > {
397
401
crate :: parse:: parse_private_key_pkcs1 ( der)
398
402
}
@@ -433,6 +437,7 @@ impl RSAPrivateKey {
433
437
/// let der_bytes = base64::decode(&der_encoded).expect("failed to decode base64 content");
434
438
/// let private_key = RSAPrivateKey::from_pkcs8(&der_bytes).expect("failed to parse key");
435
439
/// ```
440
+ #[ cfg( feature = "std" ) ]
436
441
pub fn from_pkcs8 ( der : & [ u8 ] ) -> Result < RSAPrivateKey > {
437
442
crate :: parse:: parse_private_key_pkcs8 ( der)
438
443
}
@@ -542,10 +547,10 @@ impl RSAPrivateKey {
542
547
match padding {
543
548
// need to pass any Rng as the type arg, so the type checker is happy, it is not actually used for anything
544
549
PaddingScheme :: PKCS1v15Encrypt => {
545
- pkcs1v15:: decrypt :: < ThreadRng , _ > ( None , self , ciphertext)
550
+ pkcs1v15:: decrypt :: < StdRng , _ > ( None , self , ciphertext)
546
551
}
547
552
PaddingScheme :: OAEP { mut digest, label } => {
548
- oaep:: decrypt :: < ThreadRng , _ > ( None , self , ciphertext, & mut * digest, label)
553
+ oaep:: decrypt :: < StdRng , _ > ( None , self , ciphertext, & mut * digest, label)
549
554
}
550
555
_ => Err ( Error :: InvalidPaddingScheme ) ,
551
556
}
@@ -572,14 +577,15 @@ impl RSAPrivateKey {
572
577
/// Sign the given digest.
573
578
pub fn sign ( & self , padding : PaddingScheme , digest_in : & [ u8 ] ) -> Result < Vec < u8 > > {
574
579
match padding {
580
+ // need to pass any Rng as the type arg, so the type checker is happy, it is not actually used for anything
575
581
PaddingScheme :: PKCS1v15Sign { ref hash } => {
576
- pkcs1v15:: sign :: < ThreadRng , _ > ( None , self , hash. as_ref ( ) , digest_in)
582
+ pkcs1v15:: sign :: < StdRng , _ > ( None , self , hash. as_ref ( ) , digest_in)
577
583
}
578
584
PaddingScheme :: PSS {
579
585
mut salt_rng,
580
586
mut digest,
581
587
salt_len,
582
- } => pss:: sign :: < _ , ThreadRng , _ > (
588
+ } => pss:: sign :: < _ , StdRng , _ > (
583
589
& mut * salt_rng,
584
590
None ,
585
591
self ,
0 commit comments