summaryrefslogtreecommitdiff
path: root/rsa/__init__.py
diff options
context:
space:
mode:
authorBarry Mead <barrymead@cox.net>2010-02-17 04:44:59 -0700
committerBarry Mead <barrymead@cox.net>2010-02-17 04:44:59 -0700
commit86a8862cf3b2719794af3af29560c300ef01cd10 (patch)
treea039ab44a62e499e1a830e74bab4d9315c6903e3 /rsa/__init__.py
parent1bb49644927ce1c333c2f83e6b498b469c5ae80b (diff)
downloadrsa-86a8862cf3b2719794af3af29560c300ef01cd10.tar.gz
Corrected __contains__ and made exceptions come first
Diffstat (limited to 'rsa/__init__.py')
-rw-r--r--rsa/__init__.py24
1 files changed, 12 insertions, 12 deletions
diff --git a/rsa/__init__.py b/rsa/__init__.py
index 68f5953..4e499fc 100644
--- a/rsa/__init__.py
+++ b/rsa/__init__.py
@@ -496,32 +496,32 @@ def gluechops(string, key, n, funcref):
def encrypt(message, key):
"""Encrypts a string 'message' with the public key 'key'"""
- if key.__contains__('n'):
- return chopstring(message, key['e'], key['n'], encrypt_int)
- else:
+ if 'n' not in key:
raise Exception("You must use the public key with encrypt")
+ return chopstring(message, key['e'], key['n'], encrypt_int)
+
def sign(message, key):
"""Signs a string 'message' with the private key 'key'"""
- if key.__contains__('p'):
- return chopstring(message, key['d'], key['p']*key['q'], encrypt_int)
- else:
+ if 'p' not in key:
raise Exception("You must use the private key with sign")
+ return chopstring(message, key['d'], key['p']*key['q'], encrypt_int)
+
def decrypt(cypher, key):
"""Decrypts a cypher with the private key 'key'"""
- if key.__contains__('p'):
- return gluechops(cypher, key['d'], key['p']*key['q'], decrypt_int)
- else:
+ if 'p' not in key:
raise Exception("You must use the private key with decrypt")
+ return gluechops(cypher, key['d'], key['p']*key['q'], decrypt_int)
+
def verify(cypher, key):
"""Verifies a cypher with the public key 'key'"""
- if key.__contains__('n'):
- return gluechops(cypher, key['e'], key['n'], decrypt_int)
- else:
+ if 'n' not in key:
raise Exception("You must use the public key with verify")
+ return gluechops(cypher, key['e'], key['n'], decrypt_int)
+
# Do doctest if we're not imported
if __name__ == "__main__":
import doctest