diff options
author | Neal Norwitz <nnorwitz@gmail.com> | 2006-07-10 01:18:57 +0000 |
---|---|---|
committer | Neal Norwitz <nnorwitz@gmail.com> | 2006-07-10 01:18:57 +0000 |
commit | 2a30cd0ef0673710a1a4e188b50c11026c403b2a (patch) | |
tree | a95d41411e8f7d39a0fa6b6b73f99fc93573d8ea /Modules/posixmodule.c | |
parent | 4a5fbda66d3132af761e32e164ed398977f51694 (diff) | |
download | cpython-git-2a30cd0ef0673710a1a4e188b50c11026c403b2a.tar.gz |
Patch #1516912: improve Modules support for OpenVMS.
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r-- | Modules/posixmodule.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index d8cf40ed7c..e1182378ee 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -7882,6 +7882,42 @@ win32_urandom(PyObject *self, PyObject *args) } #endif +#ifdef __VMS +/* Use openssl random routine */ +#include <openssl/rand.h> +PyDoc_STRVAR(vms_urandom__doc__, +"urandom(n) -> str\n\n\ +Return a string of n random bytes suitable for cryptographic use."); + +static PyObject* +vms_urandom(PyObject *self, PyObject *args) +{ + int howMany; + PyObject* result; + + /* Read arguments */ + if (! PyArg_ParseTuple(args, "i:urandom", &howMany)) + return NULL; + if (howMany < 0) + return PyErr_Format(PyExc_ValueError, + "negative argument not allowed"); + + /* Allocate bytes */ + result = PyString_FromStringAndSize(NULL, howMany); + if (result != NULL) { + /* Get random data */ + if (RAND_pseudo_bytes((unsigned char*) + PyString_AS_STRING(result), + howMany) < 0) { + Py_DECREF(result); + return PyErr_Format(PyExc_ValueError, + "RAND_pseudo_bytes"); + } + } + return result; +} +#endif + static PyMethodDef posix_methods[] = { {"access", posix_access, METH_VARARGS, posix_access__doc__}, #ifdef HAVE_TTYNAME @@ -8175,6 +8211,9 @@ static PyMethodDef posix_methods[] = { #ifdef MS_WINDOWS {"urandom", win32_urandom, METH_VARARGS, win32_urandom__doc__}, #endif + #ifdef __VMS + {"urandom", vms_urandom, METH_VARARGS, vms_urandom__doc__}, + #endif {NULL, NULL} /* Sentinel */ }; |