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.
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 @@
: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 @@
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 @@
: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):