summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSybren A. Stüvel <sybren@stuvel.eu>2016-03-29 18:18:50 +0200
committerSybren A. Stüvel <sybren@stuvel.eu>2016-03-29 18:18:50 +0200
commitfec61ece4c1593e79bc52c84cf69a715cd6a9dcd (patch)
tree50704c98620da43340cb1fd64cb576dbcdf12294 /tests
parent46b72a462dbd7955f7e8f13cef1b1a3cb0af2c51 (diff)
downloadrsa-git-fec61ece4c1593e79bc52c84cf69a715cd6a9dcd.tar.gz
Added unittest for rsa.key.gen_keys
This unittest tests both execution branches of the function (keys relatively prime or not), reducing randomness of code coverage.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_key.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/test_key.py b/tests/test_key.py
index 0e62f55..24f6501 100644
--- a/tests/test_key.py
+++ b/tests/test_key.py
@@ -40,3 +40,20 @@ class KeyGenTest(unittest.TestCase):
self.assertEqual(0x10001, priv.e)
self.assertEqual(0x10001, pub.e)
+
+ def test_custom_getprime_func(self):
+ # List of primes to test with, in order [p, q, p, q, ....]
+ primes = [64123, 50957, 39317, 33107]
+
+ def getprime(_):
+ return primes.pop(0)
+
+ # This exponent will cause two other primes to be generated.
+ exponent = 136407
+
+ (p, q, e, d) = rsa.key.gen_keys(64,
+ accurate=False,
+ getprime_func=getprime,
+ exponent=exponent)
+ self.assertEqual(39317, p)
+ self.assertEqual(33107, q)