chiark / gitweb /
debian/: Use `dh_python2' for packaging.
[catacomb-python] / group.c
diff --git a/group.c b/group.c
index 1432fc86e204c49ffa17ad8d57659d0dcafe1869..b3c8b6a9d0f0d642f8c222f9941cdd846d560668 100644 (file)
--- a/group.c
+++ b/group.c
@@ -325,7 +325,7 @@ static PyTypeObject fginfo_pytype_skel = {
     Py_TPFLAGS_BASETYPE,
 
   /* @tp_doc@ */
-  "Abstract base class for field-group information objects.",
+"Abstract base class for field-group information objects.",
 
   0,                                   /* @tp_traverse@ */
   0,                                   /* @tp_clear@ */
@@ -373,7 +373,7 @@ static PyTypeObject dhinfo_pytype_skel = {
     Py_TPFLAGS_BASETYPE,
 
   /* @tp_doc@ */
-  "Standard (integer) Diffie-Hellman group information.",
+"DHInfo(P, R, G): standard (integer) Diffie-Hellman group information.",
 
   0,                                   /* @tp_traverse@ */
   0,                                   /* @tp_clear@ */
@@ -421,7 +421,7 @@ static PyTypeObject bindhinfo_pytype_skel = {
     Py_TPFLAGS_BASETYPE,
 
   /* @tp_doc@ */
-  "Binary-field Diffie-Hellman group information.",
+"BinDHInfo(P, R, G): binary-field Diffie-Hellman group information.",
 
   0,                                   /* @tp_traverse@ */
   0,                                   /* @tp_clear@ */
@@ -695,8 +695,8 @@ static PyObject *ge_pyint(PyObject *me)
 
   if ((x = G_TOINT(GE_G(me), MP_NEW, GE_X(me))) == 0)
     TYERR("can't convert to integer");
-  if (mp_tolong_checked(x, &l)) goto end;
-  rc = PyInt_FromLong(l);
+  if (!mp_tolong_checked(x, &l, 0)) rc = PyInt_FromLong(l);
+  else rc = mp_topylong(x);
 end:
   mp_drop(x);
   return (rc);
@@ -717,18 +717,34 @@ end:
 static PyObject *gemeth_toec(PyObject *me, PyObject *arg, PyObject *kw)
 {
   char *kwlist[] = { "curve", 0 };
-  PyTypeObject *cty = ecpt_pytype;
+  PyTypeObject *cty = 0;
+  PyObject *rc = 0;
+  group *g;
+  ec_curve *c;
   ec p = EC_INIT;
 
   if (!PyArg_ParseTupleAndKeywords(arg, kw, "|O:toec", kwlist,
                                   &cty)) goto end;
-  if (!PyType_Check(cty) || !PyType_IsSubtype(cty, ecpt_pytype))
-    TYERR("want subtype of catacomb.ECPt");
-  if (G_TOEC(GE_G(me), &p, GE_X(me)))
+  g = GROUP_G(GE_GOBJ(me));
+  if (cty) {
+    if (!PyType_Check(cty) || !PyType_IsSubtype(cty, ecpt_pytype))
+      TYERR("want subtype of catacomb.ECPt");
+    Py_INCREF((PyObject *)cty);
+  } else if (strcmp(G_NAME(g), "ec") == 0) {
+    c = eccurve_copy(((gctx_ec *)g)->ei.c);
+    cty = (PyTypeObject *)eccurve_pywrap(0, c);
+  } else  {
+    cty = ecpt_pytype;
+    Py_INCREF((PyObject *)cty);
+  }
+  if (G_TOEC(GE_G(me), &p, GE_X(me))) {
+    Py_DECREF((PyObject *)cty);
     TYERR("can't convert to ec point");
-  return (ecpt_pywrapout(cty, &p));
+  }
+  rc = ecpt_pywrapout(cty, &p);
+  Py_DECREF((PyObject *)cty);
 end:
-  return (0);
+  return (rc);
 }
 
 static PyObject *gemeth_tobuf(PyObject *me, PyObject *arg)
@@ -1170,7 +1186,7 @@ static PyTypeObject primegroup_pytype_skel = {
     Py_TPFLAGS_BASETYPE,
 
   /* @tp_doc@ */
-"Subgroups of prime fields.",
+"PrimeGroup(INFO): subgroups of prime fields.",
 
   0,                                   /* @tp_traverse@ */
   0,                                   /* @tp_clear@ */
@@ -1247,7 +1263,7 @@ static PyTypeObject bingroup_pytype_skel = {
     Py_TPFLAGS_BASETYPE,
 
   /* @tp_doc@ */
-"Subgroups of binary fields.",
+"BinGroup(INFO): subgroups of binary fields.",
 
   0,                                   /* @tp_traverse@ */
   0,                                   /* @tp_clear@ */
@@ -1325,7 +1341,7 @@ static PyTypeObject ecgroup_pytype_skel = {
     Py_TPFLAGS_BASETYPE,
 
   /* @tp_doc@ */
-"Elliptic curve groups.",
+"ECGroup(INFO): elliptic curve groups.",
 
   0,                                   /* @tp_traverse@ */
   0,                                   /* @tp_clear@ */