Skip to content

Commit fec61ec

Browse files
committed
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.
1 parent 46b72a4 commit fec61ec

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

tests/test_key.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,20 @@ def test_default_exponent(self):
4040

4141
self.assertEqual(0x10001, priv.e)
4242
self.assertEqual(0x10001, pub.e)
43+
44+
def test_custom_getprime_func(self):
45+
# List of primes to test with, in order [p, q, p, q, ....]
46+
primes = [64123, 50957, 39317, 33107]
47+
48+
def getprime(_):
49+
return primes.pop(0)
50+
51+
# This exponent will cause two other primes to be generated.
52+
exponent = 136407
53+
54+
(p, q, e, d) = rsa.key.gen_keys(64,
55+
accurate=False,
56+
getprime_func=getprime,
57+
exponent=exponent)
58+
self.assertEqual(39317, p)
59+
self.assertEqual(33107, q)

0 commit comments

Comments
 (0)