Skip to content
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