From e01ab3c98f070073acbbebeaf815b41ca659e300 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Mon, 14 Oct 2019 00:53:56 +0100 Subject: [PATCH] algorithms.c (FOO.hashbufN): Consistently raise `ValueError' if too big. --- algorithms.c | 8 ++++---- t/t-algorithms.py | 3 +-- 2 files changed, 5 insertions(+), 6 deletions(-) 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.""" -- 2.11.0