Skip to content

Commit

Permalink
Add CKF_OS_LOCKING_OK flag to C_Initialize args (#491)
Browse files Browse the repository at this point in the history
Would it be possible to set CKF_OS_LOCKING_OK when calling C_Initialize to enable use of PKCS#11 libraries that cannot do without OS locking? Or is there something in the threading model that disallows use of OS locking?

If you are interested in merging, then l can do some further verification. First time doing changes in rust, so beware :)

Greets
  • Loading branch information
quality-leftovers authored Dec 8, 2022
1 parent 6d5c409 commit a9c96ae
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
16 changes: 16 additions & 0 deletions pkcs11/pkcs11-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,22 @@ pub struct CK_INITIALIZE_FLAGS(CK_ULONG);
pub const CKF_LIBRARY_CANT_CREATE_OS_THREADS: CK_INITIALIZE_FLAGS =
CK_INITIALIZE_FLAGS(0x0000_0001);

pub const CKF_OS_LOCKING_OK: CK_INITIALIZE_FLAGS = CK_INITIALIZE_FLAGS(0x0000_0002);

impl std::ops::BitOr<Self> for CK_INITIALIZE_FLAGS {
type Output = Self;

fn bitor(self, rhs: Self) -> Self::Output {
CK_INITIALIZE_FLAGS(self.0 | rhs.0)
}
}

impl std::ops::BitOrAssign for CK_INITIALIZE_FLAGS {
fn bitor_assign(&mut self, rhs: Self) {
self.0 |= rhs.0;
}
}

#[derive(Clone, Copy, Debug)]
#[repr(transparent)]
pub struct CK_OPEN_SESSION_FLAGS(CK_ULONG);
Expand Down
3 changes: 2 additions & 1 deletion pkcs11/pkcs11/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ impl Context {
DestroyMutex: destroy_mutex,
LockMutex: lock_mutex,
UnlockMutex: unlock_mutex,
flags: pkcs11_sys::CKF_LIBRARY_CANT_CREATE_OS_THREADS,
flags: pkcs11_sys::CKF_LIBRARY_CANT_CREATE_OS_THREADS
| pkcs11_sys::CKF_OS_LOCKING_OK,
pReserved: std::ptr::null_mut(),
};
let result = C_Initialize(&initialize_args);
Expand Down

0 comments on commit a9c96ae

Please sign in to comment.