From f61bbe69fa3593c2a60bf296add756e920941eeb Mon Sep 17 00:00:00 2001 From: Tom Cocagne Date: Tue, 30 Nov 2010 16:18:44 -0500 Subject: added parameter error checking --- _ctsrp.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to '_ctsrp.py') diff --git a/_ctsrp.py b/_ctsrp.py index 57b8283..83eccb7 100644 --- a/_ctsrp.py +++ b/_ctsrp.py @@ -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) -- cgit v1.2.3