Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion akd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
4 changes: 2 additions & 2 deletions akd/benches/azks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,10 @@ fn gen_nodes(rng: &mut impl Rng, num_nodes: usize) -> Vec<AzksElement> {
(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()
Expand Down
6 changes: 3 additions & 3 deletions akd/benches/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -63,8 +63,8 @@ fn history_generation<TC: NamedConfiguration>(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
Expand Down
24 changes: 12 additions & 12 deletions akd/src/storage/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -134,8 +134,8 @@ async fn test_get_and_set_item<Ns: Database>(storage: &Ns) {
async fn test_batch_get_items<Ns: Database>(storage: &Ns) {
let mut rand_users: Vec<Vec<u8>> = 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();
Expand Down Expand Up @@ -302,8 +302,8 @@ async fn test_batch_get_items<Ns: Database>(storage: &Ns) {
async fn test_transactions<S: Database>(storage: &StorageManager<S>) {
let mut rand_users: Vec<Vec<u8>> = 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();
Expand Down Expand Up @@ -380,15 +380,15 @@ async fn test_transactions<S: Database>(storage: &StorageManager<S>) {
}

async fn test_user_data<S: Database>(storage: &S) {
let rand_user = thread_rng()
.sample_iter(&Alphanumeric)
let rand_user = rand::rng()
.sample_iter(Alphanumeric)
.take(30)
.map(char::from)
.collect::<String>()
.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::<String>()
Expand Down Expand Up @@ -581,8 +581,8 @@ async fn test_user_data<S: Database>(storage: &S) {
async fn test_tombstoning_data<S: Database>(
storage: &StorageManager<S>,
) -> 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::<String>()
Expand Down
2 changes: 1 addition & 1 deletion akd/src/tests/test_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
manager::StorageManager, memory::AsyncInMemoryDatabase, types::DbRecord, types::ValueState,
Database,
},
test_config,

Check warning on line 27 in akd/src/tests/test_errors.rs

View workflow job for this annotation

GitHub Actions / Test the base library, enabling runtime metrics processing

unused import: `test_config`

Check warning on line 27 in akd/src/tests/test_errors.rs

View workflow job for this annotation

GitHub Actions / Test the base library, with default features

unused import: `test_config`

Check warning on line 27 in akd/src/tests/test_errors.rs

View workflow job for this annotation

GitHub Actions / benches (Build the akd benches, akd, -F bench)

unused import: `test_config`

Check warning on line 27 in akd/src/tests/test_errors.rs

View workflow job for this annotation

GitHub Actions / Coverage using xtask (ubuntu-latest, stable)

unused import: `test_config`
tests::{setup_mocked_db, MockLocalDatabase},
AkdLabel, AkdValue, Azks, EpochHash, HistoryParams, HistoryVerificationParams, NodeLabel,
};
Expand Down Expand Up @@ -415,7 +415,7 @@
let akd =
Directory::<TC, _, _>::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((
Expand Down
2 changes: 1 addition & 1 deletion akd/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand Down
4 changes: 2 additions & 2 deletions akd_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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"

Expand Down
6 changes: 3 additions & 3 deletions akd_core/benches/parallel_vrfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
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 {
Expand Down Expand Up @@ -71,11 +71,11 @@

bench_config!(bench_single_vrf);
fn bench_single_vrf<TC: NamedConfiguration>(c: &mut Criterion) {
let rng = rand::rngs::OsRng;
let mut rng = rand::rng();

Check warning on line 74 in akd_core/benches/parallel_vrfs.rs

View workflow job for this annotation

GitHub Actions / benches (Build the akd_core benches, akd_core, -F bench)

variable does not need to be mutable

// Generate a random label
let label = AkdLabel::from(
&rng.sample_iter(&Alphanumeric)
&rng.sample_iter(Alphanumeric)
.take(32)
.map(char::from)
.collect::<String>(),
Expand Down
8 changes: 4 additions & 4 deletions akd_core/src/ecvrf/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,30 @@
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
/// a cryptographically-secure [`CryptoRng`][::rand::CryptoRng].
pub trait Uniform {

Check warning on line 34 in akd_core/src/ecvrf/tests.rs

View workflow job for this annotation

GitHub Actions / Test the core crate (akd_core) with no standard library

trait `Uniform` is never used

Check warning on line 34 in akd_core/src/ecvrf/tests.rs

View workflow job for this annotation

GitHub Actions / Test the core crate (akd_core)

trait `Uniform` is never used

Check warning on line 34 in akd_core/src/ecvrf/tests.rs

View workflow job for this annotation

GitHub Actions / benches (Build the akd_core benches, akd_core, -F bench)

trait `Uniform` is never used
/// Generate key material from an RNG for testing purposes.
fn generate_for_testing<R>(rng: &mut R) -> Self
where
R: CryptoRng + RngCore;
R: CryptoRng;
}

/// Output value of our hash function. Intentionally opaque for safety and modularity.
#[derive(
Clone, Copy, Eq, Hash, PartialEq, Serialize, Deserialize, PartialOrd, Ord, Arbitrary, Debug,
)]
pub struct HashValue {

Check warning on line 45 in akd_core/src/ecvrf/tests.rs

View workflow job for this annotation

GitHub Actions / Test the core crate (akd_core) with no standard library

struct `HashValue` is never constructed

Check warning on line 45 in akd_core/src/ecvrf/tests.rs

View workflow job for this annotation

GitHub Actions / Test the core crate (akd_core)

struct `HashValue` is never constructed

Check warning on line 45 in akd_core/src/ecvrf/tests.rs

View workflow job for this annotation

GitHub Actions / benches (Build the akd_core benches, akd_core, -F bench)

struct `HashValue` is never constructed
pub(crate) hash: [u8; 32],
}

impl Uniform for VRFPrivateKey {
fn generate_for_testing<R>(rng: &mut R) -> Self
where
R: CryptoRng + RngCore,
R: CryptoRng,
{
let mut bytes = [0u8; 32];
rng.fill_bytes(&mut bytes);
Expand All @@ -59,7 +59,7 @@

/// A keypair consisting of a private and public key
#[derive(Clone)]
pub struct KeyPair<S, P>

Check warning on line 62 in akd_core/src/ecvrf/tests.rs

View workflow job for this annotation

GitHub Actions / Test the core crate (akd_core) with no standard library

struct `KeyPair` is never constructed

Check warning on line 62 in akd_core/src/ecvrf/tests.rs

View workflow job for this annotation

GitHub Actions / Test the core crate (akd_core)

struct `KeyPair` is never constructed

Check warning on line 62 in akd_core/src/ecvrf/tests.rs

View workflow job for this annotation

GitHub Actions / benches (Build the akd_core benches, akd_core, -F bench)

struct `KeyPair` is never constructed
where
for<'a> P: From<&'a S>,
{
Expand All @@ -86,7 +86,7 @@
{
fn generate_for_testing<R>(rng: &mut R) -> Self
where
R: RngCore + CryptoRng,
R: CryptoRng,
{
let private_key = S::generate_for_testing(rng);
private_key.into()
Expand Down
24 changes: 12 additions & 12 deletions akd_core/src/proto/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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::<u32>() % 257, // Can be up to 256
label_len: rand::rng().random::<u32>() % 257, // Can be up to 256
};
label.get_prefix(label.label_len)
}
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down
6 changes: 3 additions & 3 deletions akd_core/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -206,7 +206,7 @@ impl core::convert::From<&String> for AkdLabel {
impl AkdLabel {
#[cfg(feature = "rand")]
/// Gets a random label
pub fn random<R: CryptoRng + Rng>(rng: &mut R) -> Self {
pub fn random<R: CryptoRng>(rng: &mut R) -> Self {
let mut bytes = [0u8; 32];
rng.fill_bytes(&mut bytes);
Self(bytes.to_vec())
Expand Down Expand Up @@ -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<R: CryptoRng + Rng>(rng: &mut R) -> Self {
pub fn random<R: CryptoRng>(rng: &mut R) -> Self {
let mut bytes = [0u8; 32];
rng.fill_bytes(&mut bytes);
Self(bytes.to_vec())
Expand Down
6 changes: 3 additions & 3 deletions akd_core/src/types/node_label/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand Down
12 changes: 6 additions & 6 deletions akd_core/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion examples/src/fixture_generator/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ pub(crate) async fn generate<TC: NamedConfiguration, L: DomainLabel>(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)));
}
Expand Down
Loading
Loading