*.c: Use Python `METH_NOARGS' methods where applicable.
[catacomb-python] / algorithms.c
index ad9fe9c..4d4f5e2 100644 (file)
@@ -640,9 +640,8 @@ end:
   return (0);
 }
 
-static PyObject *gcmeth_bdry(PyObject *me, PyObject *arg)
+static PyObject *gcmeth_bdry(PyObject *me)
 {
-  if (!PyArg_ParseTuple(arg, ":bdry")) goto end;
   if (!GCIPHER_C(me)->ops->bdry) VALERR("`bdry' not supported");
   if (!GC_CLASS(GCIPHER_C(me))->blksz) VALERR("not a block cipher mode");
   GC_BDRY(GCIPHER_C(me));
@@ -667,7 +666,7 @@ static const PyMethodDef gcipher_pymethods[] = {
   METH (decrypt,       "C.decrypt(CT) -> PT")
   METH (deczero,       "C.deczero(N) -> PT")
   METH (setiv,         "C.setiv(IV)")
-  METH (bdry,          "C.bdry()")
+  NAMETH(bdry,         "C.bdry()")
 #undef METHNAME
   { 0 }
 };
@@ -976,12 +975,11 @@ static const PyGetSetDef gcaead_pygetset[] = {
   { 0 }
 };
 
