summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimeon Simeonov2020-12-04 12:36:58 +0100
committerSimeon Simeonov2020-12-04 12:36:58 +0100
commit7498bf51d85f98d67d72193dc01db2afb83aeaf3 (patch)
treef92f504d3d056dbb09e10c63f06e17201d2b76f1
parentc1378156e2ae02c37d0b19b033cad20f72bcd37d (diff)
Raise exceptions from except properly
-rw-r--r--otp2289/generator.py4
-rw-r--r--otp2289/server.py6
2 files changed, 5 insertions, 5 deletions
diff --git a/otp2289/generator.py b/otp2289/generator.py
index 723ed04..5ea738b 100644
--- a/otp2289/generator.py
+++ b/otp2289/generator.py
@@ -407,7 +407,7 @@ class OTPGenerator:
407 hash_algo, step, seed = challenge[4:].split() 407 hash_algo, step, seed = challenge[4:].split()
408 return (seed, hash_algo, int(step)) 408 return (seed, hash_algo, int(step))
409 except ValueError: 409 except ValueError:
410 raise OTPChallengeException('Invalid challenge') 410 raise OTPChallengeException('Invalid challenge') from None
411 411
412 @staticmethod 412 @staticmethod
413 def sha1_digest_folding(sha1_digest): 413 def sha1_digest_folding(sha1_digest):
@@ -506,7 +506,7 @@ class OTPGenerator:
506 tokens] 506 tokens]
507 except ValueError: 507 except ValueError:
508 raise OTPGeneratorException( 508 raise OTPGeneratorException(
509 'One or more words not present in RFC1760') 509 'One or more words not present in RFC1760') from None
510 # now we build a string of bits 510 # now we build a string of bits
511 bit_stream = format(token_ints[0], '011b') 511 bit_stream = format(token_ints[0], '011b')
512 bit_stream += format(token_ints[1], '011b') 512 bit_stream += format(token_ints[1], '011b')
diff --git a/otp2289/server.py b/otp2289/server.py
index 7322727..d0c3e01 100644
--- a/otp2289/server.py
+++ b/otp2289/server.py
@@ -79,7 +79,7 @@ class OTPState:
79 self._hash_algo = OTPGenerator.validate_hash_algo(hash_algo) 79 self._hash_algo = OTPGenerator.validate_hash_algo(hash_algo)
80 self._step = OTPGenerator.validate_step(current_step) 80 self._step = OTPGenerator.validate_step(current_step)
81 except OTPGeneratorException as exp: 81 except OTPGeneratorException as exp:
82 raise OTPStateException(exp.args[0]) 82 raise OTPStateException(exp.args[0]) from None
83 self._current_digest = None 83 self._current_digest = None
84 if ot_hex is not None: 84 if ot_hex is not None:
85 self._current_digest = self.validate_hex(ot_hex) 85 self._current_digest = self.validate_hex(ot_hex)
@@ -166,7 +166,7 @@ class OTPState:
166 return OTPState.validate_hex(response) 166 return OTPState.validate_hex(response)
167 except OTPStateException: 167 except OTPStateException:
168 raise OTPInvalidResponse( 168 raise OTPInvalidResponse(
169 'The response is neither a valid token or hex') 169 'The response is neither a valid token or hex') from None
170 170
171 @staticmethod 171 @staticmethod
172 def validate_hex(ot_hex): 172 def validate_hex(ot_hex):
@@ -192,7 +192,7 @@ class OTPState:
192 try: 192 try:
193 return binascii.unhexlify(ot_hex) 193 return binascii.unhexlify(ot_hex)
194 except binascii.Error: 194 except binascii.Error:
195 raise OTPStateException('Invalid OT-hex') 195 raise OTPStateException('Invalid OT-hex') from None
196 196
197 def get_next_state(self): 197 def get_next_state(self):
198 """ 198 """