diff options
Diffstat (limited to 'cryptech/py11/attributes.py')
-rw-r--r-- | cryptech/py11/attributes.py | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/cryptech/py11/attributes.py b/cryptech/py11/attributes.py index c6a87da..035677c 100644 --- a/cryptech/py11/attributes.py +++ b/cryptech/py11/attributes.py @@ -15,7 +15,7 @@ class Attribute(object): from . import types assert attribute_name.startswith("CKA_") attribute_number = getattr(constants, attribute_name) - type_class = getattr(types, type_name, str) + type_class = getattr(types, type_name, bytes) if type_class is CK_BBOOL: cls = Attribute_CK_BBOOL elif type_class is CK_ULONG: @@ -35,15 +35,15 @@ class Attribute(object): def decode(self, x): return x class Attribute_CK_BBOOL(Attribute): - def encode(self, x): return chr(int(x)) - def decode(self, x): return bool(ord(x)) + def encode(self, x): return pack("B", int(x)) + def decode(self, x): return bool(unpack("B", x)[0]) class Attribute_CK_ULONG(Attribute): def encode(self, x): return pack("L", x) def decode(self, x): return unpack("L", x)[0] class Attribute_biginteger(Attribute): - def encode(self, x): return "\x00" if x == 0 else unhexlify("{0:0{1}x".format(x, ((x.bit_length() + 7) / 8) * 2)) + def encode(self, x): return "\x00" if x == 0 else unhexlify("{0:0{1}x}".format(x, ((x.bit_length() + 7) // 8) * 2)) def decode(self, x): return int(hexlify(x), 16) |