Repository navigation
Conversation
ECAlgorithm and OKPAlgorithm let cryptography's ValueError through when a PEM or SSH key can't be parsed, while RSAAlgorithm raises InvalidKeyError since jpadilla#952. Also list the expected key classes by name in the key type error instead of printing a generator object.
HardMax71
force-pushed
the
fix/ec-okp-invalid-key-error
branch
from
October 15, 2026 16:33
fad019d to
d886fcc
Compare
Author
|
@jpadilla could you review this when you have time? It raises InvalidKeyError for EC and OKP keys that can't be parsed. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1229
ECAlgorithm.prepare_keyandOKPAlgorithm.prepare_keylet cryptography'sValueError(orUnsupportedAlgorithm) through when a PEM or SSH key can't be parsed.RSAAlgorithmraisesInvalidKeyErrorfor the same input since #952, so code that catchesPyJWTErrorarounddecode()only breaks for EC and Ed25519 keys.load_pem_private_key, the same way RSA wraps its fallback.UnicodeDecodeError, which is aValueErrortoo, so that case is covered as well.check_crypto_key_type: join the class names, so the message readsExpected one of EllipticCurvePrivateKey, EllipticCurvePublicKey, got: RSAPublicKeyinstead of printing a generator object.Both new errors say "Could not parse the provided key." because EC and OKP try both public and private keys.
Tests: parametrized cases for EC (3 inputs) and OKP (4 inputs), plus a
matchon the existing EC wrong-key test for the message. All of them fail on master. The full suite passes with and without cryptography, andmypyand the pre-commit hooks pass. Changelog entry added under Unreleased.#1199 also rewrites
OKPAlgorithm.prepare_key, so whichever lands second needs a small rebase there.