Skip to content

Commit 4cf6d70

Browse files
committed
- Fixed a bug in Pkcs11::new by replacing MaybeUninit::uninit() with null-assigned variables; this resolves an issue that prevented my PKCS#11 library from loading
- Ran `cargo update` to refresh crate versions - Raised `rust-version` to 1.77 in `Cargo.toml`, since `mem::offset_of` is stabilized only in this version - Made `basic.rs` tests compile successfully again
1 parent 52daf5f commit 4cf6d70

File tree

9 files changed

+339
-215
lines changed

9 files changed

+339
-215
lines changed

Cargo.lock

Lines changed: 270 additions & 147 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cryptoki-sys/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cryptoki-sys"
3-
version = "0.4.0"
3+
version = "0.4.1"
44
authors = ["Contributors to the Parsec project"]
55
edition = '2021'
66
description = "FFI wrapper around the PKCS #11 API"
@@ -10,13 +10,13 @@ categories = ["api-bindings", "external-ffi-bindings", "cryptography", "hardware
1010
license = "Apache-2.0"
1111
repository = "https://github.com/parallaxsecond/rust-cryptoki"
1212
documentation = "https://docs.rs/crate/cryptoki-sys"
13-
rust-version = "1.66.0"
13+
rust-version = "1.77.0"
1414

1515
[build-dependencies]
16-
bindgen = { version = "0.70.1", optional = true }
16+
bindgen = { version = "0.72.0", optional = true }
1717

1818
[dependencies]
19-
libloading = "0.8.6"
19+
libloading = "0.8.8"
2020

2121
[features]
2222
generate-bindings = ["bindgen"]

cryptoki/Cargo.toml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cryptoki"
3-
version = "0.10.0"
3+
version = "0.10.1"
44
authors = ["Contributors to the Parsec project"]
55
edition = '2021'
66
description = "Rust-native wrapper around the PKCS #11 API"
@@ -10,20 +10,18 @@ categories = ["api-bindings", "external-ffi-bindings", "cryptography", "hardware
1010
license = "Apache-2.0"
1111
repository = "https://github.com/parallaxsecond/rust-cryptoki"
1212
documentation = "https://docs.rs/crate/cryptoki"
13-
rust-version = "1.66.0"
13+
rust-version = "1.77.0"
1414

1515
[dependencies]
16-
bitflags = "1.3"
17-
libloading = "0.8.6"
18-
log = "0.4.14"
19-
cryptoki-sys = { path = "../cryptoki-sys", version = "0.4.0" }
20-
paste = "1.0.6"
16+
bitflags = "1.3.2"
17+
libloading = "0.8.8"
18+
log = "0.4.27"
19+
cryptoki-sys = { path = "../cryptoki-sys", version = "0.4.1" }
20+
paste = "1.0.15"
2121
secrecy = "0.10.3"
2222

2323
[dev-dependencies]
24-
num-traits = "0.2.14"
25-
hex = "0.4.3"
26-
serial_test = "0.5.1"
24+
serial_test = "3.2.0"
2725
testresult = "0.4.1"
2826

2927
[features]

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,

cryptoki/src/mechanism/kbkdf.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
//! See: <https://docs.oasis-open.org/pkcs11/pkcs11-curr/v3.0/os/pkcs11-curr-v3.0-os.html#_Toc30061446>
55
66
use core::{convert::TryInto, marker::PhantomData, ptr};
7+
use std::mem::size_of;
78
use std::num::NonZeroUsize;
89

910
use cryptoki_sys::{

cryptoki/src/session/random.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl Session {
3434
Rv::from(get_pkcs11!(self.client(), C_GenerateRandom)(
3535
self.handle(),
3636
result.as_mut_ptr(),
37-
random_len.into(),
37+
random_len,
3838
))
3939
.into_result(Function::GenerateRandom)?;
4040
}

cryptoki/src/slot/slot_info.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use std::fmt::Debug;
1010
bitflags! {
1111
/// Collection of flags defined for [`CK_SLOT_INFO`]
1212
struct SlotInfoFlags: CK_FLAGS {
13-
const TOKEN_PRESENT=CKF_TOKEN_PRESENT;
14-
const REMOVABLE_DEVICE=CKF_REMOVABLE_DEVICE;
13+
const TOKEN_PRESENT = CKF_TOKEN_PRESENT;
14+
const REMOVABLE_DEVICE = CKF_REMOVABLE_DEVICE;
1515
const HW_SLOT = CKF_HW_SLOT;
1616
}
1717
}

cryptoki/src/types.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,14 @@ pub struct Ulong {
127127
val: CK_ULONG,
128128
}
129129

130+
impl Ulong {
131+
/// Create a new variable
132+
#[must_use]
133+
pub const fn new(ulong: CK_ULONG) -> Self {
134+
Ulong { val: ulong }
135+
}
136+
}
137+
130138
impl Deref for Ulong {
131139
type Target = CK_ULONG;
132140

@@ -284,7 +292,6 @@ pub type RawAuthPin = SecretBox<Vec<u8>>;
284292

285293
#[cfg(test)]
286294
mod test {
287-
288295
use super::*;
289296
const UTC_TIME: UtcTime = UtcTime {
290297
year: 1970,

0 commit comments

Comments
 (0)