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",
"env_logger",
"hmac",
"lazy_static",
"log",
"nom",
"num-bigint-dig",
"num-integer",
"num-traits",
"once_cell",
"p256",
"p384",
"pbkdf2",
@@ -1307,8 +1307,8 @@ version = "0.6.0"
dependencies = [
"clap",
"env_logger",
"lazy_static",
"log",
"once_cell",
"sha2",
"subtle-encoding",
"termcolor",
+1 -1
View File
@@ -49,7 +49,7 @@ zeroize = "1"
[dev-dependencies]
env_logger = "0.9"
lazy_static = "1"
once_cell = "1"
rsa = { version = "0.7.1", features = ["hazmat"] }
signature = { version = "1.6.4", features = ["hazmat-preview"] }
+1 -1
View File
@@ -17,8 +17,8 @@ rust-version = "1.56"
[dependencies]
clap = { version = "4", features = ["derive"] }
env_logger = "0.9"
lazy_static = "1"
log = "0.4"
once_cell = "1"
sha2 = "0.10"
subtle-encoding = "0.5"
termcolor = "1"
+4 -6
View File
@@ -1,7 +1,7 @@
//! Status messages
use lazy_static::lazy_static;
use log::debug;
use once_cell::sync::Lazy;
use sha2::{Digest, Sha256};
use std::{
io::{self, Write},
@@ -59,16 +59,14 @@ macro_rules! status_err {
};
}
lazy_static! {
/// Color configuration
static ref COLOR_CHOICE: Mutex<Option<ColorChoice>> = Mutex::new(None);
static COLOR_CHOICE: Lazy<Mutex<Option<ColorChoice>>> = Lazy::new(|| Mutex::new(None));
/// 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
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.
///
+4 -9
View File
@@ -3,8 +3,8 @@
#![forbid(unsafe_code)]
#![warn(missing_docs, rust_2018_idioms, trivial_casts, unused_qualifications)]
use lazy_static::lazy_static;
use log::trace;
use once_cell::sync::Lazy;
use rand_core::{OsRng, RngCore};
use rsa::pkcs1v15;
use sha2::{Digest, Sha256};
@@ -18,13 +18,7 @@ use yubikey::{
Error, MgmKey, PinPolicy, Serial, TouchPolicy, YubiKey,
};
lazy_static! {
/// 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> {
static YUBIKEY: Lazy<Mutex<YubiKey>> = Lazy::new(|| {
// Only show logs if `RUST_LOG` is set
if env::var("RUST_LOG").is_ok() {
env_logger::builder().format_timestamp(None).init();
@@ -36,11 +30,12 @@ fn init_yubikey() -> Mutex<YubiKey> {
} else {
YubiKey::open().unwrap()
};
trace!("serial: {}", yubikey.serial());
trace!("version: {}", yubikey.version());
Mutex::new(yubikey)
}
});
//
// CCCID support