aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2015-09-11 15:31:34 -0400
committerRob Austein <sra@hactrn.net>2015-09-11 15:31:34 -0400
commit1086cc3324dacc5d6a5bdb11ada2f4597d4f68a4 (patch)
tree3f163d346bddc90cca7dfbe82d1d45229eae83e1
parentcce50cb3a36bec58db683316a2862f1cfcba4829 (diff)
Python ctypes arrays and pointers really do work just as in C, once
one wraps one's brain around the syntactic differences.
-rw-r--r--py11/__init__.py20
1 files 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: