aucoin/tests/test_dsa.py
Casper V. Kristensen b7053ad014
Publish
2018-07-15 23:30:55 +02:00

33 lines
875 B
Python

import unittest
import logging
from aucoin import dsa
logging.basicConfig(level=logging.DEBUG)
class TestDSA(unittest.TestCase):
def setUp(self):
self.private, self.public = dsa.generate_keypair()
self.data = b"Hello, world!"
self.data_tampered = b"Goodbye, world!"
self.signature_tampered = bytes(70) # 0x00...00
def test_sign_verify(self):
signature = dsa.sign(self.private, self.data)
self.assertTrue(dsa.verify(self.public, self.data, signature))
def test_reject_tampered_data(self):
signature = dsa.sign(self.private, self.data)
self.assertFalse(dsa.verify(self.public, self.data_tampered, signature))
def test_reject_tampered_signature(self):
self.assertFalse(dsa.verify(self.public, self.data, self.signature_tampered))
if __name__ == '__main__':
unittest.main()