From: Mark Wooding Date: Sun, 13 Oct 2019 23:53:56 +0000 (+0100) Subject: algorithms.c (FOO.hashbufN): Consistently raise `ValueError' if too big. X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb-python/commitdiff_plain/37e554049676f4a826fa783eacbbee20e763f4b7 algorithms.c (FOO.hashbufN): Consistently raise `ValueError' if too big. --- diff --git a/algorithms.c b/algorithms.c index 4c8158d..8f3ae0b 100644 --- a/algorithms.c +++ b/algorithms.c @@ -1194,7 +1194,7 @@ DOUINTCONV(GAEAMETH_HASHU_) { \ struct bin in; octet b[SZ_##W]; \ if (!PyArg_ParseTuple(arg, "O&:hashbuf" #w, convbin, &in)) goto end; \ - if (in.sz > MASK##n) TYERR("string too long"); \ + if (in.sz > MASK##n) VALERR("too large"); \ STORE##W(b, in.sz); if (gaeadaad_hash(me, b, sizeof(b))) goto end; \ if (gaeadaad_hash(me, in.p, in.sz)) goto end; \ RETURN_ME; \ @@ -2044,7 +2044,7 @@ DOUINTCONV(GHMETH_HASHU_) { \ struct bin in; \ if (!PyArg_ParseTuple(arg, "O&:hashbuf" #w, convbin, &in)) goto end; \ - if (in.sz > MASK##n) TYERR("string too long"); \ + if (in.sz > MASK##n) VALERR("too large"); \ GH_HASHBUF##W(GHASH_H(me), in.p, in.sz); \ RETURN_ME; \ end: \ @@ -2588,7 +2588,7 @@ DOUINTCONV(POLYMETH_HASHU_) struct bin in; \ octet b[SZ_##W]; \ if (!PyArg_ParseTuple(arg, "O&:hashbuf" #w, convbin, &in)) goto end; \ - if (in.sz > MASK##n) TYERR("string too long"); \ + if (in.sz > MASK##n) VALERR("too large"); \ STORE##W(b, in.sz); poly1305_hash(P1305_CTX(me), b, sizeof(b)); \ poly1305_hash(P1305_CTX(me), in.p, in.sz); \ RETURN_ME; \ @@ -3081,7 +3081,7 @@ DOUINTCONV(SHAKEMETH_HASHU_) struct bin in; \ octet b[SZ_##W]; \ if (!PyArg_ParseTuple(arg, "O&:hashbuf" #w, convbin, &in)) goto end; \ - if (in.sz > MASK##n) TYERR("string too long"); \ + if (in.sz > MASK##n) VALERR("too large"); \ if (shake_check(me, 0)) goto end; \ STORE##W(b, in.sz); shake_hash(SHAKE_H(me), b, sizeof(b)); \ shake_hash(SHAKE_H(me), in.p, in.sz); \ diff --git a/t/t-algorithms.py b/t/t-algorithms.py index 8346fad..261c53b 100644 --- a/t/t-algorithms.py +++ b/t/t-algorithms.py @@ -95,8 +95,7 @@ class HashBufferTestMixin (U.TestCase): if w <= 3: n = 1 << 8*w h0, _ = makefn(w + n) - me.assertRaises((ValueError, TypeError), - hashfn, h0, C.ByteString.zero(n)) + me.assertRaises(ValueError, hashfn, h0, C.ByteString.zero(n)) def check_hashbuffer(me, makefn): """Test the various `hash...' methods."""