Skip to content

Commit

Permalink
avoid baking the RNG seed into the Wizer output (#216)
Browse files Browse the repository at this point in the history
This simply switches from using `rand::thread_rng` to `rand::rngs::OsRng`,
directing all RNG requests straight to the host.  More efficient options are
possible, but I'm keeping things simple for now.

Fixes #215

Signed-off-by: Joel Dice <[email protected]>
  • Loading branch information
dicej authored Dec 14, 2023
1 parent b5bd67a commit c440112
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions crates/spin-js-engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use {
http::{header::HeaderName, request, HeaderValue},
once_cell::sync::{Lazy, OnceCell},
quickjs_wasm_rs::{Context, Deserializer, Exception, Serializer, Value},
rand::{thread_rng, Rng},
rand::{rngs::OsRng, Rng},
send_wrapper::SendWrapper,
serde::{Deserialize, Serialize},
serde_bytes::ByteBuf,
Expand Down Expand Up @@ -265,7 +265,7 @@ fn get_glob(context: &Context, _this: &Value, args: &[Value]) -> Result<Value> {
}

fn get_rand(context: &Context, _this: &Value, _args: &[Value]) -> Result<Value> {
context.value_from_u32(thread_rng().gen_range(0..=255))
context.value_from_u32(OsRng.gen_range(0..=255))
}

fn get_hash(context: &Context, _this: &Value, args: &[Value]) -> Result<Value> {
Expand Down Expand Up @@ -333,7 +333,7 @@ fn get_hmac(context: &Context, _this: &Value, args: &[Value]) -> Result<Value> {
}

fn math_rand(context: &Context, _this: &Value, _args: &[Value]) -> Result<Value> {
context.value_from_f64(thread_rng().gen_range(0.0_f64..1.0))
context.value_from_f64(OsRng.gen_range(0.0_f64..1.0))
}

fn redis_exec(context: &Context, _this: &Value, args: &[Value]) -> Result<Value> {
Expand Down

0 comments on commit c440112

Please sign in to comment.