mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 03:15:11 +00:00
Backed out changeset 8feed89ecea4 (bug 1787268) for causing build bustages. CLOSED TREE
This commit is contained in:
parent
c49ba6a8f8
commit
26ac918f96
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -2688,6 +2688,7 @@ name = "ipcclientcerts-static"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"byteorder",
|
"byteorder",
|
||||||
|
"once_cell",
|
||||||
"pkcs11",
|
"pkcs11",
|
||||||
"rsclientcerts",
|
"rsclientcerts",
|
||||||
"sha2",
|
"sha2",
|
||||||
|
@ -6,6 +6,7 @@ edition = "2018"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
byteorder = "1.3"
|
byteorder = "1.3"
|
||||||
|
once_cell = "1"
|
||||||
pkcs11 = "0.4"
|
pkcs11 = "0.4"
|
||||||
rsclientcerts = { path = "../rsclientcerts" }
|
rsclientcerts = { path = "../rsclientcerts" }
|
||||||
sha2 = "0.10.2"
|
sha2 = "0.10.2"
|
||||||
|
@ -6,11 +6,13 @@
|
|||||||
#![allow(non_snake_case)]
|
#![allow(non_snake_case)]
|
||||||
|
|
||||||
extern crate byteorder;
|
extern crate byteorder;
|
||||||
|
extern crate once_cell;
|
||||||
extern crate pkcs11;
|
extern crate pkcs11;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate rsclientcerts;
|
extern crate rsclientcerts;
|
||||||
extern crate sha2;
|
extern crate sha2;
|
||||||
|
|
||||||
|
use once_cell::sync::OnceCell;
|
||||||
use pkcs11::types::*;
|
use pkcs11::types::*;
|
||||||
use rsclientcerts::manager::{Manager, SlotType};
|
use rsclientcerts::manager::{Manager, SlotType};
|
||||||
use std::ffi::{c_void, CStr};
|
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
|
/// 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.
|
/// 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
|
// 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
|
// (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);
|
// let manager = manager_guard_to_manager!(manager_guard);
|
||||||
macro_rules! try_to_get_manager_guard {
|
macro_rules! try_to_get_manager_guard {
|
||||||
() => {
|
() => {
|
||||||
match MANAGER.lock() {
|
unsafe {
|
||||||
Ok(maybe_manager) => maybe_manager,
|
match MANAGER.get_or_init(|| Mutex::new(None)).lock() {
|
||||||
Err(_) => return CKR_DEVICE_ERROR,
|
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
|
// 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
|
// reference to this module (which is going away), so there shouldn't be
|
||||||
// any concurrency issues.
|
// any concurrency issues.
|
||||||
let mut manager_guard = try_to_get_manager_guard!();
|
let _ = unsafe { MANAGER.take() };
|
||||||
match manager_guard.take() {
|
CKR_OK
|
||||||
Some(_) => CKR_OK,
|
|
||||||
None => CKR_CRYPTOKI_NOT_INITIALIZED,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The specification mandates that these strings be padded with spaces to the appropriate length.
|
// The specification mandates that these strings be padded with spaces to the appropriate length.
|
||||||
|
Loading…
Reference in New Issue
Block a user