aboutsummaryrefslogtreecommitdiff
path: root/cryptech
diff options
context:
space:
mode:
Diffstat (limited to 'cryptech')
-rw-r--r--cryptech/libhal.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/cryptech/libhal.py b/cryptech/libhal.py
index d7bc328..56712cb 100644
--- a/cryptech/libhal.py
+++ b/cryptech/libhal.py
@@ -39,6 +39,7 @@ A Python interface to the Cryptech libhal RPC API.
# not likely to want to use the full ONC RPC mechanism.
import os
+import sys
import uuid
import xdrlib
import socket
@@ -47,6 +48,13 @@ import binascii
logger = logging.getLogger(__name__)
+if sys.version_info.major == 2:
+ def colon_hex(raw):
+ return ":".join("{:02x}".format(ord(b)) for b in raw)
+else:
+ def colon_hex(raw):
+ return ":".join("{:02x}".format(b) for b in raw)
+
SLIP_END = b"\300" # indicates end of packet
SLIP_ESC = b"\333" # indicates byte stuffing
@@ -466,7 +474,7 @@ class HSM(object):
def _send(self, msg): # Expects an xdrlib.Packer
msg = slip_encode(msg.get_buffer())
if self.debug_io:
- logger.debug("send: %s", ":".join(binascii.hexlify(c) for c in msg))
+ logger.debug("send: %s", colon_hex(msg))
self.socket.sendall(msg)
def _recv(self, code): # Returns a ContextManagedUnpacker
@@ -478,7 +486,7 @@ class HSM(object):
raise HAL_ERROR_RPC_TRANSPORT()
msg.append(self.sockfile.read(1))
if self.debug_io:
- logger.debug("recv: %s", ":".join(binascii.hexlify(c) for c in msg))
+ logger.debug("recv: %s", colon_hex(msg))
msg = slip_decode(b"".join(msg))
if not msg:
continue