*.c: Split the constant definitions into the various submodules.
[catacomb-python] / pubkey.c
index 6084c3d..b1d32a5 100644 (file)
--- a/pubkey.c
+++ b/pubkey.c
@@ -108,11 +108,8 @@ end:
   return (rc);
 }
 
-static PyObject *dsameth_beginhash(PyObject *me, PyObject *arg)
-{
-  if (!PyArg_ParseTuple(arg, ":beginhash")) return (0);
-  return (ghash_pywrap(DSA_HASH(me), gdsa_beginhash(DSA_D(me))));
-}
+static PyObject *dsameth_beginhash(PyObject *me)
+  { return (ghash_pywrap(DSA_HASH(me), gdsa_beginhash(DSA_D(me)))); }
 
 static PyObject *dsameth_endhash(PyObject *me, PyObject *arg)
 {
@@ -190,7 +187,7 @@ end:
 
 static const PyMethodDef dsapub_pymethods[] = {
 #define METHNAME(name) dsameth_##name
-  METH (beginhash,     "D.beginhash() -> hash object")
+  NAMETH(beginhash,    "D.beginhash() -> hash object")
   METH (endhash,       "D.endhash(H) -> BYTES")
   METH (verify,        "D.verify(MSG, (R, S)) -> true/false")
 #undef METHNAME
@@ -221,7 +218,7 @@ static const PyMemberDef dsapriv_pymembers[] = {
   { 0 }
 };
 
-static PyTypeObject dsapub_pytype_skel = {
+static const PyTypeObject dsapub_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
   "DSAPub",                            /* @tp_name@ */
   sizeof(dsa_pyobj),                   /* @tp_basicsize@ */
@@ -269,7 +266,7 @@ static PyTypeObject dsapub_pytype_skel = {
   0                                    /* @tp_is_gc@ */
 };
 
-static PyTypeObject dsapriv_pytype_skel = {
+static const PyTypeObject dsapriv_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
   "DSAPriv",                           /* @tp_name@ */
   sizeof(dsa_pyobj),                   /* @tp_basicsize@ */
@@ -363,11 +360,8 @@ end:
   return (rc);
 }
 
-static PyObject *kcdsameth_beginhash(PyObject *me, PyObject *arg)
-{
-  if (!PyArg_ParseTuple(arg, ":beginhash")) return (0);
-  return (ghash_pywrap(DSA_HASH(me), gkcdsa_beginhash(DSA_D(me))));
-}
+static PyObject *kcdsameth_beginhash(PyObject *me)
+  { return (ghash_pywrap(DSA_HASH(me), gkcdsa_beginhash(DSA_D(me)))); }
 
 static PyObject *kcdsameth_endhash(PyObject *me, PyObject *arg)
 {
@@ -428,7 +422,7 @@ end:
 
 static const PyMethodDef kcdsapub_pymethods[] = {
 #define METHNAME(name) kcdsameth_##name
-  METH (beginhash,     "D.beginhash() -> hash object")
+  NAMETH(beginhash,    "D.beginhash() -> hash object")
   METH (endhash,       "D.endhash(H) -> BYTES")
   METH (verify,        "D.verify(MSG, (R, S)) -> true/false")
 #undef METHNAME
@@ -442,7 +436,7 @@ static const PyMethodDef kcdsapriv_pymethods[] = {
   { 0 }
 };
 
-static PyTypeObject kcdsapub_pytype_skel = {
+static const PyTypeObject kcdsapub_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
   "KCDSAPub",                          /* @tp_name@ */
   sizeof(dsa_pyobj),                   /* @tp_basicsize@ */
@@ -490,7 +484,7 @@ static PyTypeObject kcdsapub_pytype_skel = {
   0                                    /* @tp_is_gc@ */
 };
 
-static PyTypeObject kcdsapriv_pytype_skel = {
+static const PyTypeObject kcdsapriv_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
   "KCDSAPriv",                         /* @tp_name@ */
   sizeof(dsa_pyobj),                   /* @tp_basicsize@ */
@@ -786,14 +780,14 @@ static const PyGetSetDef rsapriv_pygetset[] = {
 
 static const PyMethodDef rsapriv_pymethods[] = {
 #define METHNAME(name) rsameth_##name
-  KWMETH(privop,               "R.privop(X, [rng = None]) -> X^D (mod N)")
+  KWMETH(privop,       "R.privop(X, [rng = None]) -> X^D (mod N)")
   KWSMTH(generate, "generate(NBITS, [event = pgen_nullev], [rng = rand], "
                                                        "[nsteps = 0]) -> R")
 #undef METHNAME
   { 0 }
 };
 
-static PyTypeObject rsapub_pytype_skel = {
+static const PyTypeObject rsapub_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
   "RSAPub",                            /* @tp_name@ */
   sizeof(rsapub_pyobj),                        /* @tp_basicsize@ */
@@ -841,7 +835,7 @@ static PyTypeObject rsapub_pytype_skel = {
   0                                    /* @tp_is_gc@ */
 };
 
-static PyTypeObject rsapriv_pytype_skel = {
+static const PyTypeObject rsapriv_pytype_skel = {
   PyObject_HEAD_INIT(0) 0,             /* Header */
   "RSAPriv",                           /* @tp_name@ */
   sizeof(rsapriv_pyobj),               /* @tp_basicsize@ */
@@ -1262,6 +1256,16 @@ EDDSAS(DEFEDDSA)
 
 /*----- Global stuff ------------------------------------------------------*/
 
+static const struct nameval consts[] = {
+  CONST(X25519_KEYSZ), CONST(X25519_PUBSZ), CONST(X25519_OUTSZ),
+  CONST(X448_KEYSZ), CONST(X448_PUBSZ), CONST(X448_OUTSZ),
+  CONST(ED25519_KEYSZ), CONST(ED25519_PUBSZ), CONST(ED25519_SIGSZ),
+    CONST(ED25519_MAXPERSOSZ),
+  CONST(ED448_KEYSZ), CONST(ED448_PUBSZ), CONST(ED448_SIGSZ),
+    CONST(ED448_MAXPERSOSZ),
+  { 0 }
+};
+
 static const PyMethodDef methods[] = {
 #define METHNAME(name) meth_##name
   KWMETH(_p1crypt_encode, 0)
@@ -1307,6 +1311,7 @@ void pubkey_pyinsert(PyObject *mod)
   INSERT("KCDSAPriv", kcdsapriv_pytype);
   INSERT("RSAPub", rsapub_pytype);
   INSERT("RSAPriv", rsapriv_pytype);
+  setconstants(mod, consts);
 }
 
 /*----- That's all, folks -------------------------------------------------*/