Skip to content

Commit 7db7413

Browse files
authored
crypto-common: conditionally re-export getrandom (#2152)
Removes bespoke re-exports and simply re-exports the whole crate, which replaces the following: - `crypto_common::RngError` => `crypto_common::getrandom::Error` - `crypto_common::SysRng` => `crypto_common::getrandom::SysRng`
1 parent 10ddeb0 commit 7db7413

3 files changed

Lines changed: 6 additions & 8 deletions

File tree

crypto-common/src/generate.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
use hybrid_array::{Array, ArraySize};
22
use rand_core::{CryptoRng, TryCryptoRng};
33

4-
#[cfg(feature = "getrandom")]
5-
use crate::RngError;
6-
74
/// Secure random generation.
85
pub trait Generate: Sized {
96
/// Generate random key using the provided [`TryCryptoRng`].
@@ -19,9 +16,10 @@ pub trait Generate: Sized {
1916
/// random number generator.
2017
///
2118
/// # Errors
22-
/// Returns [`RngError`] in the event the system's ambient RNG experiences an internal failure.
19+
/// Returns [`getrandom::Error`] in the event the system's ambient RNG experiences an internal
20+
/// failure.
2321
#[cfg(feature = "getrandom")]
24-
fn try_generate() -> Result<Self, RngError> {
22+
fn try_generate() -> Result<Self, getrandom::Error> {
2523
Self::try_generate_from_rng(&mut getrandom::SysRng)
2624
}
2725

crypto-common/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ mod generate;
1919
pub use hybrid_array as array;
2020
pub use hybrid_array::typenum;
2121

22+
#[cfg(feature = "getrandom")]
23+
pub use getrandom;
2224
#[cfg(feature = "rand_core")]
2325
pub use {generate::Generate, rand_core};
24-
#[cfg(feature = "getrandom")]
25-
pub use {getrandom::Error as RngError, getrandom::SysRng};
2626

2727
use core::fmt;
2828
use hybrid_array::{

kem/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub trait Encapsulate<EK, SS> {
2929
/// Encapsulate a fresh shared secret generated using the system's secure RNG.
3030
#[cfg(feature = "getrandom")]
3131
fn encapsulate(&self) -> Result<(EK, SS), Self::Error> {
32-
self.encapsulate_with_rng(&mut crypto_common::SysRng)
32+
self.encapsulate_with_rng(&mut crypto_common::getrandom::SysRng)
3333
}
3434
}
3535

0 commit comments

Comments
 (0)