From 2f21fc43638cf39da07ab85dd21546bc34515730 Mon Sep 17 00:00:00 2001 From: Rob Austein Date: Tue, 9 Jun 2020 18:34:06 -0400 Subject: Whack with club until Python 2 works again and Python 3 almost works There's still something wrong with XDR for attribute lists in Python 3, XDR complains that there's unconsumed data and attributes coming back are (sometimes truncated). Python 2 works. Probably data type issue somewhere but haven't spotted it yet. --- cryptech/libhal.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'cryptech') diff --git a/cryptech/libhal.py b/cryptech/libhal.py index 56712cb..1e2dbc6 100644 --- a/cryptech/libhal.py +++ b/cryptech/libhal.py @@ -490,18 +490,19 @@ class HSM(object): msg = slip_decode(b"".join(msg)) if not msg: continue - msg = ContextManagedUnpacker(b"".join(msg)) + msg = ContextManagedUnpacker(msg) if msg.unpack_uint() != code: continue return msg _pack_builtin = ((int, "_pack_uint"), - (str, "_pack_bytes"), + (bytes, "_pack_bytes"), + (str, "_pack_str"), ((list, tuple, set), "_pack_array"), (dict, "_pack_items")) try: - _pack_builtin += (long, "_pack_uint") + _pack_builtin += ((long, "_pack_uint"),) except NameError: # "long" merged with "int" in Python 3 pass @@ -523,6 +524,9 @@ class HSM(object): def _pack_bytes(self, packer, arg): packer.pack_bytes(arg) + def _pack_str(self, packer, arg): + packer.pack_bytes(arg.encode()) + def _pack_array(self, packer, arg): packer.pack_uint(len(arg)) self._pack_args(packer, arg) -- cgit v1.2.3