Skip to content

Commit e5585ea

Browse files
committed
Finalize Pkcs11 instead of Pkcs11Impl
Signed-off-by: Wiktor Kwapisiewicz <wiktor@metacode.biz>
1 parent 9f19f12 commit e5585ea

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

cryptoki/src/context/mod.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,22 @@ impl Pkcs11Impl {
7575
FunctionList::V3_0(l) => l,
7676
}
7777
}
78+
}
79+
80+
/// Main PKCS11 context. Should usually be unique per application.
81+
#[derive(Debug)]
82+
pub struct Pkcs11 {
83+
pub(crate) impl_: Pkcs11Impl,
84+
initialized: RwLock<bool>,
85+
}
7886

87+
impl Pkcs11 {
7988
// Private finalize call
8089
#[inline(always)]
81-
fn finalize(&self) -> Result<()> {
90+
fn finalize_ref(&self) -> Result<()> {
8291
unsafe {
8392
Rv::from(self
93+
.impl_
8494
.get_function_list()
8595
.C_Finalize
8696
.ok_or(Error::NullFunctionPointer)?(
@@ -91,21 +101,14 @@ impl Pkcs11Impl {
91101
}
92102
}
93103

94-
impl Drop for Pkcs11Impl {
104+
impl Drop for Pkcs11 {
95105
fn drop(&mut self) {
96-
if let Err(e) = self.finalize() {
106+
if let Err(e) = self.finalize_ref() {
97107
error!("Failed to finalize: {}", e);
98108
}
99109
}
100110
}
101111

102-
/// Main PKCS11 context. Should usually be unique per application.
103-
#[derive(Debug)]
104-
pub struct Pkcs11 {
105-
pub(crate) impl_: Pkcs11Impl,
106-
initialized: RwLock<bool>,
107-
}
108-
109112
impl Pkcs11 {
110113
/// Instantiate a new context from the path of a PKCS11 dynamic library implementation.
111114
pub fn new<P>(filename: P) -> Result<Self>

0 commit comments

Comments
 (0)