Skip to content

Commit

Permalink
Replace once_cell::OnceCell with std::sync::OnceLock. (#1246)
Browse files Browse the repository at this point in the history
This PR removes the dependency on once_cell since all the relevant functionality is now in std.
  • Loading branch information
partim authored Jan 10, 2025
1 parent c13d44f commit 9ef5e22
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
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 @@ -39,7 +39,6 @@ jmespatch = { version = "0.3", features = ["sync"], optional = true }
kmip = { version = "0.4.3", package = "kmip-protocol", features = [ "tls-with-openssl" ], optional = true }
kvx = { version = "0.9.3", features = ["macros"] }
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 @@ -76,7 +75,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

0 comments on commit 9ef5e22

Please sign in to comment.