summaryrefslogtreecommitdiff
path: root/rsa/core.py
diff options
context:
space:
mode:
authorSybren A. Stüvel <sybren@stuvel.eu>2011-07-10 01:35:46 +0200
committerSybren A. Stüvel <sybren@stuvel.eu>2011-07-10 01:35:46 +0200
commit65f254fcf1928740c4828c9287aada3197525d56 (patch)
treee2e1ea230eb30723d6b23b2bc203899a31f7001c /rsa/core.py
parent2cc58a8604facfb130579958466c2b71a5146cbd (diff)
downloadrsa-git-65f254fcf1928740c4828c9287aada3197525d56.tar.gz
Reinstated some of the backed out changeset 812d745b6bef:
- added support for block size - improved some exceptions
Diffstat (limited to 'rsa/core.py')
-rwxr-xr-xrsa/core.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/rsa/core.py b/rsa/core.py
index 8f989df..2df4be5 100755
--- a/rsa/core.py
+++ b/rsa/core.py
@@ -17,8 +17,11 @@ def encrypt_int(message, ekey, n):
if not type(message) is types.LongType:
raise TypeError("You must pass a long or int")
- if message < 0 or message > n:
- raise OverflowError("The message is too long")
+ if message < 0:
+ raise ValueError('Only non-negative numbers are supported')
+
+ if message > n:
+ raise OverflowError("The message %i is too long for n=%i" % (message, n))
#Note: Bit exponents start at zero (bit counts start at 1) this is correct
safebit = rsa.common.bit_size(n) - 2 # compute safe bit (MSB - 1)