aboutsummaryrefslogtreecommitdiff
path: root/py11
diff options
context:
space:
mode:
Diffstat (limited to 'py11')
-rw-r--r--py11/__init__.py35
1 files changed, 32 insertions, 3 deletions
diff --git a/py11/__init__.py b/py11/__init__.py
index ec51d19..9d3837e 100644
--- a/py11/__init__.py
+++ b/py11/__init__.py
@@ -140,10 +140,39 @@ class PKCS11 (object):
for i in xrange(count.value):
yield objects[i]
- def C_GenerateKeyPair(self, session, mechanism_type, public_template, private_template):
+ def _parse_GenerateKeyPair_template(self,
+ # Attributes common to public and private templates
+ CKA_ID,
+ CKA_LABEL = None,
+ CKA_TOKEN = False,
+ # Attributes only in private template
+ CKA_SIGN = False,
+ CKA_DECRYPT = False,
+ CKA_UNWRAP = False,
+ CKA_SENSITIVE = True,
+ CKA_PRIVATE = True,
+ CKA_EXTRACTABLE = False,
+ # Finer-grained control for CKA_TOKEN
+ public_CKA_TOKEN = False,
+ private_CKA_TOKEN = False,
+ # Anything else is only in public template
+ **kwargs):
+ if CKA_LABEL is None:
+ CKA_LABEL = CKA_ID
+ public = dict(kwargs, CKA_LABEL = CKA_LABEL, CKA_ID = CKA_ID, CKA_TOKEN = public_CKA_TOKEN or CKA_TOKEN)
+ private = dict(CKA_LABEL = CKA_LABEL, CKA_ID = CKA_ID, CKA_TOKEN = private_CKA_TOKEN or CKA_TOKEN,
+ CKA_SIGN = CKA_SIGN, CKA_DECRYPT = CKA_DECRYPT, CKA_UNWRAP = CKA_UNWRAP,
+ CKA_SENSITIVE = CKA_SENSITIVE, CKA_PRIVATE = CKA_PRIVATE, CKA_EXTRACTABLE = CKA_EXTRACTABLE)
+ return self.adb.to_ctypes(public), self.adb.to_ctypes(private)
+
+ def C_GenerateKeyPair(self, session, mechanism_type, public_template = None, private_template = None, **kwargs):
+ assert kwargs or (public_template and private_template)
+ if kwargs:
+ public_template, private_template = self._parse_GenerateKeyPair_template(**kwargs)
+ else:
+ public_template = self.adb.to_ctypes(public_template)
+ private_template = self.adb.to_ctypes(private_template)
mechanism = CK_MECHANISM(mechanism_type, None, 0)
- public_template = self.adb.to_ctypes(public_template)
- private_template = self.adb.to_ctypes(private_template)
public_handle = CK_OBJECT_HANDLE()
private_handle = CK_OBJECT_HANDLE()
self.so.C_GenerateKeyPair(session, byref(mechanism),