tor-netdir: Use reproducible RNG in tests.

The rand crate's documentation says it's not okay to rely on StdRng
having reproducible output.  So instead, let's switch to ChaCha12Rng
instead (which is what StrRng currently uses).
This commit is contained in:
Nick Mathewson 2021-12-06 15:06:34 -05:00
parent 31b385c5b2
commit d33d7f7fdd
3 changed files with 4 additions and 5 deletions

1
Cargo.lock generated
View File

@ -2755,6 +2755,7 @@ dependencies = [
"hex",
"hex-literal",
"rand 0.8.4",
"rand_chacha 0.3.1",
"serde",
"signature",
"thiserror",

View File

@ -47,3 +47,4 @@ tracing = "0.1.26"
hex = "0.4.3"
hex-literal = "0.3.1"
tor-netdoc = { path="../tor-netdoc", version = "0.0.2", features=["build_docs"] }
rand_chacha = "0.3.1"

View File

@ -16,12 +16,9 @@ mod imp {
pub(crate) fn get_rng() -> impl rand::Rng {
// When stochastic tests aren't enabled, we use a RNG seeded
// with a fixed value and a small number of iterators for each test.
//
// XXXX: Note that the StdRng is not guaranteed to be
// reproducible across rust stdlib versions; an upgrade might break
// these tests.
use rand::SeedableRng;
rand::rngs::StdRng::from_seed(
// Use this RNG to make the tests reproducible.
rand_chacha::ChaCha12Rng::from_seed(
// Fun facts:
// The Julius Tote was a mechanical computer and point-of-sale
// system from the 1920s that used horses as an RNG.