aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2020-09-01 18:42:56 -0400
committerRob Austein <sra@hactrn.net>2020-09-01 18:42:56 -0400
commit9733c5e7faf9aee874c1176381abcda98deb48f9 (patch)
tree84f03eca300fb8319026168380c4ef6be0603848
parentf120a263ec422739d201843a5979bfabdf410708 (diff)
Work around PyCrypto being EOL and therefore not tracking Python 3.8
This is a short term kludge to let the old unit test code continue to work under Python 3.8. Medium term, we should replace all use of PyCrypto with PyCryptodome (API-compatible successor package). Long term we might want a newer API, but that can wait.
-rw-r--r--unit-tests.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/unit-tests.py b/unit-tests.py
index c2f7171..526379c 100644
--- a/unit-tests.py
+++ b/unit-tests.py
@@ -41,6 +41,7 @@ import unittest
import datetime
import binascii
import logging
+import time
import sys
from struct import pack, unpack
@@ -76,6 +77,20 @@ except ImportError:
ecdsa_loaded = False
+# PyCrypto has been deprecated, at some point we should move on to
+# pycryptodome, cryptography.io, or some other modern thing. For the
+# moment, an awful kludge to let PyCrypto hobble a little further with
+# Python 3.8.
+#
+# Given that PyCrypto is using this as input to its random number
+# generator, you should not use any keys generated by PyCrypto with
+# this hack in place for any serious purpose: they're fine as
+# throwaway test keys, but not for securing any data you care about.
+
+if pycrypto_loaded and not hasattr(time, "clock") and hasattr(time, "process_time"):
+ time.clock = time.process_time
+
+
logger = logging.getLogger("unit-tests")