From: Mark Wooding Date: Mon, 14 Oct 2019 00:01:33 +0000 (+0100) Subject: algorithms.c (ShakeNN constructor): Support `None' for func/perso args. X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb-python/commitdiff_plain/04b75d719e7435aac5a943ec083bb6c0789e4afd algorithms.c (ShakeNN constructor): Support `None' for func/perso args. --- diff --git a/algorithms.c b/algorithms.c index 4e22a54..dd0bd0a 100644 --- a/algorithms.c +++ b/algorithms.c @@ -2976,12 +2976,14 @@ static PyObject *shake_dopynew(void (*initfn)(shake_ctx *, PyObject *arg, PyObject *kw) { shake_pyobj *rc = 0; + PyObject *pobj = Py_None, *fobj = Py_None; struct bin p = { 0, 0 }, f = { 0, 0 }; static const char *const kwlist[] = { "perso", "func", 0 }; - if (!PyArg_ParseTupleAndKeywords(arg, kw, "|O&O&:new", KWLIST, - convbin, &p, convbin, &f)) - goto end; + if (!PyArg_ParseTupleAndKeywords(arg, kw, "|OO:new", KWLIST, &pobj, &fobj)) + goto end; + if (pobj != Py_None && !convbin(pobj, &p)) goto end; + if (fobj != Py_None && !convbin(fobj, &f)) goto end; rc = (shake_pyobj *)ty->tp_alloc(ty, 0); initfn(&rc->h, f.p, f.sz, p.p, p.sz); rc->st = 0; diff --git a/t/t-algorithms.py b/t/t-algorithms.py index d7b97cb..bf637ef 100644 --- a/t/t-algorithms.py +++ b/t/t-algorithms.py @@ -820,7 +820,7 @@ class TestKeccak (HashBufferTestMixin): def check_kmac(me, mcls, c): k = T.span(32) - me.check_shake(lambda func = None, perso = T.bin(""): + me.check_shake(lambda func = None, perso = None: mcls(k, perso = perso), c, done_matches_xof = False)