aboutsummaryrefslogtreecommitdiff
path: root/tests/parallel-signatures.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/parallel-signatures.py')
-rwxr-xr-xtests/parallel-signatures.py15
1 files changed, 8 insertions, 7 deletions
diff --git a/tests/parallel-signatures.py b/tests/parallel-signatures.py
index 980f759..7cb7132 100755
--- a/tests/parallel-signatures.py
+++ b/tests/parallel-signatures.py
@@ -44,6 +44,7 @@ import uuid
import xdrlib
import socket
import logging
+import binascii
import datetime
import collections
@@ -103,7 +104,7 @@ class PKey(cryptech.libhal.Handle):
raise Return(r)
@coroutine
- def verify(self, data = "", signature = None):
+ def verify(self, data = b"", signature = None):
yield self.hsm.pkey_verify(self, data = data, signature = signature)
@@ -135,7 +136,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("{:02x}".format(ord(c)) for c in packer))
+ logger.debug("send: %s", ":".join(binascii.hexlify(c) for c in packer))
yield self.iostream.write(packer)
while True:
try:
@@ -143,11 +144,11 @@ class HSM(cryptech.libhal.HSM):
except StreamClosedError:
raise HAL_ERROR_RPC_TRANSPORT()
if self.debug_io:
- logger.debug("recv: %s", ":".join("{:02x}".format(ord(c)) for c in unpacker))
+ logger.debug("recv: %s", ":".join(binascii.hexlify(c) for c in unpacker))
unpacker = cryptech.libhal.slip_decode(unpacker)
if not unpacker:
continue
- unpacker = ContextManagedUnpacker("".join(unpacker))
+ unpacker = ContextManagedUnpacker(b"".join(unpacker))
if unpacker.unpack_uint() == code:
break
client = unpacker.unpack_uint()
@@ -209,7 +210,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("{:02x}".format(ord(b)) for b in s))
+ logger.debug("Signature %s: %s", n, ":".join(binascii.hexlify(b) for b in s))
if args.verify and not v.verify(h, s):
raise RuntimeError("RSA verification failed")
r.add(t0, t1)
@@ -236,11 +237,11 @@ def main():
d = k.exportKey(format = "DER", pkcs = 8)
h = SHA256(args.text)
v = PKCS115_SigScheme(k)
- q = range(args.iterations)
+ q = list(range(args.iterations))
m = pkcs1_hash_and_pad(args.text)
r = Result(args, args.key)
- hsms = [HSM() for i in xrange(args.clients)]
+ hsms = [HSM() for i in range(args.clients)]
for hsm in hsms:
yield hsm.login(HAL_USER_NORMAL, args.pin)