summaryrefslogtreecommitdiff
path: root/SWIG/_ec.i
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2016-04-06 19:19:32 +0200
committerMatěj Cepl <mcepl@cepl.eu>2016-04-11 19:55:33 +0200
commitf51df5da26a67387f9dac0f35aa7eea4f77cd6d7 (patch)
tree0b81e3fdf0ad214e00dc5a2cfb3e5ffc75a2dd07 /SWIG/_ec.i
parent3aa2c8a70855685bbecd7575efa5f7631013808a (diff)
downloadm2crypto-f51df5da26a67387f9dac0f35aa7eea4f77cd6d7.tar.gz
Add implementation of the function ec_get_builtin_curves.
* including Python interface (EC.get_builtin_curves). * including test for EC.get_builtin_curves
Diffstat (limited to 'SWIG/_ec.i')
-rw-r--r--SWIG/_ec.i51
1 files changed, 51 insertions, 0 deletions
diff --git a/SWIG/_ec.i b/SWIG/_ec.i
index 35d19ca..9ee1d64 100644
--- a/SWIG/_ec.i
+++ b/SWIG/_ec.i
@@ -115,6 +115,57 @@ void ec_init(PyObject *ec_err) {
_ec_err = ec_err;
}
+PyObject *ec_get_builtin_curves(void) {
+ /* size_t EC_get_builtin_curves(EC_builtin_curve *r, size_t
+ * nitems); */
+ EC_builtin_curve *curves;
+ Py_ssize_t ret_curves = 0;
+ size_t num_curves = EC_get_builtin_curves(NULL, 0);
+ PyObject *ret_tuple = NULL;
+ PyObject *ret_dict = NULL;
+ Py_ssize_t i;
+ const char *comment;
+ const char *sname;
+
+ if (!(curves = PyMem_Malloc(num_curves * sizeof(EC_builtin_curve)))) {
+ PyErr_SetString(PyExc_MemoryError, "ec_get_builtin_curves");
+ return NULL;
+ }
+
+ ret_curves = (Py_ssize_t)EC_get_builtin_curves(curves, num_curves);
+
+ if (!(ret_tuple = PyTuple_New(ret_curves))) {
+ PyErr_SetString(PyExc_MemoryError, "ec_get_builtin_curves");
+ return NULL;
+ }
+
+ for (i = 0; i < ret_curves; i++) {
+ if (!(ret_dict = PyDict_New())) {
+ PyErr_SetString(PyExc_MemoryError, "ec_get_builtin_curves");
+ return NULL;
+ }
+
+ comment = curves[i].comment;
+ sname = OBJ_nid2sn(curves[i].nid);
+ if (sname == NULL)
+ sname = "";
+
+ PyDict_SetItemString(ret_dict, "NID",
+ PyLong_FromLong((long)curves[i].nid));
+ PyDict_SetItemString(ret_dict, "sname",
+ PyString_FromString(sname));
+ PyDict_SetItemString(ret_dict, "comment",
+ PyString_FromString(comment));
+
+ PyTuple_SET_ITEM(ret_tuple, i, ret_dict);
+
+ }
+
+ PyMem_Free(curves);
+
+ return ret_tuple;
+}
+
EC_KEY* ec_key_new_by_curve_name(int nid)
{
EC_KEY *key;