summaryrefslogtreecommitdiff
path: root/rsa/pkcs1_v2.py
diff options
context:
space:
mode:
authorRam Rachum <ram@rachum.com>2020-06-19 23:39:00 +0300
committerSybren A. Stüvel <sybren@stuvel.eu>2021-02-24 13:19:55 +0100
commit1a5b2d166fc95e5f3f07fdfec075acdf4d0eda92 (patch)
tree94973309e96f59a1367819c51240e2059aaca288 /rsa/pkcs1_v2.py
parentb8ac79fdbc28d3ad5e15c50930d223e98df10487 (diff)
downloadrsa-git-1a5b2d166fc95e5f3f07fdfec075acdf4d0eda92.tar.gz
Fix exception causes all over the codebase
The mistake is this: In some parts of the code, an exception is being caught and replaced with a more user-friendly error. In these cases the syntax `raise new_error from old_error` needs to be used. Python's exception chaining means it shows not only the traceback of the current exception, but that of the original exception (and possibly more.) This is regardless of `raise from`. The usage of `raise from` tells Python to put a more accurate message between the tracebacks. Instead of this: During handling of the above exception, another exception occurred: You'll get this: The above exception was the direct cause of the following exception: The first is inaccurate, because it signifies a bug in the exception-handling code itself, which is a separate situation than wrapping an exception.
Diffstat (limited to 'rsa/pkcs1_v2.py')
-rw-r--r--rsa/pkcs1_v2.py4
1 files changed, 2 insertions, 2 deletions
diff --git a/rsa/pkcs1_v2.py b/rsa/pkcs1_v2.py
index f780aff..ed616f5 100644
--- a/rsa/pkcs1_v2.py
+++ b/rsa/pkcs1_v2.py
@@ -49,12 +49,12 @@ def mgf1(seed: bytes, length: int, hasher: str = 'SHA-1') -> bytes:
try:
hash_length = pkcs1.HASH_METHODS[hasher]().digest_size
- except KeyError:
+ except KeyError as ex:
raise ValueError(
'Invalid `hasher` specified. Please select one of: {hash_list}'.format(
hash_list=', '.join(sorted(pkcs1.HASH_METHODS.keys()))
)
- )
+ ) from ex
# If l > 2^32(hLen), output "mask too long" and stop.
if length > (2**32 * hash_length):