Convert rand functions to accept bytes instead of bytes or text
diff --git a/OpenSSL/rand/rand.c b/OpenSSL/rand/rand.c
index 8c23015..fabf805 100644
--- a/OpenSSL/rand/rand.c
+++ b/OpenSSL/rand/rand.c
@@ -45,7 +45,7 @@
int size;
double entropy;
- if (!PyArg_ParseTuple(args, "s#d:add", &buf, &size, &entropy))
+ if (!PyArg_ParseTuple(args, BYTESTRING_FMT "#d:add", &buf, &size, &entropy))
return NULL;
RAND_add(buf, size, entropy);
@@ -67,7 +67,7 @@
char *buf;
int size;
- if (!PyArg_ParseTuple(args, "s#:seed", &buf, &size))
+ if (!PyArg_ParseTuple(args, BYTESTRING_FMT "#:seed", &buf, &size))
return NULL;
RAND_seed(buf, size);
diff --git a/OpenSSL/test/test_rand.py b/OpenSSL/test/test_rand.py
index c6717e9..a785168 100644
--- a/OpenSSL/test/test_rand.py
+++ b/OpenSSL/test/test_rand.py
@@ -8,7 +8,7 @@
import os
import stat
-from OpenSSL.test.util import TestCase
+from OpenSSL.test.util import TestCase, b
from OpenSSL import rand
@@ -46,16 +46,16 @@
type C{str} and C{int}, L{OpenSSL.rand.add} raises L{TypeError}.
"""
self.assertRaises(TypeError, rand.add)
- self.assertRaises(TypeError, rand.add, "foo", None)
+ self.assertRaises(TypeError, rand.add, b("foo"), None)
self.assertRaises(TypeError, rand.add, None, 3)
- self.assertRaises(TypeError, rand.add, "foo", 3, None)
+ self.assertRaises(TypeError, rand.add, b("foo"), 3, None)
def test_add(self):
"""
L{OpenSSL.rand.add} adds entropy to the PRNG.
"""
- rand.add('hamburger', 3)
+ rand.add(b('hamburger'), 3)
def test_seed_wrong_args(self):
@@ -65,14 +65,14 @@
"""
self.assertRaises(TypeError, rand.seed)
self.assertRaises(TypeError, rand.seed, None)
- self.assertRaises(TypeError, rand.seed, "foo", None)
+ self.assertRaises(TypeError, rand.seed, b("foo"), None)
def test_seed(self):
"""
L{OpenSSL.rand.seed} adds entropy to the PRNG.
"""
- rand.seed('milk shake')
+ rand.seed(b('milk shake'))
def test_status_wrong_args(self):