From a50016b3da4dd8ae66e2467f542fa38bc8b8d038 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 7 Jun 2023 17:24:46 +0100 Subject: [PATCH] tor-hscrypto: implement Rng.gen() for RendCookie --- Cargo.lock | 1 + crates/tor-hscrypto/Cargo.toml | 1 + crates/tor-hscrypto/src/lib.rs | 6 ++++++ 3 files changed, 8 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index d5f82b4d4..adadf7e48 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4197,6 +4197,7 @@ dependencies = [ "humantime 2.1.0", "itertools", "paste", + "rand 0.8.5", "rand_core 0.6.4", "safelog", "serde", diff --git a/crates/tor-hscrypto/Cargo.toml b/crates/tor-hscrypto/Cargo.toml index d93ecff38..260e1854f 100644 --- a/crates/tor-hscrypto/Cargo.toml +++ b/crates/tor-hscrypto/Cargo.toml @@ -21,6 +21,7 @@ derive_more = "0.99.3" digest = "0.10.0" itertools = "0.10.1" paste = "1" +rand = "0.8" rand_core = "0.6.2" safelog = { path = "../safelog", version = "0.3.1" } serde = { version = "1.0.103", features = ["derive"] } diff --git a/crates/tor-hscrypto/src/lib.rs b/crates/tor-hscrypto/src/lib.rs index 484c07990..a5e34b6bd 100644 --- a/crates/tor-hscrypto/src/lib.rs +++ b/crates/tor-hscrypto/src/lib.rs @@ -91,3 +91,9 @@ define_bytes! { #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub struct RendCookie([u8; REND_COOKIE_LEN]); } + +impl rand::distributions::Distribution for rand::distributions::Standard { + fn sample(&self, rng: &mut R) -> RendCookie { + RendCookie(rng.gen::<[u8; REND_COOKIE_LEN]>().into()) + } +}