From fd3567b3fa3471b6dfebf21d9fa8550773010063 Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Tue, 27 Jul 2021 22:21:20 +0300 Subject: [PATCH] Add a test for sign() and verify() --- src/tests/samples.py | 10 ++++++++++ src/tests/test_crypto.py | 18 ++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/tests/samples.py b/src/tests/samples.py index 93e5ed61..e33c5f50 100644 --- a/src/tests/samples.py +++ b/src/tests/samples.py @@ -63,3 +63,13 @@ sample_object_expires = 1712271487 # .. do pow and obj.to_bytes() sample_object_data = unhexlify( '00000000001be7fc00000000660f307f0000002a010248454c4c4f') + +sample_msg = unhexlify( + '0592a10584ffabf96539f3d780d776828c67da1ab5b169e9e8aed838aaecc9ed36d49ff' + '1423c55f019e050c66c6324f53588be88894fef4dcffdb74b98e2b200') +sample_sig = unhexlify( + '304402202302475351db6b822de15d922e29397541f10d8a19780ba2ca4a920b1035f075' + '02205e5bba40d5f07a24c23a89ba5f01a3828371dfbb685dd5375fa1c29095fd232b') +sample_sig_sha1 = unhexlify( + '30460221008ad234687d1bdc259932e28ea6ee091b88b0900d8134902aa8c2fd7f016b96e' + 'd022100dafb94e28322c2fa88878f9dcbf0c2d33270466ab3bbffaec3dca0a2d1ef9354') diff --git a/src/tests/test_crypto.py b/src/tests/test_crypto.py index e68e7ee5..7be59a24 100644 --- a/src/tests/test_crypto.py +++ b/src/tests/test_crypto.py @@ -17,8 +17,9 @@ except ImportError: RIPEMD160 = None from .samples import ( - sample_pubsigningkey, sample_pubencryptionkey, - sample_privsigningkey, sample_privencryptionkey, sample_ripe + sample_msg, sample_pubsigningkey, sample_pubencryptionkey, + sample_privsigningkey, sample_privencryptionkey, sample_ripe, + sample_sig, sample_sig_sha1 ) @@ -65,6 +66,19 @@ class TestCrypto(RIPEMD160TestCase, unittest.TestCase): class TestHighlevelcrypto(unittest.TestCase): """Test highlevelcrypto public functions""" + def test_signatures(self): + """Verify sample signatures and newly generated ones""" + pubkey_hex = hexlify(sample_pubsigningkey) + # pregenerated signatures + self.assertTrue( + highlevelcrypto.verify(sample_msg, sample_sig, pubkey_hex)) + self.assertTrue( + highlevelcrypto.verify(sample_msg, sample_sig_sha1, pubkey_hex)) + # new signature + sig1 = highlevelcrypto.sign(sample_msg, sample_privsigningkey) + self.assertTrue( + highlevelcrypto.verify(sample_msg, sig1, pubkey_hex)) + def test_privtopub(self): """Generate public keys and check the result""" self.assertEqual(