From bcbf8feacfed3b905ef024e59a5da114c0234bc9 Mon Sep 17 00:00:00 2001 From: William Grant Date: Thu, 17 Mar 2011 22:47:50 +1100 Subject: [PATCH] Add int2str/str2int tests. --- dkim/tests/test_crypto.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/dkim/tests/test_crypto.py b/dkim/tests/test_crypto.py index f882e92..9dbcb40 100644 --- a/dkim/tests/test_crypto.py +++ b/dkim/tests/test_crypto.py @@ -25,9 +25,26 @@ from dkim import ( from dkim.crypto import ( DigestTooLargeError, EMSA_PKCS1_v1_5_encode, + int2str, + str2int, ) +class TestStrIntConversion(unittest.TestCase): + + def test_str2int(self): + self.assertEquals(1234, str2int('\x04\xd2')) + + def test_int2str(self): + self.assertEquals('\x04\xd2', int2str(1234)) + + def test_int2str_with_length(self): + self.assertEquals('\x00\x00\x04\xd2', int2str(1234, 4)) + + def test_int2str_fails_on_negative(self): + self.assertRaises(AssertionError, int2str, -1) + + class TestEMSA_PKCS1_v1_5(unittest.TestCase): def test_encode_sha256(self):