Slicing the old crypto branch: signatures #2206

Merged
PeterSurda merged 2 commits from gitea-78 into v0.6 2024-04-06 02:34:17 +02:00
2 changed files with 26 additions and 2 deletions
Showing only changes of commit fd3567b3fa - Show all commits

View File

@ -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')

View File

@ -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(