aboutsummaryrefslogtreecommitdiff
path: root/tests/parallel-signatures.py
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2020-05-26 15:18:19 -0400
committerRob Austein <sra@hactrn.net>2020-05-26 15:18:19 -0400
commited4c22473f5fb07006e773137ed047950e25a4d8 (patch)
tree26f7b93d5447b2e0cf5bd9c92dcda70161a46545 /tests/parallel-signatures.py
parent1cd42f6d3332e1edf78b06bd7dcf51f5a1a7bb23 (diff)
Wow, python-version-independent hexadecimal is painful
Diffstat (limited to 'tests/parallel-signatures.py')
-rwxr-xr-xtests/parallel-signatures.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/tests/parallel-signatures.py b/tests/parallel-signatures.py
index 7cb7132..87bac0a 100755
--- a/tests/parallel-signatures.py
+++ b/tests/parallel-signatures.py
@@ -44,7 +44,6 @@ import uuid
import xdrlib
import socket
import logging
-import binascii
import datetime
import collections
@@ -81,6 +80,14 @@ globals().update((name, getattr(cryptech.libhal, name))
for prefix in ("HAL", "RPC", "SLIP")))
+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 PKey(cryptech.libhal.Handle):
def __init__(self, hsm, handle, uuid):
@@ -136,7 +143,7 @@ class HSM(cryptech.libhal.HSM):
self._pack_args(packer, args)
packer = cryptech.libhal.slip_encode(packer.get_buffer())
if self.debug_io:
- logger.debug("send: %s", ":".join(binascii.hexlify(c) for c in packer))
+ logger.debug("send: %s", colon_hex(packer))
yield self.iostream.write(packer)
while True:
try:
@@ -144,7 +151,7 @@ class HSM(cryptech.libhal.HSM):
except StreamClosedError:
raise HAL_ERROR_RPC_TRANSPORT()
if self.debug_io:
- logger.debug("recv: %s", ":".join(binascii.hexlify(c) for c in unpacker))
+ logger.debug("recv: %s", colon_hex(unpacker))
unpacker = cryptech.libhal.slip_decode(unpacker)
if not unpacker:
continue
@@ -210,7 +217,7 @@ def client(args, k, p, q, r, m, v, h):
t0 = datetime.datetime.now()
s = yield p.sign(data = m)
t1 = datetime.datetime.now()
- logger.debug("Signature %s: %s", n, ":".join(binascii.hexlify(b) for b in s))
+ logger.debug("Signature %s: %s", n, colon_hex(s))
if args.verify and not v.verify(h, s):
raise RuntimeError("RSA verification failed")
r.add(t0, t1)