summaryrefslogtreecommitdiff
path: root/SWIG
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2017-10-18 16:38:39 +0200
committerMatěj Cepl <mcepl@cepl.eu>2017-10-19 01:05:32 +0200
commit05f62122bf9d78a9004d89504282762b75242075 (patch)
treed952efc7a6a60237c13b329568689db8407b3550 /SWIG
parent41558c868dad5bde807664dbc1c20f0db6157825 (diff)
downloadm2crypto-05f62122bf9d78a9004d89504282762b75242075.tar.gz
Add exceptions for dsa_generate_parameters, dsa_read_{params,pub_key,key}
Diffstat (limited to 'SWIG')
-rw-r--r--SWIG/_dsa.i99
1 files changed, 62 insertions, 37 deletions
diff --git a/SWIG/_dsa.i b/SWIG/_dsa.i
index 2d88c96..8d7ca5a 100644
--- a/SWIG/_dsa.i
+++ b/SWIG/_dsa.i
@@ -39,7 +39,18 @@ void dsa_init(PyObject *dsa_err) {
Py_INCREF(dsa_err);
_dsa_err = dsa_err;
}
+%}
+
+%typemap(out) DSA * {
+ PyObject *self = NULL; /* bug in SWIG_NewPointerObj as of 3.0.5 */
+ if ($1 != NULL)
+ $result = SWIG_NewPointerObj($1, $1_descriptor, 0);
+ else {
+ $result = NULL;
+ }
+}
+%inline %{
DSA *dsa_generate_parameters(int bits, PyObject *pyfunc) {
DSA *dsa;
BN_GENCB *gencb;
@@ -72,6 +83,57 @@ DSA *dsa_generate_parameters(int bits, PyObject *pyfunc) {
return NULL;
}
+DSA *dsa_read_params(BIO *f, PyObject *pyfunc) {
+ DSA *ret;
+
+ Py_INCREF(pyfunc);
+ Py_BEGIN_ALLOW_THREADS
+ ret = PEM_read_bio_DSAparams(f, NULL, passphrase_callback, (void *)pyfunc);
+ Py_END_ALLOW_THREADS
+ Py_DECREF(pyfunc);
+
+ if (ret == NULL) {
+ m2_PyErr_Msg(_dsa_err);
+ }
+
+ return ret;
+}
+
+DSA *dsa_read_key(BIO *f, PyObject *pyfunc) {
+ DSA *ret;
+
+ Py_INCREF(pyfunc);
+ Py_BEGIN_ALLOW_THREADS
+ ret = PEM_read_bio_DSAPrivateKey(f, NULL, passphrase_callback, (void *)pyfunc);
+ Py_END_ALLOW_THREADS
+ Py_DECREF(pyfunc);
+
+ if (ret == NULL) {
+ m2_PyErr_Msg(_dsa_err);
+ }
+
+ return ret;
+}
+
+DSA *dsa_read_pub_key(BIO *f, PyObject *pyfunc) {
+ DSA *ret;
+
+ Py_INCREF(pyfunc);
+ Py_BEGIN_ALLOW_THREADS
+ ret = PEM_read_bio_DSA_PUBKEY(f, NULL, passphrase_callback, (void *)pyfunc);
+ Py_END_ALLOW_THREADS
+ Py_DECREF(pyfunc);
+
+ if (ret == NULL) {
+ m2_PyErr_Msg(_dsa_err);
+ }
+
+ return ret;
+}
+%}
+%typemap(out) DSA * ;
+
+%inline %{
PyObject *dsa_get_p(DSA *dsa) {
const BIGNUM* p = NULL;
DSA_get0_pqg(dsa, &p, NULL, NULL);
@@ -163,19 +225,6 @@ PyObject *dsa_set_pub(DSA *dsa, PyObject *value) {
}
%}
-%inline %{
-DSA *dsa_read_params(BIO *f, PyObject *pyfunc) {
- DSA *ret;
-
- Py_INCREF(pyfunc);
- Py_BEGIN_ALLOW_THREADS
- ret = PEM_read_bio_DSAparams(f, NULL, passphrase_callback, (void *)pyfunc);
- Py_END_ALLOW_THREADS
- Py_DECREF(pyfunc);
- return ret;
-}
-%}
-
%threadallow dsa_write_params_bio;
%inline %{
int dsa_write_params_bio(DSA* dsa, BIO* f) {
@@ -219,30 +268,6 @@ int dsa_write_pub_key_bio(DSA* dsa, BIO* f) {
%}
%inline %{
-DSA *dsa_read_key(BIO *f, PyObject *pyfunc) {
- DSA *ret;
-
- Py_INCREF(pyfunc);
- Py_BEGIN_ALLOW_THREADS
- ret = PEM_read_bio_DSAPrivateKey(f, NULL, passphrase_callback, (void *)pyfunc);
- Py_END_ALLOW_THREADS
- Py_DECREF(pyfunc);
- return ret;
-}
-%}
-
-%inline %{
-DSA *dsa_read_pub_key(BIO *f, PyObject *pyfunc) {
- DSA *ret;
-
- Py_INCREF(pyfunc);
- Py_BEGIN_ALLOW_THREADS
- ret = PEM_read_bio_DSA_PUBKEY(f, NULL, passphrase_callback, (void *)pyfunc);
- Py_END_ALLOW_THREADS
- Py_DECREF(pyfunc);
- return ret;
-}
-
PyObject *dsa_sign(DSA *dsa, PyObject *value) {
const void *vbuf;
int vlen;