From 109aae13b378a87c344de05fd868653397ed2ad7 Mon Sep 17 00:00:00 2001 From: Dwayne Litzenberger Date: Sun, 10 Feb 2013 05:44:56 -0800 Subject: pct-speedtest.py: Python 2.1-2.3 compatibility They don't have os.urandom, so use Crypto.Random.get_random_bytes --- pct-speedtest.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'pct-speedtest.py') diff --git a/pct-speedtest.py b/pct-speedtest.py index daed105..9763f09 100644 --- a/pct-speedtest.py +++ b/pct-speedtest.py @@ -30,11 +30,18 @@ import sys from Crypto.PublicKey import RSA from Crypto.Cipher import AES, ARC2, ARC4, Blowfish, CAST, DES3, DES, XOR from Crypto.Hash import MD2, MD4, MD5, SHA256, SHA +from Crypto.Random import get_random_bytes try: from Crypto.Hash import RIPEMD except ImportError: # Some builds of PyCrypto don't have the RIPEMD module RIPEMD = None +# os.urandom() is less noisy when profiling, but it doesn't exist in Python < 2.4 +try: + urandom = os.urandom +except AttributeError: + urandom = get_random_bytes + class Benchmark: def __init__(self): @@ -70,7 +77,7 @@ class Benchmark: return self.__random_data def _random_bytes(self, b): - return os.urandom(b) + return urandom(b) def announce_start(self, test_name): sys.stdout.write("%s: " % (test_name,)) -- cgit v1.2.1