summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSybren A. Stüvel <sybren@stuvel.eu>2016-03-17 16:12:55 +0100
committerSybren A. Stüvel <sybren@stuvel.eu>2016-03-17 16:12:55 +0100
commitff7f0c7ae75e8aa56a1ad338185004077a854e17 (patch)
tree200c62058600387f34be7271a382d295df623e0d /tests
parentbb27408398923b746c81282fb738b70b1015f912 (diff)
downloadrsa-git-ff7f0c7ae75e8aa56a1ad338185004077a854e17.tar.gz
Added unit test for rsa.util.private_to_public()
Diffstat (limited to 'tests')
-rw-r--r--tests/test_cli.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/test_cli.py b/tests/test_cli.py
index 511d25d..aad734a 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -14,6 +14,7 @@ from io import StringIO, BytesIO
import rsa
import rsa.cli
+import rsa.util
from rsa._compat import b
if sys.version_info[0] < 3:
@@ -278,3 +279,21 @@ class SignVerifyTest(AbstractCliTest):
with cli_args('-i', 'cleartext.txt', self.pub_fname, 'signature.txt'):
with captured_output() as (out, err):
self.assertExits('Verification failed.', rsa.cli.verify)
+
+
+class PrivatePublicTest(AbstractCliTest):
+ """Test CLI command to convert a private to a public key."""
+
+ @cleanup_files('test_private_to_public.pem')
+ def test_private_to_public(self):
+
+ with cli_args('-i', self.priv_fname, '-o', 'test_private_to_public.pem'):
+ with captured_output():
+ rsa.util.private_to_public()
+
+ # Check that the key is indeed valid.
+ with open('test_private_to_public.pem', 'rb') as pemfile:
+ key = rsa.PublicKey.load_pkcs1(pemfile.read())
+
+ self.assertEqual(self.priv_key.n, key.n)
+ self.assertEqual(self.priv_key.e, key.e)