aboutsummaryrefslogtreecommitdiff
path: root/py11/__init__.py
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2015-09-17 18:06:28 -0400
committerRob Austein <sra@hactrn.net>2015-09-17 18:06:28 -0400
commit261e1e35db97e99df38c12f6a48bb28f6b827ac8 (patch)
tree0edcc1b6c8353c2a2d7db796198fd5e44be3d3ae /py11/__init__.py
parentfcb9943a4f1103768f225395f2ea4d7a2ff0d3a8 (diff)
Enable locking in py11.
Diffstat (limited to 'py11/__init__.py')
-rw-r--r--py11/__init__.py17
1 files changed, 15 insertions, 2 deletions
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)