- Timestamp:
- Mar 22, 2014, 2:49:57 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk/Modules/posixmodule.c
r402 r404 8706 8706 #endif 8707 8707 8708 #ifndef __EMX__8709 8708 PyDoc_STRVAR(posix_urandom__doc__, 8710 8709 "urandom(n) -> str\n\n\ … … 8736 8735 return result; 8737 8736 } 8738 #else8739 /* Use openssl random routine */8740 #include <openssl/rand.h>8741 PyDoc_STRVAR(os2_urandom__doc__,8742 "urandom(n) -> str\n\n\8743 Return a string of n random bytes suitable for cryptographic use.");8744 8745 static PyObject*8746 os2_urandom(PyObject *self, PyObject *args)8747 {8748 int howMany;8749 PyObject* result;8750 8751 /* Read arguments */8752 if (! PyArg_ParseTuple(args, "i:urandom", &howMany))8753 return NULL;8754 if (howMany < 0)8755 return PyErr_Format(PyExc_ValueError,8756 "negative argument not allowed");8757 8758 /* Allocate bytes */8759 result = PyString_FromStringAndSize(NULL, howMany);8760 if (result != NULL) {8761 /* Get random data */8762 if (RAND_pseudo_bytes((unsigned char*)8763 PyString_AS_STRING(result),8764 howMany) < 0) {8765 Py_DECREF(result);8766 return PyErr_Format(PyExc_ValueError,8767 "RAND_pseudo_bytes");8768 }8769 }8770 return result;8771 }8772 #endif8773 8737 8774 8738 #ifdef HAVE_SETRESUID … … 9167 9131 {"getresgid", posix_getresgid, METH_NOARGS, posix_getresgid__doc__}, 9168 9132 #endif 9169 #ifndef __EMX__9170 9133 {"urandom", posix_urandom, METH_VARARGS, posix_urandom__doc__}, 9171 #else9172 {"urandom", os2_urandom, METH_VARARGS, os2_urandom__doc__},9173 #endif9174 9134 {NULL, NULL} /* Sentinel */ 9175 9135 }; -
python/trunk/Python/random.c
r391 r404 96 96 97 97 98 #if def __VMS98 #if defined(__VMS) || defined(__OS2__) 99 99 /* Use openssl random routine */ 100 100 #include <openssl/rand.h> … … 117 117 118 118 119 #if !defined(MS_WINDOWS) && !defined(__VMS) 119 #if !defined(MS_WINDOWS) && !defined(__VMS) && !defined(__OS2__) 120 120 121 121 /* Read size bytes from /dev/urandom into buffer. … … 244 244 return win32_urandom((unsigned char *)buffer, size, 1); 245 245 #else 246 # if def __VMS246 # if defined(__VMS) || defined(__OS2__) 247 247 return vms_urandom((unsigned char *)buffer, size, 1); 248 248 # else … … 303 303 (void)win32_urandom((unsigned char *)secret, secret_size, 0); 304 304 #else /* #ifdef MS_WINDOWS */ 305 # if def __VMS305 # if defined(__VMS) || defined(__OS2__) 306 306 vms_urandom((unsigned char *)secret, secret_size, 0); 307 307 # else
Note:
See TracChangeset
for help on using the changeset viewer.