From 7498bf51d85f98d67d72193dc01db2afb83aeaf3 Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Fri, 4 Dec 2020 12:36:58 +0100 Subject: Raise exceptions from except properly --- otp2289/generator.py | 4 ++-- otp2289/server.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'otp2289') 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: hash_algo, step, seed = challenge[4:].split() return (seed, hash_algo, int(step)) except ValueError: - raise OTPChallengeException('Invalid challenge') + raise OTPChallengeException('Invalid challenge') from None @staticmethod def sha1_digest_folding(sha1_digest): @@ -506,7 +506,7 @@ class OTPGenerator: tokens] except ValueError: raise OTPGeneratorException( - 'One or more words not present in RFC1760') + 'One or more words not present in RFC1760') from None # now we build a string of bits bit_stream = format(token_ints[0], '011b') 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: self._hash_algo = OTPGenerator.validate_hash_algo(hash_algo) self._step = OTPGenerator.validate_step(current_step) except OTPGeneratorException as exp: - raise OTPStateException(exp.args[0]) + raise OTPStateException(exp.args[0]) from None self._current_digest = None if ot_hex is not None: self._current_digest = self.validate_hex(ot_hex) @@ -166,7 +166,7 @@ class OTPState: return OTPState.validate_hex(response) except OTPStateException: raise OTPInvalidResponse( - 'The response is neither a valid token or hex') + 'The response is neither a valid token or hex') from None @staticmethod def validate_hex(ot_hex): @@ -192,7 +192,7 @@ class OTPState: try: return binascii.unhexlify(ot_hex) except binascii.Error: - raise OTPStateException('Invalid OT-hex') + raise OTPStateException('Invalid OT-hex') from None def get_next_state(self): """ -- cgit v1.3