[Cryptech-Commits] [sw/pkcs11] 08/14: Add C_FindObject*() to py11.

git at cryptech.is git at cryptech.is
Mon Sep 14 21:43:59 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 cce50cb3a36bec58db683316a2862f1cfcba4829
Author: Rob Austein <sra at hactrn.net>
Date:   Fri Sep 11 14:48:08 2015 -0400

    Add C_FindObject*() to py11.
---
 py11/__init__.py | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/py11/__init__.py b/py11/__init__.py
index d99c1b0..d4c07a1 100644
--- a/py11/__init__.py
+++ b/py11/__init__.py
@@ -179,6 +179,22 @@ class PKCS11 (object):
     self.so.C_GetAttributeValue(session_handle, object_handle, byref(t), len(t))
     return dict((a.type, a.pValue.raw) for a in t)
 
+  def C_FindObjectsInit(self, session, template):
+    if template:
+      self.so.C_FindObjectsInit(session, attributes_to_ctypes(template), len(template))
+    else:
+      self.so.C_FindObjectsInit(session, None, 0)
+
+  def C_FindObjects(self, session, chunk_size = 10):
+    objects = (CK_OBJECT_HANDLE * chunk_size)()
+    count   = CK_ULONG()
+    while True:
+      self.so.C_FindObjects(session, byref(objects), len(objects), byref(count))
+      for i in xrange(count.value):
+        yield objects[i]
+      if count.value == 0:
+        break
+
   def C_GenerateKeyPair(self, session, mechanism_type, public_template, private_template):
     mechanism = CK_MECHANISM(mechanism_type, None, 0)
     public_template  = attributes_to_ctypes(public_template)
@@ -191,6 +207,7 @@ class PKCS11 (object):
                               byref(public_handle), byref(private_handle))
     return public_handle.value, private_handle.value
 
+
 __all__ = ["PKCS11"]
 __all__.extend(name for name in globals()
                if name.startswith("CK")



More information about the Commits mailing list