[Cryptech-Commits] [sw/stm32] branch python3 updated: Wow, python-version-independent hexadecimal is painful
git at cryptech.is
git at cryptech.is
Tue May 26 19:18:37 UTC 2020
This is an automated email from the git hooks/post-receive script.
sra at hactrn.net pushed a commit to branch python3
in repository sw/stm32.
The following commit(s) were added to refs/heads/python3 by this push:
new 6d797bf Wow, python-version-independent hexadecimal is painful
6d797bf is described below
commit 6d797bffbd7571df98198df26977a39b86630ac7
Author: Rob Austein <sra at hactrn.net>
AuthorDate: Tue May 26 15:18:35 2020 -0400
Wow, python-version-independent hexadecimal is painful
---
bin/dfu | 2 +-
projects/cli-test/filetransfer | 2 +-
projects/hsm/cryptech_probe | 10 ++++++++--
projects/hsm/cryptech_upload | 7 +++++--
4 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/bin/dfu b/bin/dfu
index d37d3ba..50015da 100755
--- a/bin/dfu
+++ b/bin/dfu
@@ -80,7 +80,7 @@ def _write(dst, data):
dst.write(data[i])
time.sleep(0.1)
if len(data) == 4:
- print("Wrote 0x{}".format(hexlify(data)))
+ print("Wrote 0x{}".format(hexlify(data).decode("ascii")))
else:
print("Wrote {!r}".format(data))
diff --git a/projects/cli-test/filetransfer b/projects/cli-test/filetransfer
index 147f081..809c6b8 100755
--- a/projects/cli-test/filetransfer
+++ b/projects/cli-test/filetransfer
@@ -79,7 +79,7 @@ def parse_args():
def _write(dst, data):
dst.write(data)
if len(data) == 4:
- print(("Wrote 0x{!s}".format(hexlify(data))))
+ print(("Wrote 0x{!s}".format(hexlify(data).decode("ascii"))))
else:
print(("Wrote {!r}".format(data)))
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""
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Commits
mailing list