Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace once_cell::OnceCell with std::sync::OnceLock. #1246

Merged
merged 2 commits into from
Jan 10, 2025
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
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ kmip = { version = "0.4.3", package = "kmip-protocol", features = [ "
kvx = { version = "0.9.3", features = ["macros"] }
libflate = "2.1.0"
log = "0.4"
once_cell = { version = "1.20.2", optional = true }
openidconnect = { version = "2.5.1", optional = true, default-features = false }
openssl = { version = "0.10", features = ["v110"] }
oso = { version = "0.12", optional = true, default-features = false }
Expand Down Expand Up @@ -78,7 +77,7 @@ syslog = "6.1.1"

[features]
default = ["multi-user", "hsm"]
hsm = ["backoff", "kmip", "once_cell", "cryptoki", "r2d2"]
hsm = ["backoff", "kmip", "cryptoki", "r2d2"]
multi-user = [
"basic-cookies",
"jmespatch/sync",
Expand Down
16 changes: 6 additions & 10 deletions src/commons/crypto/signing/signers/pkcs11/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use cryptoki::{
slot::{Slot, SlotInfo, TokenInfo},
types::AuthPin,
};
use once_cell::sync::OnceCell;
use std::sync::OnceLock;

use crate::commons::crypto::SignerError;

Expand Down Expand Up @@ -80,7 +80,7 @@ impl ThreadSafePkcs11Context {
/// RwLock'd HashMap for this.
type Pkcs11ContextsByFileName =
Arc<RwLock<HashMap<String, ThreadSafePkcs11Context>>>;
static CONTEXTS: OnceCell<Pkcs11ContextsByFileName> = OnceCell::new();
static CONTEXTS: OnceLock<Pkcs11ContextsByFileName> = OnceLock::new();

#[derive(Debug)]
pub(super) struct Pkcs11Context {
Expand All @@ -106,14 +106,10 @@ impl Pkcs11Context {
pub fn get_or_load(
lib_path: &Path,
) -> Result<ThreadSafePkcs11Context, SignerError> {
// Initialize the singleton map of PKCS#11 contexts. Failure here
// should be impossible or else so severe that panicking is
// all we can do.
let contexts = CONTEXTS
.get_or_try_init(|| -> Result<Pkcs11ContextsByFileName, ()> {
Ok(Arc::new(RwLock::new(HashMap::new())))
})
.unwrap();
// Initialize the singleton map of PKCS#11 contexts.
let contexts = CONTEXTS.get_or_init(|| {
Arc::new(RwLock::new(HashMap::new()))
});

// Use the file name of the library as the key into the map, if the
// path represents a file.
Expand Down
Loading