Skip to content

Commit a136046

Browse files
committed
Revert "rand_core: upcoming API breaks (RustCrypto#2175)"
This reverts commit 08b22e5. Those changes are no longer necessary after fixes made in rand_core 0.10.0-rc-5
1 parent ba98810 commit a136046

File tree

13 files changed

+51
-68
lines changed

13 files changed

+51
-68
lines changed

cms/src/builder.rs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@ use alloc::{
2626
vec::Vec,
2727
};
2828
use cipher::{
29-
BlockModeEncrypt, Iv, Key, KeyIvInit,
30-
block_padding::Pkcs7,
31-
crypto_common::Generate,
32-
rand_core::{CryptoRng, RngCore},
29+
BlockModeEncrypt, Iv, Key, KeyIvInit, block_padding::Pkcs7, crypto_common::Generate,
30+
rand_core::CryptoRng,
3331
};
3432
use const_oid::ObjectIdentifier;
3533
use core::{cmp::Ordering, fmt, marker::PhantomData};
@@ -439,7 +437,7 @@ impl<'s> SignedDataBuilder<'s> {
439437
S: RandomizedSigner<Signature>,
440438
S::VerifyingKey: EncodePublicKey,
441439
Signature: SignatureBitStringEncoding,
442-
R: CryptoRng + RngCore + ?Sized,
440+
R: CryptoRng + ?Sized,
443441
{
444442
let signer_info = signer_info_builder
445443
.build_with_rng::<S, Signature, R>(signer, rng)
@@ -484,7 +482,7 @@ impl<'s> SignedDataBuilder<'s> {
484482
S: AsyncRandomizedSigner<Signature>,
485483
S::VerifyingKey: EncodePublicKey,
486484
Signature: SignatureBitStringEncoding,
487-
R: CryptoRng + RngCore + ?Sized,
485+
R: CryptoRng + ?Sized,
488486
{
489487
let signer_info = signer_info_builder
490488
.build_with_rng_async::<S, Signature, R>(signer, rng)
@@ -608,7 +606,7 @@ impl<'s> SignedDataBuilder<'s> {
608606
/// formats. All implementations must implement this trait.
609607
pub trait RecipientInfoBuilder {
610608
/// Associated Rng type
611-
type Rng: CryptoRng + RngCore + ?Sized;
609+
type Rng: CryptoRng + ?Sized;
612610

613611
/// Return the recipient info type
614612
fn recipient_info_type(&self) -> RecipientInfoType;
@@ -670,9 +668,9 @@ impl<R> KeyTransRecipientInfoBuilder<R> {
670668
}
671669
}
672670

673-
impl<R> RecipientInfoBuilder for KeyTransRecipientInfoBuilder<R>
671+
impl<R: ?Sized> RecipientInfoBuilder for KeyTransRecipientInfoBuilder<R>
674672
where
675-
R: CryptoRng + RngCore + ?Sized,
673+
R: CryptoRng,
676674
{
677675
type Rng = R;
678676

@@ -741,9 +739,9 @@ impl<R> KekRecipientInfoBuilder<R> {
741739
}
742740
}
743741

744-
impl<R> RecipientInfoBuilder for KekRecipientInfoBuilder<R>
742+
impl<R: ?Sized> RecipientInfoBuilder for KekRecipientInfoBuilder<R>
745743
where
746-
R: CryptoRng + RngCore + ?Sized,
744+
R: CryptoRng,
747745
{
748746
type Rng = R;
749747

@@ -784,7 +782,7 @@ pub trait PwriEncryptor {
784782
/// including eventual parameters (e.g. the used iv).
785783
fn key_encryption_algorithm(&self) -> Result<AlgorithmIdentifierOwned>;
786784
/// Encrypt the padded content-encryption key twice following RFC 3211, § 2.3.1
787-
fn encrypt_rfc3211<R: CryptoRng + RngCore + ?Sized>(
785+
fn encrypt_rfc3211<R: CryptoRng + ?Sized>(
788786
&mut self,
789787
padded_content_encryption_key: &[u8],
790788
rng: &mut R,
@@ -832,10 +830,10 @@ where
832830
}
833831
}
834832

835-
impl<P, R> PasswordRecipientInfoBuilder<P, R>
833+
impl<P, R: ?Sized> PasswordRecipientInfoBuilder<P, R>
836834
where
837835
P: PwriEncryptor,
838-
R: CryptoRng + RngCore + ?Sized,
836+
R: CryptoRng,
839837
{
840838
/// Wrap the content-encryption key according to [RFC 3211, §2.3.1]:
841839
/// ....
@@ -876,7 +874,7 @@ where
876874
impl<P, R> RecipientInfoBuilder for PasswordRecipientInfoBuilder<P, R>
877875
where
878876
P: PwriEncryptor,
879-
R: CryptoRng + RngCore + ?Sized,
877+
R: CryptoRng + ?Sized,
880878
{
881879
type Rng = R;
882880

@@ -935,7 +933,7 @@ impl<R> OtherRecipientInfoBuilder<R> {
935933

936934
impl<R> RecipientInfoBuilder for OtherRecipientInfoBuilder<R>
937935
where
938-
R: CryptoRng + RngCore + ?Sized,
936+
R: CryptoRng + ?Sized,
939937
{
940938
type Rng = R;
941939

@@ -1019,7 +1017,7 @@ impl<'c, R> EnvelopedDataBuilder<'c, R> {
10191017

10201018
impl<'c, R> EnvelopedDataBuilder<'c, R>
10211019
where
1022-
R: CryptoRng + RngCore + ?Sized,
1020+
R: CryptoRng + ?Sized,
10231021
{
10241022
/// Add recipient info. A builder is used, which generates a `RecipientInfo` according to
10251023
/// RFC 5652 § 6.2, when `EnvelopedData` is built.
@@ -1216,7 +1214,7 @@ fn encrypt_data<R>(
12161214
rng: &mut R,
12171215
) -> Result<(Vec<u8>, Vec<u8>, AlgorithmIdentifierOwned)>
12181216
where
1219-
R: CryptoRng + RngCore + ?Sized,
1217+
R: CryptoRng + ?Sized,
12201218
{
12211219
match encryption_algorithm_identifier {
12221220
ContentEncryptionAlgorithm::Aes128Cbc => encrypt_block_mode!(

cms/src/builder/kari.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
99
// Super imports
1010
use super::{
11-
AlgorithmIdentifierOwned, CryptoRng, RecipientInfoBuilder, RecipientInfoType, Result, RngCore,
11+
AlgorithmIdentifierOwned, CryptoRng, RecipientInfoBuilder, RecipientInfoType, Result,
1212
UserKeyingMaterial,
1313
utils::kw::{KeyWrapAlgorithm, WrappedKey},
1414
};
@@ -250,9 +250,10 @@ where
250250
})
251251
}
252252
}
253-
impl<R, C, KA, KW, Enc> RecipientInfoBuilder for KeyAgreeRecipientInfoBuilder<R, C, KA, KW, Enc>
253+
impl<R: ?Sized, C, KA, KW, Enc> RecipientInfoBuilder
254+
for KeyAgreeRecipientInfoBuilder<R, C, KA, KW, Enc>
254255
where
255-
R: CryptoRng + RngCore + ?Sized,
256+
R: CryptoRng,
256257
KA: KeyAgreementAlgorithm + AssociatedOid,
257258
C: CurveArithmetic + AssociatedOid + PointCompression,
258259
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,

cms/tests/builder.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use pem_rfc7468::LineEnding;
2323
use pkcs5::pbes2::Pbkdf2Params;
2424
use rand::rngs::SysRng;
2525
use rsa::pkcs1::DecodeRsaPrivateKey;
26-
use rsa::rand_core::{CryptoRng, RngCore, TryRngCore};
26+
use rsa::rand_core::{CryptoRng, TryRngCore};
2727
use rsa::{Pkcs1v15Encrypt, RsaPrivateKey, RsaPublicKey};
2828
use rsa::{pkcs1v15, pss};
2929
use sha2::Sha256;
@@ -690,10 +690,7 @@ fn test_create_password_recipient_info() {
690690
key_derivation_params: pkcs5::pbes2::Pbkdf2Params,
691691
}
692692
impl<'a> Aes128CbcPwriEncryptor<'a> {
693-
pub fn new<R: CryptoRng + RngCore + ?Sized>(
694-
challenge_password: &'a [u8],
695-
rng: &mut R,
696-
) -> Self {
693+
pub fn new<R: CryptoRng + ?Sized>(challenge_password: &'a [u8], rng: &mut R) -> Self {
697694
let mut key_encryption_iv = [0u8; 16];
698695
rng.fill_bytes(key_encryption_iv.as_mut_slice());
699696
let key_encryption_iv = key_encryption_iv.into();
@@ -711,7 +708,7 @@ fn test_create_password_recipient_info() {
711708
}
712709
impl PwriEncryptor for Aes128CbcPwriEncryptor<'_> {
713710
const BLOCK_LENGTH_BITS: usize = 128; // AES block length
714-
fn encrypt_rfc3211<R: CryptoRng + RngCore + ?Sized>(
711+
fn encrypt_rfc3211<R: CryptoRng + ?Sized>(
715712
&mut self,
716713
padded_content_encryption_key: &[u8],
717714
_rng: &mut R,

phc/src/salt.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use core::{
88
str::{self, FromStr},
99
};
1010
#[cfg(feature = "rand_core")]
11-
use rand_core::{CryptoRng, RngCore, TryCryptoRng, TryRngCore};
11+
use rand_core::{CryptoRng, TryCryptoRng};
1212

1313
/// Error message used with `expect` for when internal invariants are violated
1414
/// (i.e. the contents of a [`Salt`] should always be valid)
@@ -117,14 +117,14 @@ impl Salt {
117117

118118
/// Generate a random [`Salt`] from the given [`CryptoRng`].
119119
#[cfg(feature = "rand_core")]
120-
pub fn from_rng<R: CryptoRng + RngCore + ?Sized>(rng: &mut R) -> Self {
120+
pub fn from_rng<R: CryptoRng + ?Sized>(rng: &mut R) -> Self {
121121
let Ok(out) = Self::try_from_rng(rng);
122122
out
123123
}
124124

125125
/// Generate a random [`Salt`] from the given [`TryCryptoRng`].
126126
#[cfg(feature = "rand_core")]
127-
pub fn try_from_rng<R: TryCryptoRng + TryRngCore + ?Sized>(
127+
pub fn try_from_rng<R: TryCryptoRng + ?Sized>(
128128
rng: &mut R,
129129
) -> core::result::Result<Self, R::Error> {
130130
let mut bytes = [0u8; Self::RECOMMENDED_LENGTH];
@@ -256,14 +256,14 @@ impl SaltString {
256256

257257
/// Generate a random B64-encoded [`SaltString`] from [`CryptoRng`].
258258
#[cfg(feature = "rand_core")]
259-
pub fn from_rng<R: CryptoRng + RngCore + ?Sized>(rng: &mut R) -> Self {
259+
pub fn from_rng<R: CryptoRng + ?Sized>(rng: &mut R) -> Self {
260260
let Ok(out) = Self::try_from_rng(rng);
261261
out
262262
}
263263

264264
/// Generate a random B64-encoded [`SaltString`] from [`TryCryptoRng`].
265265
#[cfg(feature = "rand_core")]
266-
pub fn try_from_rng<R: TryCryptoRng + TryRngCore + ?Sized>(
266+
pub fn try_from_rng<R: TryCryptoRng + ?Sized>(
267267
rng: &mut R,
268268
) -> core::result::Result<Self, R::Error> {
269269
Ok(Salt::try_from_rng(rng)?.to_salt_string())

pkcs5/src/pbes2.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use der::{
1919
};
2020

2121
#[cfg(feature = "rand_core")]
22-
use rand_core::{CryptoRng, RngCore};
22+
use rand_core::CryptoRng;
2323

2424
#[cfg(all(feature = "alloc", feature = "pbes2"))]
2525
use alloc::vec::Vec;
@@ -106,7 +106,7 @@ impl Parameters {
106106
/// This is currently an alias for [`Parameters::scrypt`]. See that method
107107
/// for more information.
108108
#[cfg(all(feature = "pbes2", feature = "rand_core"))]
109-
pub fn recommended<R: CryptoRng + RngCore + ?Sized>(rng: &mut R) -> Self {
109+
pub fn recommended<R: CryptoRng>(rng: &mut R) -> Self {
110110
Self::scrypt(rng)
111111
}
112112

@@ -118,7 +118,7 @@ impl Parameters {
118118
/// This will use AES-256-CBC as the encryption algorithm and SHA-256 as
119119
/// the hash function for PBKDF2.
120120
#[cfg(feature = "rand_core")]
121-
pub fn pbkdf2<R: CryptoRng + RngCore + ?Sized>(rng: &mut R) -> Self {
121+
pub fn pbkdf2<R: CryptoRng>(rng: &mut R) -> Self {
122122
let mut iv = [0u8; Self::DEFAULT_IV_LEN];
123123
rng.fill_bytes(&mut iv);
124124

@@ -169,7 +169,7 @@ impl Parameters {
169169
///
170170
/// [RustCrypto/formats#1205]: https://github.com/RustCrypto/formats/issues/1205
171171
#[cfg(all(feature = "pbes2", feature = "rand_core"))]
172-
pub fn scrypt<R: CryptoRng + RngCore + ?Sized>(rng: &mut R) -> Self {
172+
pub fn scrypt<R: CryptoRng>(rng: &mut R) -> Self {
173173
let mut iv = [0u8; Self::DEFAULT_IV_LEN];
174174
rng.fill_bytes(&mut iv);
175175

pkcs8/src/encrypted_private_key_info.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ use pkcs5::EncryptionScheme;
1212
use der::{SecretDocument, asn1::OctetString};
1313

1414
#[cfg(feature = "encryption")]
15-
use {
16-
pkcs5::pbes2,
17-
rand_core::{CryptoRng, RngCore},
18-
};
15+
use {pkcs5::pbes2, rand_core::CryptoRng};
1916

2017
#[cfg(feature = "pem")]
2118
use der::pem::PemLabel;
@@ -67,7 +64,7 @@ where
6764
/// Encrypt the given ASN.1 DER document using a symmetric encryption key
6865
/// derived from the provided password.
6966
#[cfg(feature = "encryption")]
70-
pub(crate) fn encrypt<R: CryptoRng + RngCore + ?Sized>(
67+
pub(crate) fn encrypt<R: CryptoRng>(
7168
rng: &mut R,
7269
password: impl AsRef<[u8]>,
7370
doc: &[u8],

pkcs8/src/private_key_info.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ use der::{
1717

1818
#[cfg(feature = "encryption")]
1919
use {
20-
crate::EncryptedPrivateKeyInfoRef,
21-
der::zeroize::Zeroizing,
22-
pkcs5::pbes2,
23-
rand_core::{CryptoRng, RngCore},
20+
crate::EncryptedPrivateKeyInfoRef, der::zeroize::Zeroizing, pkcs5::pbes2, rand_core::CryptoRng,
2421
};
2522

2623
#[cfg(feature = "pem")]
@@ -151,7 +148,7 @@ where
151148
/// - p: 1
152149
/// - Cipher: AES-256-CBC (best available option for PKCS#5 encryption)
153150
#[cfg(feature = "encryption")]
154-
pub fn encrypt<R: CryptoRng + RngCore + ?Sized>(
151+
pub fn encrypt<R: CryptoRng>(
155152
&self,
156153
rng: &mut R,
157154
password: impl AsRef<[u8]>,

pkcs8/src/traits.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ use crate::{Error, PrivateKeyInfoRef, Result};
66
use der::SecretDocument;
77

88
#[cfg(feature = "encryption")]
9-
use {
10-
crate::EncryptedPrivateKeyInfoRef,
11-
rand_core::{CryptoRng, RngCore},
12-
};
9+
use {crate::EncryptedPrivateKeyInfoRef, rand_core::CryptoRng};
1310

1411
#[cfg(feature = "pem")]
1512
use {
@@ -104,7 +101,7 @@ pub trait EncodePrivateKey {
104101
/// Create an [`SecretDocument`] containing the ciphertext of
105102
/// a PKCS#8 encoded private key encrypted under the given `password`.
106103
#[cfg(feature = "encryption")]
107-
fn to_pkcs8_encrypted_der<R: CryptoRng + RngCore + ?Sized>(
104+
fn to_pkcs8_encrypted_der<R: CryptoRng>(
108105
&self,
109106
rng: &mut R,
110107
password: impl AsRef<[u8]>,
@@ -122,7 +119,7 @@ pub trait EncodePrivateKey {
122119
/// Serialize this private key as an encrypted PEM-encoded PKCS#8 private
123120
/// key using the `provided` to derive an encryption key.
124121
#[cfg(all(feature = "encryption", feature = "pem"))]
125-
fn to_pkcs8_encrypted_pem<R: CryptoRng + RngCore + ?Sized>(
122+
fn to_pkcs8_encrypted_pem<R: CryptoRng>(
126123
&self,
127124
rng: &mut R,
128125
password: impl AsRef<[u8]>,

x509-cert/src/builder.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ use alloc::vec;
44
use core::fmt;
55
use der::{Encode, asn1::BitString, referenced::OwnedToRef};
66
use signature::{
7-
AsyncRandomizedSigner, AsyncSigner, Keypair, RandomizedSigner, Signer,
8-
rand_core::{CryptoRng, RngCore},
7+
AsyncRandomizedSigner, AsyncSigner, Keypair, RandomizedSigner, Signer, rand_core::CryptoRng,
98
};
109
use spki::{
1110
DynSignatureAlgorithmIdentifier, EncodePublicKey, ObjectIdentifier, SignatureBitStringEncoding,
@@ -348,7 +347,7 @@ pub trait Builder: Sized {
348347
S: Keypair + DynSignatureAlgorithmIdentifier,
349348
S::VerifyingKey: EncodePublicKey,
350349
Signature: SignatureBitStringEncoding,
351-
R: CryptoRng + RngCore + ?Sized,
350+
R: CryptoRng + ?Sized,
352351
{
353352
let blob = self.finalize(signer)?;
354353

@@ -540,7 +539,7 @@ pub trait AsyncBuilder: Sized {
540539
S: Keypair + DynSignatureAlgorithmIdentifier,
541540
S::VerifyingKey: EncodePublicKey,
542541
Signature: SignatureBitStringEncoding,
543-
R: CryptoRng + RngCore + ?Sized,
542+
R: CryptoRng + ?Sized,
544543
{
545544
let blob = self.finalize(signer)?;
546545

x509-cert/src/serial_number.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ use der::{
88
asn1::{self, Int},
99
};
1010
#[cfg(feature = "builder")]
11-
use {
12-
alloc::vec,
13-
signature::rand_core::{CryptoRng, RngCore},
14-
};
11+
use {alloc::vec, signature::rand_core::CryptoRng};
1512

1613
use crate::certificate::{Profile, Rfc5280};
1714

@@ -80,7 +77,7 @@ impl<P: Profile> SerialNumber<P> {
8077
/// of output from the CSPRNG. This currently defaults to a 17-bytes long serial number.
8178
///
8279
/// [ballot 164]: https://cabforum.org/2016/03/31/ballot-164/
83-
pub fn generate<R: CryptoRng + RngCore + ?Sized>(rng: &mut R) -> Self {
80+
pub fn generate<R: CryptoRng + ?Sized>(rng: &mut R) -> Self {
8481
Self::generate_with_prefix(&[], 17, rng)
8582
.expect("a random of 17 is acceptable, and rng may not fail")
8683
}
@@ -94,7 +91,7 @@ impl<P: Profile> SerialNumber<P> {
9491
/// equal or below 19 (to account for leading sign disambiguation, and the maximum length of 20).
9592
///
9693
/// [ballot 164]: https://cabforum.org/2016/03/31/ballot-164/
97-
pub fn generate_with_prefix<R: CryptoRng + RngCore + ?Sized>(
94+
pub fn generate_with_prefix<R: CryptoRng + ?Sized>(
9895
prefix: &[u8],
9996
rand_len: usize,
10097
rng: &mut R,

0 commit comments

Comments
 (0)