Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Use get_algorithm_by_name in _verify_signature
Rather than catching the KeyError from a dict lookup, catch the
NotImplementedError raised by get_algorithm_by_name. This changes the
exception seen in the cause under exception chaining but otherwise has
no public-facing impact.
  • Loading branch information
sirosen committed Jun 29, 2022
commit e612fbd19006b068afc29d646e282b80d0a909d2
13 changes: 6 additions & 7 deletions jwt/api_jws.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,13 @@ def _verify_signature(
raise InvalidAlgorithmError("The specified alg value is not allowed")

try:
alg_obj = self._algorithms[alg]
key = alg_obj.prepare_key(key)

if not alg_obj.verify(signing_input, key, signature):
raise InvalidSignatureError("Signature verification failed")

except KeyError as e:
alg_obj = self.get_algorithm_by_name(alg)
except NotImplementedError as e:
raise InvalidAlgorithmError("Algorithm not supported") from e
key = alg_obj.prepare_key(key)

if not alg_obj.verify(signing_input, key, signature):
raise InvalidSignatureError("Signature verification failed")

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