Backed out changeset 8feed89ecea4 (bug 1787268) for causing build bustages. CLOSED TREE

This commit is contained in:
Iulian Moraru 2022-08-27 01:31:43 +03:00
parent c49ba6a8f8
commit 26ac918f96
3 changed files with 12 additions and 9 deletions

1
Cargo.lock generated
View File

@ -2688,6 +2688,7 @@ name = "ipcclientcerts-static"
version = "0.1.0"
dependencies = [
"byteorder",
"once_cell",
"pkcs11",
"rsclientcerts",
"sha2",

View File

@ -6,6 +6,7 @@ edition = "2018"
[dependencies]
byteorder = "1.3"
once_cell = "1"
pkcs11 = "0.4"
rsclientcerts = { path = "../rsclientcerts" }
sha2 = "0.10.2"

View File

@ -6,11 +6,13 @@
#![allow(non_snake_case)]
extern crate byteorder;
extern crate once_cell;
extern crate pkcs11;
#[macro_use]
extern crate rsclientcerts;
extern crate sha2;
use once_cell::sync::OnceCell;
use pkcs11::types::*;
use rsclientcerts::manager::{Manager, SlotType};
use std::ffi::{c_void, CStr};
@ -50,7 +52,7 @@ type SignFunction = extern "C" fn(
/// The singleton `Manager` that handles state with respect to PKCS #11. Only one thread
/// may use it at a time, but there is no restriction on which threads may use it.
static MANAGER: Mutex<Option<Manager<Backend>>> = Mutex::new(None);
static mut MANAGER: OnceCell<Mutex<Option<Manager<Backend>>>> = OnceCell::new();
// Obtaining a handle on the manager is a two-step process. First the mutex must be locked, which
// (if successful), results in a mutex guard object. We must then get a mutable refence to the
@ -61,9 +63,11 @@ static MANAGER: Mutex<Option<Manager<Backend>>> = Mutex::new(None);
// let manager = manager_guard_to_manager!(manager_guard);
macro_rules! try_to_get_manager_guard {
() => {
match MANAGER.lock() {
Ok(maybe_manager) => maybe_manager,
Err(_) => return CKR_DEVICE_ERROR,
unsafe {
match MANAGER.get_or_init(|| Mutex::new(None)).lock() {
Ok(maybe_manager) => maybe_manager,
Err(_) => return CKR_DEVICE_ERROR,
}
}
};
}
@ -115,11 +119,8 @@ extern "C" fn C_Finalize(_pReserved: CK_VOID_PTR) -> CK_RV {
// Drop the manager. When C_Finalize is called, there should be only one
// reference to this module (which is going away), so there shouldn't be
// any concurrency issues.
let mut manager_guard = try_to_get_manager_guard!();
match manager_guard.take() {
Some(_) => CKR_OK,
None => CKR_CRYPTOKI_NOT_INITIALIZED,
}
let _ = unsafe { MANAGER.take() };
CKR_OK
}
// The specification mandates that these strings be padded with spaces to the appropriate length.