Skip to content

Commit

Permalink
Add a test for sign() and verify()
Browse files Browse the repository at this point in the history
  • Loading branch information
g1itch authored and Lee Miller committed Apr 4, 2024
1 parent 13d090e commit fd3567b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/tests/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,13 @@
# .. 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')
18 changes: 16 additions & 2 deletions src/tests/test_crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
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
)


Expand Down Expand Up @@ -65,6 +66,19 @@ def _hashdigest(data):
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(
Expand Down

0 comments on commit fd3567b

Please sign in to comment.