From d52b9d3acb8e613b388bccd3192d30fff3957718 Mon Sep 17 00:00:00 2001 From: Rob Austein Date: Tue, 22 Sep 2015 12:53:02 -0400 Subject: Clean up Python APIs to C_FindObject*() and C_GetSlotList(). --- py11/__init__.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'py11') diff --git a/py11/__init__.py b/py11/__init__.py index 80495d9..da79e34 100644 --- a/py11/__init__.py +++ b/py11/__init__.py @@ -95,10 +95,11 @@ class PKCS11 (object): self._C_Initialize_args = None def C_GetSlotList(self): - slots = (CK_SLOT_ID * 10)() - count = CK_ULONG(len(slots)) + count = CK_ULONG() + self.so.C_GetSlotList(CK_TRUE, None, byref(count)) + slots = (CK_SLOT_ID * count.value)() self.so.C_GetSlotList(CK_TRUE, slots, byref(count)) - return [slots[i] for i in xrange(count.value)] + return tuple(slots[i] for i in xrange(count.value)) def C_GetTokenInfo(self, slot_id): token_info = CK_TOKEN_INFO() @@ -145,11 +146,11 @@ class PKCS11 (object): for i in xrange(count.value): yield objects[i] - def Find(self, session, template = None, **kwargs): + def FindObjects(self, session, template = None, **kwargs): self.C_FindObjectsInit(session, template, **kwargs) - for obj in self.C_FindObjects(session): - yield obj + result = tuple(self.C_FindObjects(session)) self.C_FindObjectsFinal(session) + return result def _parse_GenerateKeyPair_template(self, # Attributes common to public and private templates -- cgit v1.2.3