diff options
author | Rob Austein <sra@hactrn.net> | 2016-11-19 21:16:52 -0500 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2016-11-19 21:16:52 -0500 |
commit | 306c1dec5eb20da03bc9569aab83ae97a2ca9e7a (patch) | |
tree | d9786e97899f2b04e34b2040537cbbde34d1db7d /libhal.py | |
parent | ecbc49a97941b208fb162e4a6d10ca7277dc9359 (diff) |
Support queries for attribute length and presence.
Calling hal_rpc_pkey_get_attributes() with attribute_buffer_len = 0
now changes the return behavior so that it reports the lengths of
attributes listed in the query, with a length of zero for attributes
not present at all. This is mostly to support C_GetAttributeValue()
in PKCS #11, but we also use it to make the Python interface a bit
kinder to the user.
Diffstat (limited to 'libhal.py')
-rw-r--r-- | libhal.py | 14 |
1 files changed, 11 insertions, 3 deletions
@@ -382,8 +382,13 @@ class PKey(Handle): def set_attributes(self, attributes): self.hsm.pkey_set_attributes(self, attributes) - def get_attributes(self, attributes, attributes_buffer_len = 2048): - return self.hsm.pkey_get_attributes(self, attributes, attributes_buffer_len) + def get_attributes(self, attributes): + lengths = self.hsm.pkey_get_attributes(self, attributes, 0) + attributes = (k for k, v in lengths.iteritems() if v > 0) + buffer_length = sum(lengths.itervalues()) + result = dict((a, None) for a in lengths) + result.update(self.hsm.pkey_get_attributes(self, attributes, buffer_length)) + return result class HSM(object): @@ -650,4 +655,7 @@ class HSM(object): n = r.unpack_uint() if n != len(attributes): raise HAL_ERROR_RPC_PROTOCOL_ERROR - return dict((r.unpack_uint(), r.unpack_bytes()) for i in xrange(n)) + if attributes_buffer_len > 0: + return dict((r.unpack_uint(), r.unpack_bytes()) for i in xrange(n)) + else: + return dict((r.unpack_uint(), r.unpack_uint()) for i in xrange(n)) |