From 2d4c2ef4a1ab2516ed392dc41bcbb51dfcaae86e Mon Sep 17 00:00:00 2001 From: Jeff Burdges Date: Wed, 7 Aug 2019 07:20:26 +0200 Subject: [PATCH] Attempt to resolve this randomness mess --- Cargo.toml | 9 ++++++--- src/lib.rs | 13 +++++++------ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4d49125..31900bf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 @@ -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"] diff --git a/src/lib.rs b/src/lib.rs index 4b2787d..05c6c08 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -231,16 +231,17 @@ fn zeroize_hack(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!!";