summaryrefslogtreecommitdiff
path: root/rsa/key.py
diff options
context:
space:
mode:
authorSybren A. Stüvel <sybren@stuvel.eu>2016-03-29 18:20:17 +0200
committerSybren A. Stüvel <sybren@stuvel.eu>2016-03-29 18:20:17 +0200
commita5487826a1f28952a560c50f14e284c4292d94ca (patch)
tree3734791d7c65ded746a4187f1d1d4d3339087e97 /rsa/key.py
parentfec61ece4c1593e79bc52c84cf69a715cd6a9dcd (diff)
downloadrsa-git-a5487826a1f28952a560c50f14e284c4292d94ca.tar.gz
Introduced NotRelativePrimeError exception.
This makes catching exceptions slightly stronger, as it is now possible to check for this specific exception. Furthermore, information about the not-prime numbers is included in the exception object.
Diffstat (limited to 'rsa/key.py')
-rw-r--r--rsa/key.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/rsa/key.py b/rsa/key.py
index 40a7c83..a5afced 100644
--- a/rsa/key.py
+++ b/rsa/key.py
@@ -666,9 +666,11 @@ def calculate_keys_custom_exponent(p, q, exponent):
try:
d = rsa.common.inverse(exponent, phi_n)
- except ValueError:
- raise ValueError("e (%d) and phi_n (%d) are not relatively prime" %
- (exponent, phi_n))
+ except rsa.common.NotRelativePrimeError as ex:
+ raise rsa.common.NotRelativePrimeError(
+ exponent, phi_n, ex.d,
+ msg="e (%d) and phi_n (%d) are not relatively prime (divider=%i)" %
+ (exponent, phi_n, ex.d))
if (exponent * d) % phi_n != 1:
raise ValueError("e (%d) and d (%d) are not mult. inv. modulo "