Skip to content

Commit 4adf340

Browse files
committed
Remove the initialize check
Callers can directly use the initialize function and check the return code to see if the initialization already happened.
1 parent 8597e0e commit 4adf340

File tree

2 files changed

+2
-20
lines changed

2 files changed

+2
-20
lines changed

cryptoki/src/context/mod.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ impl Pkcs11Impl {
7878
#[derive(Debug)]
7979
pub struct Pkcs11 {
8080
pub(crate) impl_: Pkcs11Impl,
81-
initialized: RwLock<bool>,
8281
}
8382

8483
impl Pkcs11 {
@@ -133,7 +132,6 @@ impl Pkcs11 {
133132
_pkcs11_lib: pkcs11_lib,
134133
function_list: FunctionList::V3_2(*list32_ptr),
135134
},
136-
initialized: RwLock::new(false),
137135
});
138136
}
139137
let list30_ptr: *mut cryptoki_sys::CK_FUNCTION_LIST_3_0 =
@@ -143,7 +141,6 @@ impl Pkcs11 {
143141
_pkcs11_lib: pkcs11_lib,
144142
function_list: FunctionList::V3_0(v30tov32(*list30_ptr)),
145143
},
146-
initialized: RwLock::new(false),
147144
});
148145
}
149146
/* fall back to the 2.* API */
@@ -159,22 +156,12 @@ impl Pkcs11 {
159156
_pkcs11_lib: pkcs11_lib,
160157
function_list: FunctionList::V2(v2tov3(*list_ptr)),
161158
},
162-
initialized: RwLock::new(false),
163159
})
164160
}
165161

166162
/// Initialize the PKCS11 library
167163
pub fn initialize(&self, init_args: CInitializeArgs) -> Result<()> {
168-
let mut init_lock = self.initialized.write().expect("lock not to be poisoned");
169-
if *init_lock {
170-
Err(Error::AlreadyInitialized)?
171-
}
172-
initialize(self, init_args).map(|_| *init_lock = true)
173-
}
174-
175-
/// Check whether the PKCS11 library has been initialized
176-
pub fn is_initialized(&self) -> bool {
177-
*self.initialized.read().expect("lock not to be poisoned")
164+
initialize(self, init_args)
178165
}
179166

180167
/// Finalize the PKCS11 library. Indicates that the application no longer needs to use PKCS11.

cryptoki/src/error/mod.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ pub enum Error {
4848

4949
/// The PIN was not set before logging in.
5050
PinNotSet,
51-
52-
/// The PKCS11 library has already been initialized
53-
AlreadyInitialized,
5451
}
5552

5653
impl fmt::Display for Error {
@@ -67,7 +64,6 @@ impl fmt::Display for Error {
6764
Error::NullFunctionPointer => write!(f, "Calling a NULL function pointer"),
6865
Error::InvalidValue => write!(f, "The value is not one of the expected options"),
6966
Error::PinNotSet => write!(f, "Pin has not been set before trying to log in"),
70-
Error::AlreadyInitialized => write!(f, "PKCS11 library has already been initialized"),
7167
}
7268
}
7369
}
@@ -85,8 +81,7 @@ impl std::error::Error for Error {
8581
| Error::NotSupported
8682
| Error::NullFunctionPointer
8783
| Error::PinNotSet
88-
| Error::InvalidValue
89-
| Error::AlreadyInitialized => None,
84+
| Error::InvalidValue => None,
9085
}
9186
}
9287
}

0 commit comments

Comments
 (0)