Skip to content

Commit

Permalink
Replaces rand_core::OsRng with rand::thread_rng()
Browse files Browse the repository at this point in the history
  • Loading branch information
¨Jeff committed Sep 6, 2023
1 parent bae7614 commit 6bd03e6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "schnorrkel"
version = "0.11.0"
version = "0.11.1"
authors = ["Jeff Burdges <[email protected]>"]
readme = "README.md"
license = "BSD-3-Clause"
Expand All @@ -21,6 +21,7 @@ curve25519-dalek = { version = "4.1.0", default-features = false, features = ["d
subtle = { version = "2.5.0", default-features = false }
merlin = { version = "3.0.0", default-features = false }
rand_core = { version = "0.6.2", default-features = false }
rand = { version = "0.8.5", default-features = false, features = ["std_rng"], optional = true }
serde_crate = { version = "1.0.130", package = "serde", default-features = false, optional = true }
serde_bytes = { version = "0.11.5", default-features = false, optional = true }
cfg-if = { version = "1.0.0", optional = true }
Expand All @@ -46,12 +47,12 @@ default = ["std", "getrandom"]
preaudit_deprecated = []
nightly = []
alloc = ["curve25519-dalek/alloc", "rand_core/alloc", "serde_bytes/alloc"]
std = ["alloc", "getrandom", "serde_bytes/std"]
std = ["alloc", "getrandom", "serde_bytes/std", "rand"]
asm = ["sha2/asm"]
serde = ["serde_crate", "serde_bytes", "cfg-if"]
# We cannot make getrandom a direct dependency because rand_core makes
# getrandom a feature name, which requires forwarding.
getrandom = ["rand_core/getrandom"]
getrandom = ["rand_core/getrandom", "rand/std_rng"]
# We thus cannot forward the wasm-bindgen feature of getrandom,
# but our consumers could depend upon getrandom and activate its
# wasm-bindgen feature themselve, which works due to cargo features
Expand Down
7 changes: 6 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,16 @@ extern crate alloc;
use rand_core::{RngCore,CryptoRng};
use curve25519_dalek::scalar::Scalar;

#[cfg(feature = "getrandom")]
#[cfg(all( feature = "getrandom", not(feature = "std") ))]
fn rand_hack() -> impl RngCore+CryptoRng {
rand_core::OsRng
}

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

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

0 comments on commit 6bd03e6

Please sign in to comment.