aboutsummaryrefslogtreecommitdiff
path: root/py11/__init__.py
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2015-09-21 19:20:51 -0400
committerRob Austein <sra@hactrn.net>2015-09-21 19:20:51 -0400
commita939461cf3b1a1b0226a5b700bf08e53e6517c59 (patch)
tree45bcf6e19f7c15a7af19c062ab7db5bbf986a536 /py11/__init__.py
parentf723a3b05eb960a2c0e4fe5e86c8dde91a425acf (diff)
Add keyword arguments to C_GenerateKeyPair() in an attempt to present
a saner API to the user. This requires the library to know more than it really should about which attributes go into the public and private templates; if doing it this way proves infeasible, we may have to parse more details out of attributes.yaml to support this feature.
Diffstat (limited to 'py11/__init__.py')
-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),