Skip to content

Commit

Permalink
Attempt to resolve this randomness mess
Browse files Browse the repository at this point in the history
  • Loading branch information
burdges committed Aug 7, 2019
1 parent 99808bc commit 2d4c2ef
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
9 changes: 6 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ default-features = false
[dependencies.rand_os]
version = "0.1.3" # 0.2
default-features = false
optional = true

[dependencies.rand_chacha]
version = "0.1" # 0.2
Expand Down Expand Up @@ -88,10 +89,12 @@ harness = false
[features]
default = ["std", "u64_backend", "rand"] # "chacha"
preaudit_deprecated = []
chacha = ["rand_chacha"]
std = ["curve25519-dalek/std", "rand/std"] # "failure/std"
alloc = ["curve25519-dalek/alloc"]
nightly = ["curve25519-dalek/nightly", "rand/nightly"] # "zeroize/nightly"
alloc = ["curve25519-dalek/alloc", "rand_core/alloc"]
chacha = ["rand_chacha"]
std = ["rand_os", "curve25519-dalek/std", "rand/std"] # "failure/std"
stdweb = ["rand_os/stdweb"]
wasm-bindgen = ["rand_os/wasm-bindgen"]
asm = ["sha2/asm"]
yolocrypto = ["curve25519-dalek/yolocrypto"]
u64_backend = ["curve25519-dalek/u64_backend", "ed25519-dalek/u64_backend"]
Expand Down
13 changes: 7 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,16 +231,17 @@ fn zeroize_hack<Z: Default>(z: &mut Z) {

use rand_core::{RngCore,CryptoRng};

#[cfg(feature = "std")]
#[cfg(all(feature = "std", feature = "rand"))]
fn rand_hack() -> impl RngCore+CryptoRng {
#[cfg(feature = "rand")]
{ ::rand::thread_rng() }
::rand::thread_rng()
}

#[cfg(not(feature = "rand"))]
{ ::rand_os::OsRng::new() }
#[cfg(all(feature = "rand_os", not(feature = "rand")))]
fn rand_hack() -> impl RngCore+CryptoRng {
::rand_os::OsRng::new().unwrap()
}

#[cfg(not(feature = "std"))]
#[cfg(not(feature = "rand_os"))]
fn rand_hack() -> impl RngCore+CryptoRng {
const PRM : &'static str = "Attempted to use functionality that requires system randomness!!";

Expand Down

0 comments on commit 2d4c2ef

Please sign in to comment.