diff --git a/akd/Cargo.toml b/akd/Cargo.toml index 35719e0d..fe799dbd 100644 --- a/akd/Cargo.toml +++ b/akd/Cargo.toml @@ -68,7 +68,7 @@ colored = { version = "2", optional = true } once_cell = { version = "1", optional = true } paste = { version = "1", optional = true } protobuf = { version = "3", optional = true } -rand = { version = "0.8", optional = true } +rand = { version = "0.9.3", optional = true } serde = { version = "1", features = ["derive"], optional = true } tracing = { version = "0.1.40", optional = true } diff --git a/akd/benches/azks.rs b/akd/benches/azks.rs index 10427dc8..4e13d123 100644 --- a/akd/benches/azks.rs +++ b/akd/benches/azks.rs @@ -203,10 +203,10 @@ fn gen_nodes(rng: &mut impl Rng, num_nodes: usize) -> Vec { (0..num_nodes) .map(|_| { let label = NodeLabel { - label_val: rng.gen::<[u8; 32]>(), + label_val: rng.random::<[u8; 32]>(), label_len: 256, }; - let value = AzksValue(rng.gen::<[u8; 32]>()); + let value = AzksValue(rng.random::<[u8; 32]>()); AzksElement { label, value } }) .collect() diff --git a/akd/benches/directory.rs b/akd/benches/directory.rs index 9c7a155a..d167dcb7 100644 --- a/akd/benches/directory.rs +++ b/akd/benches/directory.rs @@ -17,7 +17,7 @@ use akd::storage::memory::AsyncInMemoryDatabase; use akd::NamedConfiguration; use akd::{AkdLabel, AkdValue, Directory}; use criterion::{BatchSize, Criterion}; -use rand::distributions::Alphanumeric; +use rand::distr::Alphanumeric; use rand::rngs::StdRng; use rand::{Rng, SeedableRng}; @@ -63,8 +63,8 @@ fn history_generation(c: &mut Criterion) { .unwrap(); for _epoch in 1..num_updates { - let value: String = (0..rng.gen_range(10..20)) - .map(|_| rng.sample(&Alphanumeric)) + let value: String = (0..rng.random_range(10..20)) + .map(|_| rng.sample(Alphanumeric)) .map(char::from) .collect(); let data = idata diff --git a/akd/src/storage/tests.rs b/akd/src/storage/tests.rs index b841a364..54304636 100644 --- a/akd/src/storage/tests.rs +++ b/akd/src/storage/tests.rs @@ -18,8 +18,8 @@ use crate::{AkdLabel, AkdValue}; use akd_core::hash::EMPTY_DIGEST; use akd_core::AzksValue; -use rand::distributions::Alphanumeric; -use rand::{thread_rng, Rng}; +use rand::distr::Alphanumeric; +use rand::Rng; use std::time::{Duration, Instant}; type Azks = crate::append_only_zks::Azks; @@ -134,8 +134,8 @@ async fn test_get_and_set_item(storage: &Ns) { async fn test_batch_get_items(storage: &Ns) { let mut rand_users: Vec> = vec![]; for _ in 0..20 { - let str: String = thread_rng() - .sample_iter(&Alphanumeric) + let str: String = rand::rng() + .sample_iter(Alphanumeric) .take(30) .map(char::from) .collect(); @@ -302,8 +302,8 @@ async fn test_batch_get_items(storage: &Ns) { async fn test_transactions(storage: &StorageManager) { let mut rand_users: Vec> = vec![]; for _ in 0..20 { - let str: String = thread_rng() - .sample_iter(&Alphanumeric) + let str: String = rand::rng() + .sample_iter(Alphanumeric) .take(30) .map(char::from) .collect(); @@ -380,15 +380,15 @@ async fn test_transactions(storage: &StorageManager) { } async fn test_user_data(storage: &S) { - let rand_user = thread_rng() - .sample_iter(&Alphanumeric) + let rand_user = rand::rng() + .sample_iter(Alphanumeric) .take(30) .map(char::from) .collect::() .as_bytes() .to_vec(); - let rand_value = thread_rng() - .sample_iter(&Alphanumeric) + let rand_value = rand::rng() + .sample_iter(Alphanumeric) .take(1028) .map(char::from) .collect::() @@ -581,8 +581,8 @@ async fn test_user_data(storage: &S) { async fn test_tombstoning_data( storage: &StorageManager, ) -> Result<(), crate::errors::AkdError> { - let rand_user = thread_rng() - .sample_iter(&Alphanumeric) + let rand_user = rand::rng() + .sample_iter(Alphanumeric) .take(30) .map(char::from) .collect::() diff --git a/akd/src/tests/test_errors.rs b/akd/src/tests/test_errors.rs index d598f18f..786d5442 100644 --- a/akd/src/tests/test_errors.rs +++ b/akd/src/tests/test_errors.rs @@ -415,7 +415,7 @@ async fn test_key_history_verify_malformed() -> Result<(), Ak let akd = Directory::::new(storage, vrf.clone(), AzksParallelismConfig::default()).await?; - let mut rng = rand::rngs::OsRng; + let mut rng = rand::rng(); for _ in 0..100 { let mut updates = vec![]; updates.push(( diff --git a/akd/src/utils.rs b/akd/src/utils.rs index 76fb812a..16352663 100644 --- a/akd/src/utils.rs +++ b/akd/src/utils.rs @@ -24,7 +24,7 @@ pub(crate) fn byte_arr_from_u64(input_int: u64) -> [u8; 32] { #[cfg(any(test, feature = "public_tests"))] pub(crate) fn random_label(rng: &mut impl rand::Rng) -> crate::NodeLabel { crate::NodeLabel { - label_val: rng.gen::<[u8; 32]>(), + label_val: rng.random::<[u8; 32]>(), label_len: 256, } } diff --git a/akd_core/Cargo.toml b/akd_core/Cargo.toml index 1959fbbf..39d642ab 100644 --- a/akd_core/Cargo.toml +++ b/akd_core/Cargo.toml @@ -48,7 +48,7 @@ zeroize = "1" ## Optional dependencies ## blake3 = { version = "1", optional = true, default-features = false } protobuf = { version = "3", optional = true } -rand = { version = "0.8", optional = true } +rand = { version = "0.9.3", optional = true } serde = { version = "1", features = ["derive"], optional = true } serde_bytes = { version = "0.11", optional = true } tokio = { version = "1", features = ["rt"], optional = true } @@ -59,7 +59,7 @@ bincode = "1" itertools = "0.13" proptest = "1" proptest-derive = "0.6" -rand = "0.8" +rand = "0.9.3" serde = { version = "1", features = ["derive"] } criterion = "0.5" diff --git a/akd_core/benches/parallel_vrfs.rs b/akd_core/benches/parallel_vrfs.rs index 454ba8a2..f010a19f 100644 --- a/akd_core/benches/parallel_vrfs.rs +++ b/akd_core/benches/parallel_vrfs.rs @@ -13,7 +13,7 @@ use akd_core::configuration::NamedConfiguration; use akd_core::ecvrf::{VRFExpandedPrivateKey, VRFPublicKey}; use akd_core::VersionFreshness; use akd_core::{ecvrf::VRFKeyStorage, AkdLabel, AkdValue}; -use rand::distributions::Alphanumeric; +use rand::distr::Alphanumeric; use rand::Rng; macro_rules! bench_config { @@ -71,11 +71,11 @@ fn main() { bench_config!(bench_single_vrf); fn bench_single_vrf(c: &mut Criterion) { - let rng = rand::rngs::OsRng; + let mut rng = rand::rng(); // Generate a random label let label = AkdLabel::from( - &rng.sample_iter(&Alphanumeric) + &rng.sample_iter(Alphanumeric) .take(32) .map(char::from) .collect::(), diff --git a/akd_core/src/ecvrf/tests.rs b/akd_core/src/ecvrf/tests.rs index 7f366eaf..6bf22086 100644 --- a/akd_core/src/ecvrf/tests.rs +++ b/akd_core/src/ecvrf/tests.rs @@ -26,7 +26,7 @@ use proptest::prelude::*; use proptest_derive::Arbitrary; #[cfg(feature = "serde_serialization")] use rand::rngs::StdRng; -use rand::{CryptoRng, RngCore}; +use rand::CryptoRng; use serde::{Deserialize, Serialize}; /// A type family for schemes which know how to generate key material from @@ -35,7 +35,7 @@ pub trait Uniform { /// Generate key material from an RNG for testing purposes. fn generate_for_testing(rng: &mut R) -> Self where - R: CryptoRng + RngCore; + R: CryptoRng; } /// Output value of our hash function. Intentionally opaque for safety and modularity. @@ -49,7 +49,7 @@ pub struct HashValue { impl Uniform for VRFPrivateKey { fn generate_for_testing(rng: &mut R) -> Self where - R: CryptoRng + RngCore, + R: CryptoRng, { let mut bytes = [0u8; 32]; rng.fill_bytes(&mut bytes); @@ -86,7 +86,7 @@ where { fn generate_for_testing(rng: &mut R) -> Self where - R: RngCore + CryptoRng, + R: CryptoRng, { let private_key = S::generate_for_testing(rng); private_key.into() diff --git a/akd_core/src/proto/tests.rs b/akd_core/src/proto/tests.rs index 1261867f..7ea93c9e 100644 --- a/akd_core/src/proto/tests.rs +++ b/akd_core/src/proto/tests.rs @@ -10,12 +10,12 @@ use super::specs::types::*; use super::*; use crate::{AzksValue, Direction}; -use rand::{thread_rng, Rng}; +use rand::Rng; // ================= Test helpers ================= // fn random_hash() -> [u8; 32] { - thread_rng().gen::<[u8; 32]>() + rand::rng().random::<[u8; 32]>() } fn random_azks_element() -> crate::AzksElement { @@ -28,7 +28,7 @@ fn random_azks_element() -> crate::AzksElement { fn random_label() -> crate::NodeLabel { let label = crate::NodeLabel { label_val: random_hash(), - label_len: thread_rng().gen::() % 257, // Can be up to 256 + label_len: rand::rng().random::() % 257, // Can be up to 256 }; label.get_prefix(label.label_len) } @@ -114,11 +114,11 @@ fn test_convert_non_membership_proof() { #[test] fn test_convert_lookup_proof() { - let mut rng = thread_rng(); + let mut rng = rand::rng(); let original = crate::LookupProof { - epoch: rng.gen(), + epoch: rng.random(), value: crate::AkdValue(random_hash().to_vec()), - version: rng.gen(), + version: rng.random(), existence_vrf_proof: random_hash().to_vec(), existence_proof: crate::MembershipProof { label: random_label(), @@ -163,11 +163,11 @@ fn test_convert_lookup_proof() { #[test] fn test_convert_update_proof() { - let mut rng = thread_rng(); + let mut rng = rand::rng(); let original = crate::UpdateProof { - epoch: rng.gen(), + epoch: rng.random(), value: crate::AkdValue(random_hash().to_vec()), - version: rng.gen(), + version: rng.random(), existence_vrf_proof: random_hash().to_vec(), existence_proof: crate::MembershipProof { label: random_label(), @@ -213,11 +213,11 @@ fn non_membership_proof() -> crate::NonMembershipProof { } fn upd_proof() -> crate::UpdateProof { - let mut rng = thread_rng(); + let mut rng = rand::rng(); crate::UpdateProof { - epoch: rng.gen(), + epoch: rng.random(), value: crate::AkdValue(random_hash().to_vec()), - version: rng.gen(), + version: rng.random(), existence_vrf_proof: random_hash().to_vec(), existence_proof: crate::MembershipProof { label: random_label(), diff --git a/akd_core/src/types/mod.rs b/akd_core/src/types/mod.rs index 5c8fdefa..24953964 100644 --- a/akd_core/src/types/mod.rs +++ b/akd_core/src/types/mod.rs @@ -27,7 +27,7 @@ use alloc::vec::Vec; #[cfg(feature = "nostd")] use core::cmp::{Ord, Ordering, PartialOrd}; #[cfg(feature = "rand")] -use rand::{CryptoRng, Rng}; +use rand::CryptoRng; #[cfg(not(feature = "nostd"))] use std::cmp::{Ord, Ordering, PartialOrd}; @@ -206,7 +206,7 @@ impl core::convert::From<&String> for AkdLabel { impl AkdLabel { #[cfg(feature = "rand")] /// Gets a random label - pub fn random(rng: &mut R) -> Self { + pub fn random(rng: &mut R) -> Self { let mut bytes = [0u8; 32]; rng.fill_bytes(&mut bytes); Self(bytes.to_vec()) @@ -266,7 +266,7 @@ impl core::convert::From<&String> for AkdValue { impl AkdValue { #[cfg(feature = "rand")] /// Gets a random value for a AKD - pub fn random(rng: &mut R) -> Self { + pub fn random(rng: &mut R) -> Self { let mut bytes = [0u8; 32]; rng.fill_bytes(&mut bytes); Self(bytes.to_vec()) diff --git a/akd_core/src/types/node_label/tests.rs b/akd_core/src/types/node_label/tests.rs index 43013311..c2331442 100644 --- a/akd_core/src/types/node_label/tests.rs +++ b/akd_core/src/types/node_label/tests.rs @@ -11,14 +11,14 @@ use super::*; use crate::test_config_sync; #[cfg(feature = "nostd")] use alloc::vec; -use rand::{thread_rng, Rng}; +use rand::Rng; // ================= Test helpers ================= // fn random_label() -> crate::NodeLabel { - let mut rng = thread_rng(); + let mut rng = rand::rng(); crate::NodeLabel { - label_val: rng.gen::<[u8; 32]>(), + label_val: rng.random::<[u8; 32]>(), label_len: 256, } } diff --git a/akd_core/src/utils.rs b/akd_core/src/utils.rs index 62392758..97e60440 100644 --- a/akd_core/src/utils.rs +++ b/akd_core/src/utils.rs @@ -292,7 +292,7 @@ macro_rules! test_config_sync { mod tests { use super::*; use alloc::vec; - use rand::{rngs::OsRng, Rng}; + use rand::Rng; #[test] fn test_get_marker_versions() { @@ -331,24 +331,24 @@ mod tests { } fn gen_versions( - rng: &mut OsRng, + rng: &mut rand::rngs::ThreadRng, start_type: &RangeType, end_type: &RangeType, epoch_type: &RangeType, ) -> (u64, u64, u64) { let small_jump = 10; let medium_jump = 1000; - let start_version: u64 = rng.gen_range(match start_type { + let start_version: u64 = rng.random_range(match start_type { RangeType::Small => 1..small_jump, RangeType::Medium => 1..medium_jump, RangeType::Large => 1..u64::MAX - 2 * (small_jump + medium_jump), }); - let end_version: u64 = rng.gen_range(match end_type { + let end_version: u64 = rng.random_range(match end_type { RangeType::Small => start_version..start_version + small_jump, RangeType::Medium => start_version..start_version + medium_jump, RangeType::Large => start_version..u64::MAX - small_jump - medium_jump, }); - let epoch: u64 = rng.gen_range(match epoch_type { + let epoch: u64 = rng.random_range(match epoch_type { RangeType::Small => end_version..end_version + small_jump, RangeType::Medium => end_version..end_version + medium_jump, RangeType::Large => end_version..u64::MAX, @@ -362,7 +362,7 @@ mod tests { let iterations = 10000; let options = [RangeType::Small, RangeType::Medium, RangeType::Large]; - let mut rng = OsRng; + let mut rng = rand::rng(); for (start_type, end_type, epoch_type) in itertools::iproduct!(&options, &options, &options) { for _ in 0..iterations { diff --git a/examples/Cargo.toml b/examples/Cargo.toml index ba2f05fe..b7073b7e 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -32,7 +32,7 @@ mysql_async = "0.32" mysql_common = "0.31" once_cell = "1" protobuf = "3" -rand = "0.8" +rand = "0.9.3" serde = { version = "1", features = ["derive"] } serde_json = "1" thread-id = "4" diff --git a/examples/src/fixture_generator/generator.rs b/examples/src/fixture_generator/generator.rs index 835ecd45..63eda224 100644 --- a/examples/src/fixture_generator/generator.rs +++ b/examples/src/fixture_generator/generator.rs @@ -152,7 +152,7 @@ pub(crate) async fn generate(args: &Args // generate random key updates if allowed if !args.no_generated_updates { - let num_updates = rng.gen_range(args.min_updates..args.max_updates); + let num_updates = rng.random_range(args.min_updates..args.max_updates); for _ in updates.len()..num_updates as usize { updates.push((AkdLabel::random(&mut rng), AkdValue::random(&mut rng))); } diff --git a/examples/src/mysql_demo/mod.rs b/examples/src/mysql_demo/mod.rs index 29d15c7a..a9c7c7d3 100644 --- a/examples/src/mysql_demo/mod.rs +++ b/examples/src/mysql_demo/mod.rs @@ -15,7 +15,7 @@ use clap::{Parser, ValueEnum}; use commands::Command; use log::{debug, error, info, warn}; use mysql::AsyncMySqlDatabase; -use rand::distributions::Alphanumeric; +use rand::distr::Alphanumeric; use rand::rngs::StdRng; use rand::{Rng, SeedableRng}; use std::convert::From; @@ -226,7 +226,7 @@ async fn process_input( for i in 0..*num_users { values.push( StdRng::seed_from_u64(i) - .sample_iter(&Alphanumeric) + .sample_iter(Alphanumeric) .take(30) .map(char::from) .collect(), @@ -271,7 +271,7 @@ async fn process_input( let users: Vec = (1..=*num_users) .map(|i| { StdRng::seed_from_u64(i) - .sample_iter(&Alphanumeric) + .sample_iter(Alphanumeric) .take(256) .map(char::from) .collect() @@ -280,7 +280,7 @@ async fn process_input( let data: Vec = (1..=*num_updates_per_user) .map(|i| { StdRng::seed_from_u64(i) - .sample_iter(&Alphanumeric) + .sample_iter(Alphanumeric) .take(1024) .map(char::from) .collect() @@ -343,12 +343,12 @@ async fn process_input( .map(|i| { ( StdRng::seed_from_u64(i) - .sample_iter(&Alphanumeric) + .sample_iter(Alphanumeric) .take(256) .map(char::from) .collect(), StdRng::seed_from_u64(i) - .sample_iter(&Alphanumeric) + .sample_iter(Alphanumeric) .take(1024) .map(char::from) .collect(), diff --git a/examples/src/mysql_demo/tests/test_util.rs b/examples/src/mysql_demo/tests/test_util.rs index e3fccca9..e935c3c1 100644 --- a/examples/src/mysql_demo/tests/test_util.rs +++ b/examples/src/mysql_demo/tests/test_util.rs @@ -16,9 +16,9 @@ use akd::HistoryParams; use akd::{AkdLabel, AkdValue}; use log::{info, Level, Metadata, Record}; use once_cell::sync::OnceCell; -use rand::distributions::Alphanumeric; +use rand::distr::Alphanumeric; use rand::seq::IteratorRandom; -use rand::{thread_rng, Rng}; +use rand::Rng; use std::fs::File; use std::io; use std::io::Write; @@ -131,13 +131,13 @@ pub(crate) async fn test_lookups = vec![]; for _ in 0..num_users { users.push( - thread_rng() - .sample_iter(&Alphanumeric) + rand::rng() + .sample_iter(Alphanumeric) .take(30) .map(char::from) .collect(), @@ -271,13 +271,13 @@ pub(crate) async fn directory_test_suite< vrf: &V, ) { // generate the test data - let mut rng = thread_rng(); + let mut rng = rand::rng(); let mut users: Vec = vec![]; for _ in 0..num_users { users.push( - thread_rng() - .sample_iter(&Alphanumeric) + rand::rng() + .sample_iter(Alphanumeric) .take(30) .map(char::from) .collect(),