[Cryptech-Commits] [sw/stm32] branch python3 updated: One more set of silly Python3 bytes handling errors

git at cryptech.is git at cryptech.is
Tue Sep 1 14:55:41 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 4050df5  One more set of silly Python3 bytes handling errors
4050df5 is described below

commit 4050df583c3221e55e7ada23c211cfc38fae7d89
Author: Rob Austein <sra at hactrn.net>
AuthorDate: Tue Sep 1 10:57:21 2020 -0400

    One more set of silly Python3 bytes handling errors
---
 bin/dfu                     | 6 +++---
 projects/hsm/cryptech_probe | 8 ++++++--
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/bin/dfu b/bin/dfu
index b3f0be1..fd783e0 100755
--- a/bin/dfu
+++ b/bin/dfu
@@ -77,7 +77,7 @@ def parse_args():
 
 def _write(dst, data):
     for i in range(len(data)):
-        dst.write(data[i])
+        dst.write(data[i:i+1])
         time.sleep(0.1)
     if len(data) == 4:
         print("Wrote 0x{}".format(hexlify(data).decode("ascii")))
@@ -111,7 +111,7 @@ def send_file(filename, args):
         except serial.SerialException:
             time.sleep(0.2)
             continue
-        dst.write('\r')
+        dst.write(b'\r')
         response = _read(dst, args.verbose)
         if 'OK' in response:
             dst.timeout=2
@@ -137,7 +137,7 @@ def send_file(filename, args):
             if len(ack_bytes) == 4:
                 break
             print('ERROR: Did not receive an ACK, got {!r}'.format(ack_bytes))
-            dst.write('\r')  # eventually get back to the CLI prompt
+            dst.write(b'\r')  # eventually get back to the CLI prompt
         ack = struct.unpack('<I', ack_bytes)[0]
         if ack != counter + 1:
             print('ERROR: Did not receive the expected counter as ACK (got {!r}/{!r}, not {!r})'.format(ack, ack_bytes, counter))
diff --git a/projects/hsm/cryptech_probe b/projects/hsm/cryptech_probe
index 7c26bf4..84359b7 100755
--- a/projects/hsm/cryptech_probe
+++ b/projects/hsm/cryptech_probe
@@ -102,8 +102,12 @@ for port in ports:
         except serial.SerialException:
             time.sleep(0.2)
 
-    for c in probe_string:
-        tty.write(c)
+    # Not sure we really need to dribble the probe string out this slowly anymore,
+    # but once upon a time we did this for a reason and it's not like this program
+    # is a performance bottleneck, so stick with the safe version.
+
+    for i in range(len(probe_string)):
+        tty.write(probe_string[i:i+1])
         time.sleep(0.1)
 
     response = tty.read(args.read_buffer_size)

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Commits mailing list