Skip to content

Commit 7888c7b

Browse files
committed
Add tests for allow_truncate=False
1 parent 941a8dd commit 7888c7b

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/ecdsa/test_pyecdsa.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,44 @@ def do_test_to_openssl(self, curve, hash_name="SHA1"):
12031203
)
12041204

12051205

1206+
class TooSmallCurve(unittest.TestCase):
1207+
@pytest.mark.skipif("prime192v1" not in OPENSSL_SUPPORTED_CURVES,
1208+
reason="system openssl does not support prime192v1")
1209+
def test_sign_too_small_curve_dont_allow_truncate_raises(self):
1210+
sk = SigningKey.generate(curve=NIST192p)
1211+
vk = sk.get_verifying_key()
1212+
data = b("data")
1213+
with self.assertRaises(ecdsa.keys.BadDigestError):
1214+
sk.sign(
1215+
data,
1216+
hashfunc=partial(hashlib.new, "SHA256"),
1217+
sigencode=sigencode_der,
1218+
allow_truncate=False,
1219+
)
1220+
1221+
@pytest.mark.skipif("prime192v1" not in OPENSSL_SUPPORTED_CURVES,
1222+
reason="system openssl does not support prime192v1")
1223+
def test_verify_too_small_curve_dont_allow_truncate_raises(self):
1224+
sk = SigningKey.generate(curve=NIST192p)
1225+
vk = sk.get_verifying_key()
1226+
data = b("data")
1227+
sig_der = sk.sign(
1228+
data,
1229+
hashfunc=partial(hashlib.new, "SHA256"),
1230+
sigencode=sigencode_der,
1231+
allow_truncate=True,
1232+
)
1233+
with self.assertRaises(BadDigestError):
1234+
vk.verify(
1235+
sig_der,
1236+
data,
1237+
hashfunc=partial(hashlib.new, "SHA256"),
1238+
sigdecode=sigdecode_der,
1239+
allow_truncate=False,
1240+
)
1241+
1242+
1243+
12061244
class DER(unittest.TestCase):
12071245
def test_integer(self):
12081246
self.assertEqual(der.encode_integer(0), b("\x02\x01\x00"))

0 commit comments

Comments
 (0)