Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exception chaining #702

Merged
merged 1 commit into from
Oct 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions jwt/api_jws.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@ def encode(
key = alg_obj.prepare_key(key)
signature = alg_obj.sign(signing_input, key)

except KeyError:
except KeyError as e:
if not has_crypto and algorithm in requires_cryptography:
raise NotImplementedError(
"Algorithm '%s' could not be found. Do you have cryptography "
"installed?" % algorithm
)
) from e
else:
raise NotImplementedError("Algorithm not supported")
raise NotImplementedError("Algorithm not supported") from e

segments.append(base64url_encode(signature))

Expand Down Expand Up @@ -236,8 +236,8 @@ def _verify_signature(
if not alg_obj.verify(signing_input, key, signature):
raise InvalidSignatureError("Signature verification failed")

except KeyError:
raise InvalidAlgorithmError("Algorithm not supported")
except KeyError as e:
raise InvalidAlgorithmError("Algorithm not supported") from e

def _validate_headers(self, headers):
if "kid" in headers:
Expand Down