Switch from lazy_static to once_cell (#442)

The latter will hopefully eventually be upstreamed into `std`.
This commit is contained in:
Tony Arcieri (iqlusion)
2022-11-14 13:52:27 -07:00
committed by GitHub
parent 57bb088c7d
commit 5c4259023f
5 changed files with 15 additions and 22 deletions
Generated
+2 -2
View File
@@ -1277,12 +1277,12 @@ dependencies = [
"elliptic-curve", "elliptic-curve",
"env_logger", "env_logger",
"hmac", "hmac",
"lazy_static",
"log", "log",
"nom", "nom",
"num-bigint-dig", "num-bigint-dig",
"num-integer", "num-integer",
"num-traits", "num-traits",
"once_cell",
"p256", "p256",
"p384", "p384",
"pbkdf2", "pbkdf2",
@@ -1307,8 +1307,8 @@ version = "0.6.0"
dependencies = [ dependencies = [
"clap", "clap",
"env_logger", "env_logger",
"lazy_static",
"log", "log",
"once_cell",
"sha2", "sha2",
"subtle-encoding", "subtle-encoding",
"termcolor", "termcolor",
+1 -1
View File
@@ -49,7 +49,7 @@ zeroize = "1"
[dev-dependencies] [dev-dependencies]
env_logger = "0.9" env_logger = "0.9"
lazy_static = "1" once_cell = "1"
rsa = { version = "0.7.1", features = ["hazmat"] } rsa = { version = "0.7.1", features = ["hazmat"] }
signature = { version = "1.6.4", features = ["hazmat-preview"] } signature = { version = "1.6.4", features = ["hazmat-preview"] }
+1 -1
View File
@@ -17,8 +17,8 @@ rust-version = "1.56"
[dependencies] [dependencies]
clap = { version = "4", features = ["derive"] } clap = { version = "4", features = ["derive"] }
env_logger = "0.9" env_logger = "0.9"
lazy_static = "1"
log = "0.4" log = "0.4"
once_cell = "1"
sha2 = "0.10" sha2 = "0.10"
subtle-encoding = "0.5" subtle-encoding = "0.5"
termcolor = "1" termcolor = "1"
+7 -9
View File
@@ -1,7 +1,7 @@
//! Status messages //! Status messages
use lazy_static::lazy_static;
use log::debug; use log::debug;
use once_cell::sync::Lazy;
use sha2::{Digest, Sha256}; use sha2::{Digest, Sha256};
use std::{ use std::{
io::{self, Write}, io::{self, Write},
@@ -59,16 +59,14 @@ macro_rules! status_err {
}; };
} }
lazy_static! { /// Color configuration
/// Color configuration static COLOR_CHOICE: Lazy<Mutex<Option<ColorChoice>>> = Lazy::new(|| Mutex::new(None));
static ref COLOR_CHOICE: Mutex<Option<ColorChoice>> = Mutex::new(None);
/// Standard output /// Standard output
pub static ref STDOUT: StandardStream = StandardStream::stdout(get_color_choice()); pub static STDOUT: Lazy<StandardStream> = Lazy::new(|| StandardStream::stdout(get_color_choice()));
/// Standard error /// Standard error
pub static ref STDERR: StandardStream = StandardStream::stderr(get_color_choice()); pub static STDERR: Lazy<StandardStream> = Lazy::new(|| StandardStream::stderr(get_color_choice()));
}
/// Obtain the color configuration. /// Obtain the color configuration.
/// ///
+4 -9
View File
@@ -3,8 +3,8 @@
#![forbid(unsafe_code)] #![forbid(unsafe_code)]
#![warn(missing_docs, rust_2018_idioms, trivial_casts, unused_qualifications)] #![warn(missing_docs, rust_2018_idioms, trivial_casts, unused_qualifications)]
use lazy_static::lazy_static;
use log::trace; use log::trace;
use once_cell::sync::Lazy;
use rand_core::{OsRng, RngCore}; use rand_core::{OsRng, RngCore};
use rsa::pkcs1v15; use rsa::pkcs1v15;
use sha2::{Digest, Sha256}; use sha2::{Digest, Sha256};
@@ -18,13 +18,7 @@ use yubikey::{
Error, MgmKey, PinPolicy, Serial, TouchPolicy, YubiKey, Error, MgmKey, PinPolicy, Serial, TouchPolicy, YubiKey,
}; };
lazy_static! { static YUBIKEY: Lazy<Mutex<YubiKey>> = Lazy::new(|| {
/// Provide thread-safe access to a YubiKey
static ref YUBIKEY: Mutex<YubiKey> = init_yubikey();
}
/// One-time test initialization and setup
fn init_yubikey() -> Mutex<YubiKey> {
// Only show logs if `RUST_LOG` is set // Only show logs if `RUST_LOG` is set
if env::var("RUST_LOG").is_ok() { if env::var("RUST_LOG").is_ok() {
env_logger::builder().format_timestamp(None).init(); env_logger::builder().format_timestamp(None).init();
@@ -36,11 +30,12 @@ fn init_yubikey() -> Mutex<YubiKey> {
} else { } else {
YubiKey::open().unwrap() YubiKey::open().unwrap()
}; };
trace!("serial: {}", yubikey.serial()); trace!("serial: {}", yubikey.serial());
trace!("version: {}", yubikey.version()); trace!("version: {}", yubikey.version());
Mutex::new(yubikey) Mutex::new(yubikey)
} });
// //
// CCCID support // CCCID support