summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSybren A. St?vel <sybren@stuvel.eu>2011-07-19 23:53:59 +0200
committerSybren A. St?vel <sybren@stuvel.eu>2011-07-19 23:53:59 +0200
commite9fc17cf57ec14e652f0effe4e85279ea5f2aba2 (patch)
treec4323bc70163ad4f1d92c5c531b2f599e509d991 /tests
parentf95a8b2bba01a4d6a1076b08dc7e3a74ba656b59 (diff)
downloadrsa-e9fc17cf57ec14e652f0effe4e85279ea5f2aba2.tar.gz
Added loading of DER and PEM encoded private keys
Diffstat (limited to 'tests')
-rw-r--r--tests/test_load_save_keys.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/test_load_save_keys.py b/tests/test_load_save_keys.py
new file mode 100644
index 0000000..695de72
--- /dev/null
+++ b/tests/test_load_save_keys.py
@@ -0,0 +1,47 @@
+'''Unittest for saving and loading keys.'''
+
+import base64
+import unittest
+
+import rsa.key
+
+B64PRIV_DER = 'MC4CAQACBQDeKYlRAgMBAAECBQDHn4npAgMA/icCAwDfxwIDANcXAgInbwIDAMZt'
+PRIVATE_DER = base64.decodestring(B64PRIV_DER)
+
+PRIVATE_PEM = '''
+-----BEGIN CONFUSING STUFF-----
+Cruft before the key
+
+-----BEGIN RSA PRIVATE KEY-----
+%s
+-----END RSA PRIVATE KEY-----
+
+Stuff after the key
+-----END CONFUSING STUFF-----
+''' % B64PRIV_DER
+
+
+class DerTest(unittest.TestCase):
+ '''Test saving and loading DER keys.'''
+
+ def test_load_private_key(self):
+ '''Test loading private DER keys.'''
+
+ key = rsa.key.load_private_key_der(PRIVATE_DER)
+ expected = rsa.key.PrivateKey(3727264081, 65537, 3349121513, 65063, 57287)
+
+ self.assertEqual(expected, key)
+
+
+class PemTest(unittest.TestCase):
+ '''Test saving and loading PEM keys.'''
+
+
+ def test_load_private_key(self):
+ '''Test loading private PEM files.'''
+
+ key = rsa.key.load_private_key_pem(PRIVATE_PEM)
+ expected = rsa.key.PrivateKey(3727264081, 65537, 3349121513, 65063, 57287)
+
+ self.assertEqual(expected, key)
+