diff options
author | Matěj Cepl <mcepl@cepl.eu> | 2016-05-13 17:08:02 +0200 |
---|---|---|
committer | Matěj Cepl <mcepl@cepl.eu> | 2016-05-20 21:39:29 +0200 |
commit | aad0b7e737d7e8781d3f7a04c1b34566e5f77631 (patch) | |
tree | 6fd7754e2a55d03a1479b4730b5c8348de9cb17a /SWIG/_dsa.i | |
parent | 5016a9c532147ba50654dc4a912dde843b4cc998 (diff) | |
download | m2crypto-aad0b7e737d7e8781d3f7a04c1b34566e5f77631.tar.gz |
Work with bytes() and str() on py3k and py2k alternatively.
Mostly use PyBytes_FromStringAndSize as Guido intended for py3k.
We don't have to use a complicated construct with PyBuffer_New (which is
not supported anymore anyway) and care for the memory management.
Changes in:
SWIG/_aes.i
SWIG/_asn1.i
SWIG/_bio.i
SWIG/_bn.i
SWIG/_dh.i
SWIG/_dsa.i
SWIG/_ec.i
SWIG/_evp.i
SWIG/_lib.i
SWIG/_objects.i
SWIG/_pkcs7.i
SWIG/_rand.i
SWIG/_rc4.i
SWIG/_rsa.i
SWIG/_ssl.i
SWIG/_util.i
SWIG/_x509.i
tests/test_bn.py: even the test file should not be executable.
Diffstat (limited to 'SWIG/_dsa.i')
-rw-r--r-- | SWIG/_dsa.i | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/SWIG/_dsa.i b/SWIG/_dsa.i index a6da42d..34820c6 100644 --- a/SWIG/_dsa.i +++ b/SWIG/_dsa.i @@ -38,7 +38,7 @@ void dsa_init(PyObject *dsa_err) { void genparam_callback(int p, int n, void *arg) { PyObject *argv, *ret, *cbfunc; - cbfunc = (PyObject *)arg; + cbfunc = (PyObject *)arg; argv = Py_BuildValue("(ii)", p, n); ret = PyEval_CallObject(cbfunc, argv); PyErr_Clear(); @@ -258,7 +258,7 @@ PyObject *dsa_sign(DSA *dsa, PyObject *value) { const void *vbuf; int vlen; PyObject *tuple; - DSA_SIG *sig; + DSA_SIG *sig; if (m2_PyObject_AsReadBufferInt(value, &vbuf, &vlen) == -1) return NULL; @@ -329,13 +329,19 @@ PyObject *dsa_sign_asn1(DSA *dsa, PyObject *value) { PyMem_Free(sigbuf); return NULL; } + +#if PY_MAJOR_VERSION >= 3 + ret = PyBytes_FromStringAndSize(sigbuf, siglen); +#else ret = PyString_FromStringAndSize(sigbuf, siglen); +#endif // PY_MAJOR_VERSION >= 3 + PyMem_Free(sigbuf); return ret; } int dsa_verify_asn1(DSA *dsa, PyObject *value, PyObject *sig) { - const void *vbuf; + const void *vbuf; void *sbuf; int vlen, slen, ret; |