Skip to content

Commit 0169642

Browse files
authored
Merge pull request #291 from mematthias/pkcs11_new_fix
Fix Pkcs11::new bug preventing PKCS#11 library loading
2 parents 52daf5f + babfce3 commit 0169642

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

cryptoki/src/context/mod.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ use crate::error::{Error, Result, Rv};
3232

3333
use log::error;
3434
use std::fmt;
35-
use std::mem;
3635
use std::path::Path;
3736
use std::ptr;
3837
use std::sync::Arc;
@@ -135,18 +134,17 @@ impl Pkcs11 {
135134
unsafe fn _new(pkcs11_lib: cryptoki_sys::Pkcs11) -> Result<Self> {
136135
/* First try the 3.0 API to get default interface. It might have some more functions than
137136
* the 2.4 API */
138-
let mut interface = mem::MaybeUninit::uninit();
137+
let mut interface: *mut cryptoki_sys::CK_INTERFACE = ptr::null_mut();
139138
if pkcs11_lib.C_GetInterface.is_ok() {
140139
Rv::from(pkcs11_lib.C_GetInterface(
141140
ptr::null_mut(),
142141
ptr::null_mut(),
143-
interface.as_mut_ptr(),
142+
&mut interface,
144143
0,
145144
))
146145
.into_result(Function::GetInterface)?;
147-
if !interface.as_ptr().is_null() {
148-
let ifce_ptr: *mut cryptoki_sys::CK_INTERFACE = *interface.as_ptr();
149-
let ifce: cryptoki_sys::CK_INTERFACE = *ifce_ptr;
146+
if !interface.is_null() {
147+
let ifce: cryptoki_sys::CK_INTERFACE = *interface;
150148

151149
let list_ptr: *mut cryptoki_sys::CK_FUNCTION_LIST =
152150
ifce.pFunctionList as *mut cryptoki_sys::CK_FUNCTION_LIST;
@@ -166,13 +164,10 @@ impl Pkcs11 {
166164
}
167165
}
168166

169-
let mut list = mem::MaybeUninit::uninit();
170-
171-
Rv::from(pkcs11_lib.C_GetFunctionList(list.as_mut_ptr()))
167+
let mut list_ptr: *mut cryptoki_sys::CK_FUNCTION_LIST = ptr::null_mut();
168+
Rv::from(pkcs11_lib.C_GetFunctionList(&mut list_ptr))
172169
.into_result(Function::GetFunctionList)?;
173170

174-
let list_ptr = *list.as_ptr();
175-
176171
Ok(Pkcs11 {
177172
impl_: Arc::new(Pkcs11Impl {
178173
_pkcs11_lib: pkcs11_lib,

0 commit comments

Comments
 (0)