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 --- _pysrp.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to '_pysrp.py') diff --git a/_pysrp.py b/_pysrp.py index 4674227..2f21bba 100644 --- a/_pysrp.py +++ b/_pysrp.py @@ -148,6 +148,8 @@ def gen_x( hash_class, salt, username, password ): 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") hash_class = _hash_map[ hash_alg ] N,g = get_ng( ng_type, n_hex, g_hex ) _s = long_to_bytes( get_random( 4 ) ) @@ -181,6 +183,8 @@ def calculate_H_AMK( hash_class, A, M, K ): 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.s = bytes_to_long(bytes_s) self.v = bytes_to_long(bytes_v) self.I = username @@ -241,7 +245,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") N,g = get_ng( ng_type, n_hex, g_hex ) hash_class = _hash_map[ hash_alg ] k = H( hash_class, N, g ) -- cgit v1.2.3