diff options
author | Sybren A. St?vel <sybren@stuvel.eu> | 2011-07-24 18:29:17 +0200 |
---|---|---|
committer | Sybren A. St?vel <sybren@stuvel.eu> | 2011-07-24 18:29:17 +0200 |
commit | ac2d48aefb7b6ec801dcfed8385e9d674b8e2414 (patch) | |
tree | 06a760dd6da6ea9b134a125e0741cf7ddb105ef4 /tests | |
parent | 157c93ca1fa3293410b8d151719097c56c605e99 (diff) | |
download | rsa-ac2d48aefb7b6ec801dcfed8385e9d674b8e2414.tar.gz |
Added saving and loading public keys in PKCS#1 format (PEM+DER)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_load_save_keys.py | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/test_load_save_keys.py b/tests/test_load_save_keys.py index 5026afd..fca4241 100644 --- a/tests/test_load_save_keys.py +++ b/tests/test_load_save_keys.py @@ -8,6 +8,9 @@ import rsa.key B64PRIV_DER = 'MC4CAQACBQDeKYlRAgMBAAECBQDHn4npAgMA/icCAwDfxwIDANcXAgInbwIDAMZt' PRIVATE_DER = base64.decodestring(B64PRIV_DER) +B64PUB_DER = 'MAwCBQDeKYlRAgMBAAE=' +PUBLIC_DER = base64.decodestring(B64PUB_DER) + PRIVATE_PEM = ''' -----BEGIN CONFUSING STUFF----- Cruft before the key @@ -26,6 +29,24 @@ CLEAN_PRIVATE_PEM = '''\ -----END RSA PRIVATE KEY----- ''' % B64PRIV_DER +PUBLIC_PEM = ''' +-----BEGIN CONFUSING STUFF----- +Cruft before the key + +-----BEGIN RSA PUBLIC KEY----- +%s +-----END RSA PUBLIC KEY----- + +Stuff after the key +-----END CONFUSING STUFF----- +''' % B64PUB_DER + +CLEAN_PUBLIC_PEM = '''\ +-----BEGIN RSA PUBLIC KEY----- +%s +-----END RSA PUBLIC KEY----- +''' % B64PUB_DER + class DerTest(unittest.TestCase): '''Test saving and loading DER keys.''' @@ -46,6 +67,22 @@ class DerTest(unittest.TestCase): self.assertEqual(PRIVATE_DER, der) + def test_load_public_key(self): + '''Test loading public DER keys.''' + + key = rsa.key.PublicKey.load_pkcs1_der(PUBLIC_DER) + expected = rsa.key.PublicKey(3727264081, 65537) + + self.assertEqual(expected, key) + + def test_save_public_key(self): + '''Test saving public DER keys.''' + + key = rsa.key.PublicKey(3727264081, 65537) + der = key.save_pkcs1_der() + + self.assertEqual(PUBLIC_DER, der) + class PemTest(unittest.TestCase): '''Test saving and loading PEM keys.''' @@ -66,3 +103,20 @@ class PemTest(unittest.TestCase): self.assertEqual(CLEAN_PRIVATE_PEM, pem) + def test_load_public_key(self): + '''Test loading public PEM files.''' + + key = rsa.key.PublicKey.load_pkcs1_pem(PUBLIC_PEM) + expected = rsa.key.PublicKey(3727264081, 65537) + + self.assertEqual(expected, key) + + def test_save_public_key(self): + '''Test saving public PEM files.''' + + key = rsa.key.PublicKey(3727264081, 65537) + pem = key.save_pkcs1_pem() + + self.assertEqual(CLEAN_PUBLIC_PEM, pem) + + |