diff options
author | Tom Cocagne <devnull@localhost> | 2010-11-30 16:18:44 -0500 |
---|---|---|
committer | Tom Cocagne <devnull@localhost> | 2010-11-30 16:18:44 -0500 |
commit | f61bbe69fa3593c2a60bf296add756e920941eeb (patch) | |
tree | dc1291d5b2092ec14a2393abb0cf24ae5157e564 /_ctsrp.py | |
parent | d518af18513e0a14a9791a209643d19eeaa6567a (diff) |
added parameter error checking
Diffstat (limited to '_ctsrp.py')
-rw-r--r-- | _ctsrp.py | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -281,6 +281,8 @@ def get_ngk( hash_class, ng_type, n_hex, g_hex ): def gen_sv( username, password, hash_alg=SHA1, ng_type=NG_1024, n_hex=None, g_hex=None ):
+ if ng_type == NG_CUSTOM and (n_hex is None or g_hex is None):
+ raise ValueError("Both n_hex and g_hex are required when ng_type = NG_CUSTOM")
s = BN_new()
v = BN_new()
x = BN_new()
@@ -312,6 +314,8 @@ def gen_sv( username, password, hash_alg=SHA1, ng_type=NG_1024, n_hex=None, g_he class Verifier (object):
def __init__(self, username, bytes_s, bytes_v, bytes_A, hash_alg=SHA1, ng_type=NG_1024, n_hex=None, g_hex=None):
+ if ng_type == NG_CUSTOM and (n_hex is None or g_hex is None):
+ raise ValueError("Both n_hex and g_hex are required when ng_type = NG_CUSTOM")
self.A = BN_new()
self.B = BN_new()
self.K = None
@@ -369,6 +373,8 @@ class Verifier (object): def __del__(self):
+ if not hasattr(self, 'A'):
+ return # __init__ threw exception. no clean up required
BN_free(self.A)
BN_free(self.B)
BN_free(self.S)
@@ -414,6 +420,8 @@ class Verifier (object): class User (object):
def __init__(self, username, password, hash_alg=SHA1, ng_type=NG_1024, n_hex=None, g_hex=None):
+ if ng_type == NG_CUSTOM and (n_hex is None or g_hex is None):
+ raise ValueError("Both n_hex and g_hex are required when ng_type = NG_CUSTOM")
self.username = username
self.password = password
self.a = BN_new()
@@ -447,6 +455,8 @@ class User (object): def __del__(self):
+ if not hasattr(self, 'a'):
+ return # __init__ threw exception. no clean up required
BN_free(self.a)
BN_free(self.A)
BN_free(self.B)
|