-static PyObject *gaekmeth_aad(PyObject *me, PyObject *arg)
+static PyObject *gaekmeth_aad(PyObject *me)
 {
   const gaead_key *k = GAEADKEY_K(me);
   PyObject *rc = 0;
 
-  if (!PyArg_ParseTuple(arg, ":aad")) return (0);
   if (k->ops->c->f&AEADF_AADNDEP)
     VALERR("aad must be associated with enc/dec op");
   rc = gaeadaad_pywrap((PyObject *)GCAEAD_AAD(me->ob_type),
@@ -1068,7 +1066,7 @@ end:
 
 static const PyMethodDef gaeadkey_pymethods[] = {
 #define METHNAME(name) gaekmeth_##name
-  METH (aad,           "KEY.aad() -> AAD")
+  NAMETH(aad,          "KEY.aad() -> AAD")
   KWMETH(enc,          "KEY.enc(NONCE, [hsz], [msz], [tsz]) -> ENC")
   KWMETH(dec,          "KEY.dec(NONCE, [hsz], [csz], [tsz]) -> DEC")
 #undef METHNAME
@@ -1132,11 +1130,10 @@ static const PyGetSetDef gaeadaad_pygetset[] = {
   { 0 }
 };
 
-static PyObject *gaeameth_copy(PyObject *me, PyObject *arg)
+static PyObject *gaeameth_copy(PyObject *me)
 {
   PyObject *rc = 0;
 
-  if (!PyArg_ParseTuple(arg, ":copy")) goto end;
   if (gaea_check(me)) goto end;
   if (GAEADAAD_F(me)&AEADF_AADNDEP)
     VALERR("can't duplicate nonce-dependent aad");
@@ -1207,7 +1204,7 @@ static PyObject *gaeameth_hashstrz(PyObject *me, PyObject *arg)
 
 static const PyMethodDef gaeadaad_pymethods[] = {
 #define METHNAME(name) gaeameth_##name
-  METH (copy,          "AAD.copy() -> AAD'")
+  NAMETH(copy,         "AAD.copy() -> AAD'")
   METH (hash,          "AAD.hash(H)")
 #define METHU_(n, W, w) METH(hashu##w, "AAD.hashu" #w "(WORD)")
   DOUINTCONV(METHU_)
@@ -1271,12 +1268,11 @@ static const PyGetSetDef gaeadenc_pygetset[] = {
   { 0 }
 };
 
-static PyObject *gaeemeth_aad(PyObject *me, PyObject *arg)
+static PyObject *gaeemeth_aad(PyObject *me)
 {
   gaeadenc_pyobj *ge = (gaeadenc_pyobj *)me;
   PyObject *rc = 0;
 
-  if (!PyArg_ParseTuple(arg, ":aad")) return (0);
   if (!(ge->f&AEADF_AADNDEP))
     rc = gaeadaad_pywrap((PyObject *)GCAEADENC_KEY(ge->ob_type)->aad,
                         GAEAD_AAD(ge->e), 0, 0);
@@ -1388,7 +1384,7 @@ end:
 
 static const PyMethodDef gaeadenc_pymethods[] = {
 #define METHNAME(name) gaeemeth_##name
-  METH (aad,           "ENC.aad() -> AAD")
+  NAMETH(aad,          "ENC.aad() -> AAD")
   KWMETH(reinit,       "ENC.reinit(NONCE, [hsz], [msz], [tsz])")
   METH (encrypt,       "ENC.encrypt(MSG) -> CT")
   KWMETH(done,         "ENC.done([tsz], [aad]) -> CT, TAG")
@@ -1446,11 +1442,10 @@ static const PyGetSetDef gaeaddec_pygetset[] = {
   { 0 }
 };
 
-static PyObject *gaedmeth_aad(PyObject *me, PyObject *arg)
+static PyObject *gaedmeth_aad(PyObject *me)
 {
   gaeaddec_pyobj *gd = (gaeaddec_pyobj *)me;
 
-  if (!PyArg_ParseTuple(arg, ":aad")) return (0);
   if (!(gd->f&AEADF_AADNDEP))
     return (gaeadaad_pywrap((PyObject *)GCAEADDEC_KEY(gd->ob_type)->aad,
                            GAEAD_AAD(gd->d), 0, 0));
@@ -1551,7 +1546,7 @@ end:
 
 static const PyMethodDef gaeaddec_pymethods[] = {
 #define METHNAME(name) gaedmeth_##name
-  METH (aad,           "DEC.aad() -> AAD")
+  NAMETH(aad,          "DEC.aad() -> AAD")
   KWMETH(reinit,       "DEC.reinit(NONCE, [hsz], [csz], [tsz])")
   METH (decrypt,       "DEC.decrypt(CT) -> MSG")
   KWMETH(done,         "DEC.done(TAG, [aad]) -> MSG | None")
@@ -2013,11 +2008,8 @@ static PyObject *gchget_hashsz(PyObject *me, void *hunoz)
 static PyObject *gchget_bufsz(PyObject *me, void *hunoz)
   { return (PyInt_FromLong(GCHASH_CH(me)->bufsz)); }
 
-static PyObject *ghmeth_copy(PyObject *me, PyObject *arg)
-{
-  if (!PyArg_ParseTuple(arg, ":copy")) return (0);
-  return (ghash_pywrap((PyObject *)me->ob_type, GH_COPY(GHASH_H(me))));
-}
+static PyObject *ghmeth_copy(PyObject *me)
+  { return (ghash_pywrap((PyObject *)me->ob_type, GH_COPY(GHASH_H(me)))); }
 
 static PyObject *ghmeth_hash(PyObject *me, PyObject *arg)
 {
@@ -2060,11 +2052,10 @@ static PyObject *ghmeth_hashstrz(PyObject *me, PyObject *arg)
   RETURN_ME;
 }
 
-static PyObject *ghmeth_done(PyObject *me, PyObject *arg)
+static PyObject *ghmeth_done(PyObject *me)
 {
   ghash *g;
   PyObject *rc;
-  if (!PyArg_ParseTuple(arg, ":done")) return (0);
   g = GH_COPY(GHASH_H(me));
   rc = bytestring_pywrap(0, g->ops->c->hashsz);
   GH_DONE(g, PyString_AS_STRING(rc));
@@ -2083,7 +2074,7 @@ static const PyGetSetDef gchash_pygetset[] = {
 
 static const PyMethodDef ghash_pymethods[] = {
 #define METHNAME(name) ghmeth_##name
-  METH (copy,          "H.copy() -> HH")
+  NAMETH(copy,         "H.copy() -> HH")
   METH (hash,          "H.hash(M)")
 #define METHU_(n, W, w) METH(hashu##w, "H.hashu" #w "(WORD)")
   DOUINTCONV(METHU_)
@@ -2092,7 +2083,7 @@ static const PyMethodDef ghash_pymethods[] = {
   DOUINTCONV(METHBUF_)
 #undef METHBUF_
   METH (hashstrz,      "H.hashstrz(STRING)")
-  METH (done,          "H.done() -> HASH")
+  NAMETH(done,         "H.done() -> HASH")
 #undef METHNAME
   { 0 }
 };
@@ -2542,10 +2533,9 @@ static PyObject *poly1305clsget_masksz(PyObject *me, void *hunoz)
 static PyObject *poly1305clsget_tagsz(PyObject *me, void *hunoz)
   { return (PyInt_FromLong(POLY1305_TAGSZ)); }
 
-static PyObject *polymeth_copy(PyObject *me, PyObject *arg)
+static PyObject *polymeth_copy(PyObject *me)
 {
   poly1305hash_pyobj *ph;
-  if (!PyArg_ParseTuple(arg, ":copy")) return (0);
   ph = PyObject_NEW(poly1305hash_pyobj, me->ob_type);
   poly1305_copy(&ph->ctx, P1305_CTX(me));
   Py_INCREF(me->ob_type);
@@ -2596,19 +2586,11 @@ static PyObject *polymeth_hashstrz(PyObject *me, PyObject *arg)
   RETURN_ME;
 }
 
-static PyObject *polymeth_flush(PyObject *me, PyObject *arg)
-{
-  if (!PyArg_ParseTuple(arg, ":flush")) return (0);
-  poly1305_flush(P1305_CTX(me));
-  RETURN_ME;
-}
+static PyObject *polymeth_flush(PyObject *me)
+  { poly1305_flush(P1305_CTX(me)); RETURN_ME; }
 
-static PyObject *polymeth_flushzero(PyObject *me, PyObject *arg)
-{
-  if (!PyArg_ParseTuple(arg, ":flushzero")) return (0);
-  poly1305_flushzero(P1305_CTX(me));
-  RETURN_ME;
-}
+static PyObject *polymeth_flushzero(PyObject *me)
+  { poly1305_flushzero(P1305_CTX(me)); RETURN_ME; }
 
 static PyObject *polymeth_concat(PyObject *me, PyObject *arg)
 {
@@ -2626,10 +2608,9 @@ end:
   return (0);
 }
 
-static PyObject *polymeth_done(PyObject *me, PyObject *arg)
+static PyObject *polymeth_done(PyObject *me)
 {
   PyObject *rc;
-  if (!PyArg_ParseTuple(arg, ":done")) return (0);
   if (!(P1305_F(me) & f_mask)) VALERR("no mask");
   rc = bytestring_pywrap(0, POLY1305_TAGSZ);
   poly1305_done(P1305_CTX(me), PyString_AS_STRING(rc));
@@ -2650,7 +2631,7 @@ static const PyGetSetDef poly1305cls_pygetset[] = {
 
 static const PyMethodDef poly1305hash_pymethods[] = {
 #define METHNAME(name) polymeth_##name
-  METH (copy,          "P.copy() -> PP")
+  NAMETH(copy,         "P.copy() -> PP")
   METH (hash,          "P.hash(M)")
 #define METHU_(n, W, w) METH(hashu##w, "P.hashu" #w "(WORD)")
   DOUINTCONV(METHU_)
@@ -2659,10 +2640,10 @@ static const PyMethodDef poly1305hash_pymethods[] = {
   DOUINTCONV(METHBUF_)
 #undef METHBUF_
   METH (hashstrz,      "P.hashstrz(STRING)")
-  METH (flush,         "P.flush()")
-  METH (flushzero,     "P.flushzero()")
+  NAMETH(flush,                "P.flush()")
+  NAMETH(flushzero,    "P.flushzero()")
   METH (concat,        "P.concat(PREFIX, SUFFIX)")
-  METH (done,          "P.done() -> TAG")
+  NAMETH(done,         "P.done() -> TAG")
 #undef METHNAME
   { 0 }
 };
@@ -2866,13 +2847,11 @@ end:
   return ((PyObject *)rc);
 }
 
-static PyObject *kxvikmeth_copy(PyObject *me, PyObject *arg)
+static PyObject *kxvikmeth_copy(PyObject *me)
 {
   kxvik_pyobj *k = (kxvik_pyobj *)me, *rc = 0;
-  if (!PyArg_ParseTuple(arg, ":copy")) goto end;
   rc = (kxvik_pyobj *)k->ob_type->tp_alloc(k->ob_type, 0);
   rc->s = k->s; rc->n = k->n;
-end:
   return ((PyObject *)rc);
 }
 
@@ -2921,10 +2900,9 @@ end:
   return (rc);
 }
 
-static PyObject *kxvikmeth_step(PyObject *me, PyObject *arg)
+static PyObject *kxvikmeth_step(PyObject *me)
 {
   kxvik_pyobj *k = (kxvik_pyobj *)me;
-  if (!PyArg_ParseTuple(arg, ":step")) return (0);
   keccak1600_p(&k->s, &k->s, k->n);
   RETURN_ME;
 }
@@ -2958,10 +2936,10 @@ static const PyGetSetDef kxvik_pygetset[] = {
 
 static const PyMethodDef kxvik_pymethods[] = {
 #define METHNAME(func) kxvikmeth_##func
-  METH (copy,          "KECCAK.copy() -> KECCAK'")
+  NAMETH(copy,         "KECCAK.copy() -> KECCAK'")
   METH (mix,           "KECCAK.mix(DATA)")
   METH (extract,       "KECCAK.extract(NOCTETS)")
-  METH (step,          "KECCAK.step()")
+  NAMETH(step,         "KECCAK.step()")
 #undef METHNAME
   { 0 }
 };
@@ -3110,9 +3088,8 @@ static PyObject *shakemeth_hashstrz(PyObject *me, PyObject *arg)
   RETURN_ME;
 }
 
-static PyObject *shakemeth_xof(PyObject *me, PyObject *arg)
+static PyObject *shakemeth_xof(PyObject *me)
 {
-  if (!PyArg_ParseTuple(arg, ":xof")) goto end;
   if (shake_check(me, 0)) goto end;
   shake_xof(SHAKE_H(me));
   SHAKE_ST(me) = 1;
@@ -3134,15 +3111,13 @@ end:
   return (rc);
 }
 
-static PyObject *shakemeth_copy(PyObject *me, PyObject *arg)
+static PyObject *shakemeth_copy(PyObject *me)
 {
   shake_pyobj *rc = 0;
 
-  if (!PyArg_ParseTuple(arg, ":copy")) goto end;
   rc = PyObject_NEW(shake_pyobj, me->ob_type);
   rc->h = *SHAKE_H(me);
   rc->st = SHAKE_ST(me);
-end:
   return ((PyObject *)rc);
 }
 
@@ -3196,7 +3171,7 @@ static const PyGetSetDef shake_pygetset[] = {
 
 static const PyMethodDef shake_pymethods[] = {
 #define METHNAME(func) shakemeth_##func
-  METH (copy,          "S.copy() -> SS")
+  NAMETH(copy,         "S.copy() -> SS")
   METH (hash,          "S.hash(M)")
 #define METHU_(n, W, w) METH(hashu##w, "S.hashu" #w "(WORD)")
   DOUINTCONV(METHU_)
@@ -3205,7 +3180,7 @@ static const PyMethodDef shake_pymethods[] = {
   DOUINTCONV(METHBUF_)
 #undef METHBUF_
   METH (hashstrz,      "S.hashstrz(STRING)")
-  METH (xof,           "S.xof()")
+  NAMETH(xof,          "S.xof()")
   METH (done,          "S.done(LEN) -> H")
   METH (get,           "S.get(LEN) -> H")
   METH (mask,          "S.mask(M) -> C")