diff options
author | Jean-Paul Calderone <exarkun@twistedmatrix.com> | 2013-12-31 13:54:39 -0500 |
---|---|---|
committer | Jean-Paul Calderone <exarkun@twistedmatrix.com> | 2013-12-31 13:54:39 -0500 |
commit | c7cd3e607c359367b8b238e10007ffe644a08e50 (patch) | |
tree | 8bb94b20f1b38d296258416c2847dcb07065e322 | |
parent | 4a2592337e82bcfc5d6c80e7b76a20a7913b1076 (diff) | |
download | pyopenssl-c7cd3e607c359367b8b238e10007ffe644a08e50.tar.gz |
Make this test more 32 bit friendly: allocate the most memory that fits into a native integer.
This will avoid triggering an OverflowError on 32 bit platforms but still be more memory than can ever actually be allocated.
Also fix the implementation to accept Python longs as well as Python ints.
-rw-r--r-- | OpenSSL/rand.py | 2 | ||||
-rw-r--r-- | OpenSSL/test/test_rand.py | 3 |
2 files changed, 3 insertions, 2 deletions
diff --git a/OpenSSL/rand.py b/OpenSSL/rand.py index de158f6..9be14ec 100644 --- a/OpenSSL/rand.py +++ b/OpenSSL/rand.py @@ -30,7 +30,7 @@ def bytes(num_bytes): :param num_bytes: The number of bytes to fetch :return: A string of random bytes """ - if not isinstance(num_bytes, int): + if not isinstance(num_bytes, (int, long)): raise TypeError("num_bytes must be an integer") if num_bytes < 0: diff --git a/OpenSSL/test/test_rand.py b/OpenSSL/test/test_rand.py index b5a992d..7d2559e 100644 --- a/OpenSSL/test/test_rand.py +++ b/OpenSSL/test/test_rand.py @@ -8,6 +8,7 @@ Unit tests for :py:obj:`OpenSSL.rand`. from unittest import main import os import stat +import sys from OpenSSL.test.util import TestCase, b from OpenSSL import rand @@ -29,7 +30,7 @@ class RandTests(TestCase): :py:obj:`OpenSSL.rand.bytes` raises :py:obj:`MemoryError` if more bytes are requested than will fit in memory. """ - self.assertRaises(MemoryError, rand.bytes, 1024 * 1024 * 1024 * 1024) + self.assertRaises(MemoryError, rand.bytes, sys.maxint) def test_bytes(self): |