Skip to content

Commit 381e23c

Browse files
authored
pkcs8: use TryCryptoRng instead of CryptoRng (#2309)
Since `pkcs5` was already changed to support this (#2296) this change just works without anything else needed.
1 parent 77c386e commit 381e23c

3 files changed

Lines changed: 8 additions & 7 deletions

File tree

pkcs8/src/encrypted_private_key_info.rs

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

1414
#[cfg(feature = "encryption")]
15-
use {pkcs5::pbes2, rand_core::CryptoRng};
15+
use {pkcs5::pbes2, rand_core::TryCryptoRng};
1616

1717
#[cfg(feature = "pem")]
1818
use der::pem::PemLabel;
@@ -68,7 +68,7 @@ where
6868
/// Encrypt the given ASN.1 DER document using a symmetric encryption key
6969
/// derived from the provided password.
7070
#[cfg(feature = "encryption")]
71-
pub(crate) fn encrypt<R: CryptoRng>(
71+
pub(crate) fn encrypt<R: TryCryptoRng>(
7272
rng: &mut R,
7373
password: impl AsRef<[u8]>,
7474
doc: &[u8],

pkcs8/src/private_key_info.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ use der::{
2020
};
2121
#[cfg(feature = "encryption")]
2222
use {
23-
crate::EncryptedPrivateKeyInfoRef, der::zeroize::Zeroizing, pkcs5::pbes2, rand_core::CryptoRng,
23+
crate::EncryptedPrivateKeyInfoRef, der::zeroize::Zeroizing, pkcs5::pbes2,
24+
rand_core::TryCryptoRng,
2425
};
2526

2627
/// Context-specific tag number for attributes.
@@ -149,7 +150,7 @@ where
149150
/// - Propagates errors from calling [`Encode::to_der`] on `Self`.
150151
/// - Returns errors in the event encryption failed.
151152
#[cfg(feature = "encryption")]
152-
pub fn encrypt<R: CryptoRng>(
153+
pub fn encrypt<R: TryCryptoRng>(
153154
&self,
154155
rng: &mut R,
155156
password: impl AsRef<[u8]>,

pkcs8/src/traits.rs

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

88
#[cfg(feature = "encryption")]
9-
use {crate::EncryptedPrivateKeyInfoRef, rand_core::CryptoRng};
9+
use {crate::EncryptedPrivateKeyInfoRef, rand_core::TryCryptoRng};
1010

1111
#[cfg(feature = "pem")]
1212
use {
@@ -131,7 +131,7 @@ pub trait EncodePrivateKey {
131131
/// - Returns format-specific errors in the event the document failed to serialize.
132132
/// - Returns algorithm-specific errors in the event the document couldn't be encrypted.
133133
#[cfg(feature = "encryption")]
134-
fn to_pkcs8_encrypted_der<R: CryptoRng>(
134+
fn to_pkcs8_encrypted_der<R: TryCryptoRng>(
135135
&self,
136136
rng: &mut R,
137137
password: impl AsRef<[u8]>,
@@ -157,7 +157,7 @@ pub trait EncodePrivateKey {
157157
/// - Returns the same errors as [`EncodePrivateKey::to_pkcs8_encrypted_der`].
158158
/// - Returns the same errors as [`SecretDocument::to_pem`].
159159
#[cfg(all(feature = "encryption", feature = "pem"))]
160-
fn to_pkcs8_encrypted_pem<R: CryptoRng>(
160+
fn to_pkcs8_encrypted_pem<R: TryCryptoRng>(
161161
&self,
162162
rng: &mut R,
163163
password: impl AsRef<[u8]>,

0 commit comments

Comments
 (0)