From 1086cc3324dacc5d6a5bdb11ada2f4597d4f68a4 Mon Sep 17 00:00:00 2001 From: Rob Austein Date: Fri, 11 Sep 2015 15:31:34 -0400 Subject: 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: -- cgit v1.2.3