[Cryptech-Commits] [sw/pkcs11] 06/07: 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.
git at cryptech.is
git at cryptech.is
Mon Sep 21 23:26:12 UTC 2015
This is an automated email from the git hooks/post-receive script.
sra at hactrn.net pushed a commit to branch ecdsa
in repository sw/pkcs11.
commit a939461cf3b1a1b0226a5b700bf08e53e6517c59
Author: Rob Austein <sra at hactrn.net>
Date: Mon Sep 21 19:20:51 2015 -0400
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.
---
py11/__init__.py | 35 ++++++++++++++++++++++++++++++++---
1 file 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),
More information about the Commits
mailing list