Skip to content

Commit 94aae05

Browse files
committed
Remove lazy_static dependency for std lib once-cell. Addl cleanup / fixes.
1 parent 92c7691 commit 94aae05

File tree

8 files changed

+52
-47
lines changed

8 files changed

+52
-47
lines changed

Cargo.lock

Lines changed: 6 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ keywords = ["bitcoin", "pqc", "cryptography", "bip-360", "qubit"]
1010

1111
[dependencies]
1212
hex = "0.4"
13-
lazy_static = "1.5.0"
1413
libc = "0.2"
1514
bitmask-enum = "2.2.5"
1615

benches/sig_benchmarks.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
1-
use criterion::{criterion_group, criterion_main, Criterion};
2-
use lazy_static::lazy_static;
3-
use rand::{rng, RngCore};
41
use std::collections::HashMap;
52
use std::fs::File;
63
use std::io::Write;
74
use std::sync::Mutex;
5+
use std::sync::OnceLock;
86
use std::time::Duration;
97

8+
use criterion::{criterion_group, criterion_main, Criterion};
9+
use rand::{rng, RngCore};
10+
1011
use bitcoinpqc::{generate_keypair, sign, verify, Algorithm};
1112

1213
// Set to true to enable debug output, false to disable
1314
const DEBUG_MODE: bool = false;
1415

1516
// Global storage for sizes
16-
lazy_static! {
17-
static ref SIZE_RESULTS: Mutex<HashMap<String, usize>> = Mutex::new(HashMap::new());
17+
static SIZE_RESULTS: OnceLock<Mutex<HashMap<String, usize>>> = OnceLock::new();
18+
19+
// Helper function to get or initialize the size results
20+
fn get_size_results() -> &'static Mutex<HashMap<String, usize>> {
21+
SIZE_RESULTS.get_or_init(|| Mutex::new(HashMap::new()))
1822
}
1923

2024
// Conditional debug print macro
@@ -40,7 +44,8 @@ fn configure_group(group: &mut criterion::BenchmarkGroup<criterion::measurement:
4044

4145
// Helper function to store size results
4246
fn store_size_result(name: &str, value: usize) {
43-
let mut results = SIZE_RESULTS.lock().unwrap();
47+
let results = get_size_results();
48+
let mut results = results.lock().unwrap();
4449
results.insert(name.to_string(), value);
4550
}
4651

@@ -295,7 +300,8 @@ fn generate_report(_c: &mut Criterion) {
295300
writeln!(file, "\nThis report compares the performance and size characteristics of post-quantum cryptographic algorithms with secp256k1.\n").unwrap();
296301

297302
// Get size results
298-
let size_results = SIZE_RESULTS.lock().unwrap();
303+
let size_results = get_size_results();
304+
let size_results = size_results.lock().unwrap();
299305

300306
// Extract secp256k1 size values
301307
let secp_pubkey_size = size_results.get("secp256k1_pubkey").cloned().unwrap_or(32);

fuzz/Cargo.lock

Lines changed: 24 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fuzz/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ cargo-fuzz = true
1010
[dependencies]
1111
libfuzzer-sys = "0.4"
1212

13-
[dependencies.libbitcoinpqc]
13+
[dependencies.bitcoinpqc]
1414
path = ".."
1515

1616
# Renamed and repurposed from the original target

src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
#![allow(non_camel_case_types)]
33
#![allow(non_snake_case)]
44

5-
use bitmask_enum::bitmask;
6-
75
use std::error::Error;
86
use std::fmt;
97
use std::ptr;
8+
9+
use bitmask_enum::bitmask;
10+
1011
// Include the auto-generated bindings using our wrapper
1112
// Make it pub(crate) so doctests can access these symbols
1213
pub(crate) mod bindings_include;

tests/algorithm_tests.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
use hex::decode as hex_decode;
2+
use rand::{rng, RngCore};
3+
14
use bitcoinpqc::{
25
generate_keypair, public_key_size, secret_key_size, sign, signature_size, verify, Algorithm,
36
};
4-
use hex::decode as hex_decode;
5-
use rand::{rng, RngCore};
67

78
// Original random data generation function (commented out for deterministic tests)
89
fn _get_random_bytes_original(size: usize) -> Vec<u8> {

tests/serialization_tests.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use bitcoinpqc::{generate_keypair, sign, verify, Algorithm, PublicKey, SecretKey, Signature};
21
use hex::{decode as hex_decode, encode as hex_encode};
32
use rand::{rng, RngCore};
43

4+
use bitcoinpqc::{generate_keypair, sign, verify, Algorithm, PublicKey, SecretKey, Signature};
5+
56
// Original random data generation function (commented out for deterministic tests)
67
fn _get_random_bytes_original(size: usize) -> Vec<u8> {
78
let mut bytes = vec![0u8; size];

0 commit comments

Comments
 (0)