From 261e1e35db97e99df38c12f6a48bb28f6b827ac8 Mon Sep 17 00:00:00 2001 From: Rob Austein Date: Thu, 17 Sep 2015 18:06:28 -0400 Subject: Enable locking in py11. --- py11/__init__.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'py11') diff --git a/py11/__init__.py b/py11/__init__.py index ab187f7..bb4813f 100644 --- a/py11/__init__.py +++ b/py11/__init__.py @@ -35,8 +35,21 @@ class PKCS11 (object): self.so.C_GetInfo(byref(info)) return info.cryptokiVersion - def C_Initialize(self): - self.so.C_Initialize(None) + # http://stackoverflow.com/questions/15786635/using-ctypes-to-write-callbacks-that-pass-in-pointer-to-pointer-parameters-to-be + # suggests that it should be straightforward to write callback + # functions to implement the mutex semantics, and we get the + # CK_CREATEMUTEX call, but we dump core on the CK_LOCKMUTEX call. + # Specifying CKF_OS_LOCKING_OK does work, and is sufficient for most + # purposes, so leaving the callbacks out of the API for now. + + def C_Initialize(self, flags = 0): + if flags == 0: + self.so.C_Initialize(None) + else: + init_arg = CK_C_INITIALIZE_ARGS(cast(None, CK_CREATEMUTEX), cast(None, CK_DESTROYMUTEX), + cast(None, CK_LOCKMUTEX), cast(None, CK_UNLOCKMUTEX), + flags, None) + self.so.C_Initialize(cast(byref(init_arg), CK_VOID_PTR)) def C_Finalize(self): self.so.C_Finalize(None) -- cgit v1.2.3