Skip to content

Commit 1451d70

Browse files
akxauvipyCopilot
authored
fix: do not store reference to algorithms dict on PyJWK (#1143)
* fix: do not store reference to algorithms dict on PyJWK * Update CHANGELOG.rst Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Asif Saif Uddin {"Auvi":"অভি"} <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent f3ba74c commit 1451d70

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Fixed
1212

1313
- Annotate PyJWKSet.keys for pyright by @tamird in `#1134 <https://github.com/jpadilla/pyjwt/pull/1134>`__
1414
- Close ``HTTPError`` response to prevent ``ResourceWarning`` on Python 3.14 by @veeceey in `#1133 <https://github.com/jpadilla/pyjwt/pull/1133>`__
15+
- Do not keep ``algorithms`` dict in PyJWK instances by @akx in `#1143 <https://github.com/jpadilla/pyjwt/pull/1143>`__
1516

1617
Added
1718
~~~~~

jwt/api_jwk.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ def __init__(self, jwk_data: JWKDict, algorithm: str | None = None) -> None:
2828
:raises MissingCryptographyError: If the algorithm requires ``cryptography`` to be installed and it is not available.
2929
:raises PyJWKError: If unable to find an algorithm for the key.
3030
"""
31-
self._algorithms = get_default_algorithms()
3231
self._jwk_data = jwk_data
3332

3433
kty = self._jwk_data.get("kty", None)
@@ -73,10 +72,12 @@ def __init__(self, jwk_data: JWKDict, algorithm: str | None = None) -> None:
7372

7473
self.algorithm_name = algorithm
7574

76-
if algorithm in self._algorithms:
77-
self.Algorithm = self._algorithms[algorithm]
78-
else:
79-
raise PyJWKError(f"Unable to find an algorithm for key: {self._jwk_data}")
75+
try:
76+
self.Algorithm = get_default_algorithms()[algorithm]
77+
except KeyError:
78+
raise PyJWKError(
79+
f"Unable to find an algorithm for key: {self._jwk_data}",
80+
) from None
8081

8182
self.key = self.Algorithm.from_jwk(self._jwk_data)
8283

0 commit comments

Comments
 (0)