[Cryptech-Commits] [sw/pkcs11] 09/14: Python ctypes arrays and pointers really do work just as in C, once one wraps one's brain around the syntactic differences.

git at cryptech.is git at cryptech.is
Mon Sep 14 21:44:00 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 1086cc3324dacc5d6a5bdb11ada2f4597d4f68a4
Author: Rob Austein <sra at hactrn.net>
Date:   Fri Sep 11 15:31:34 2015 -0400

    Python ctypes arrays and pointers really do work just as in C, once
    one wraps one's brain around the syntactic differences.
---
 py11/__init__.py | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/py11/__init__.py b/py11/__init__.py
index d4c07a1..7acb7aa 100644
--- a/py11/__init__.py
+++ b/py11/__init__.py
@@ -168,16 +168,16 @@ class PKCS11 (object):
       attributes = tuple(attributes)
     if not all(isinstance(a, (int, long)) for a in attributes):
       raise TypeError
-    t = (CK_ATTRIBUTE * len(attributes))()
+    template = (CK_ATTRIBUTE * len(attributes))()
     for i in xrange(len(attributes)):
-      t[i].type = attributes[i]
-      t[i].pValue = None
-      t[i].ulValueLen = 0
-    self.so.C_GetAttributeValue(session_handle, object_handle, byref(t), len(t))
-    for a in t:
-      a.pValue = create_string_buffer(a.ulValueLen)
-    self.so.C_GetAttributeValue(session_handle, object_handle, byref(t), len(t))
-    return dict((a.type, a.pValue.raw) for a in t)
+      template[i].type = attributes[i]
+      template[i].pValue = None
+      template[i].ulValueLen = 0
+    self.so.C_GetAttributeValue(session_handle, object_handle, template, len(template))
+    for t in template:
+      t.pValue = create_string_buffer(t.ulValueLen)
+    self.so.C_GetAttributeValue(session_handle, object_handle, template, len(template))
+    return dict((t.type, t.pValue[:t.ulValueLen]) for t in template)
 
   def C_FindObjectsInit(self, session, template):
     if template:
@@ -189,7 +189,7 @@ class PKCS11 (object):
     objects = (CK_OBJECT_HANDLE * chunk_size)()
     count   = CK_ULONG()
     while True:
-      self.so.C_FindObjects(session, byref(objects), len(objects), byref(count))
+      self.so.C_FindObjects(session, objects, len(objects), byref(count))
       for i in xrange(count.value):
         yield objects[i]
       if count.value == 0:



More information about the Commits mailing list