diff options
author | Rob Austein <sra@hactrn.net> | 2020-05-26 15:18:35 -0400 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2020-05-26 15:18:35 -0400 |
commit | 6d797bffbd7571df98198df26977a39b86630ac7 (patch) | |
tree | d270af05d27bf746b4f4ba30a98542d93002f84f /projects/hsm | |
parent | f948d674351a2ca87d33c0e0d8558cbbb2f59682 (diff) |
Wow, python-version-independent hexadecimal is painful
Diffstat (limited to 'projects/hsm')
-rwxr-xr-x | projects/hsm/cryptech_probe | 10 | ||||
-rwxr-xr-x | projects/hsm/cryptech_upload | 7 |
2 files changed, 13 insertions, 4 deletions
diff --git a/projects/hsm/cryptech_probe b/projects/hsm/cryptech_probe index 3d14484..68bcfd1 100755 --- a/projects/hsm/cryptech_probe +++ b/projects/hsm/cryptech_probe @@ -38,9 +38,15 @@ goes to stderr. import sys import time import argparse -import binascii import serial.tools.list_ports_posix +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) + class positive_integer(int): def __init__(self, value): if self <= 0: @@ -102,7 +108,7 @@ for port in ports: response = tty.read(args.read_buffer_size) if args.debug: - sys.stderr.write("Received from {}: {!r} ({})\n".format(port, response, ":".join(binascii.hexlify(c) for c in response))) + sys.stderr.write("Received from {}: {!r} ({})\n".format(port, response, colon_hex(response))) # Check whether we got a known console prompt. diff --git a/projects/hsm/cryptech_upload b/projects/hsm/cryptech_upload index 0c18f25..aaa0f1c 100755 --- a/projects/hsm/cryptech_upload +++ b/projects/hsm/cryptech_upload @@ -44,7 +44,7 @@ import tarfile import argparse import platform -from binascii import crc32 +from binascii import crc32, hexlify FIRMWARE_CHUNK_SIZE = 4096 FPGA_CHUNK_SIZE = 4096 @@ -147,7 +147,10 @@ class ManagementPortAbstract(object): data = struct.pack("<I", data) self.send(data) if self.args.debug: - print("Wrote {!r}".format(data)) + if numeric: + print("Wrote 0x{}".format(hexlify(data).decode("ascii"))) + else: + print("Wrote {!r}".format(data)) def read(self): res = b"" |