Skip to content

Commit c7921da

Browse files
committed
fix(jwk): raise InvalidKeyCurveError when generate ECKey with invalid crv
1 parent 6db656f commit c7921da

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/joserfc/_rfc7518/ec_key.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
SECP521R1,
1515
)
1616
from cryptography.hazmat.backends import default_backend
17-
from ..errors import InvalidExchangeKeyError
17+
from ..errors import InvalidExchangeKeyError, InvalidKeyCurveError
1818
from .._rfc7517.models import CurveKey
1919
from .._rfc7517.pem import CryptographyBinding
2020
from .._rfc7517.types import KeyParameters, AnyKey
@@ -51,7 +51,7 @@ def register_curve(cls, name: str, curve: t.Type[EllipticCurve]) -> None:
5151
@classmethod
5252
def generate_private_key(cls, name: str) -> EllipticCurvePrivateKey:
5353
if name not in cls._dss_curves:
54-
raise ValueError("Invalid crv value: '{}'".format(name))
54+
raise InvalidKeyCurveError("Invalid crv value: '{}'".format(name))
5555

5656
curve = cls._dss_curves[name]()
5757
raw_key = generate_private_key(

tests/jwk/test_ec_key.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
from unittest import TestCase
22
from joserfc.jwk import ECKey, OctKey
3-
from joserfc.errors import InvalidExchangeKeyError, InvalidKeyTypeError
3+
from joserfc.errors import (
4+
InvalidExchangeKeyError,
5+
InvalidKeyTypeError,
6+
InvalidKeyCurveError,
7+
)
48
from tests.keys import read_key
59

610

@@ -50,7 +54,7 @@ def test_import_from_native_keys(self):
5054
self.assertEqual(key, ECKey.import_key(key.private_key))
5155

5256
def test_generate_key(self):
53-
self.assertRaises(ValueError, ECKey.generate_key, "Invalid")
57+
self.assertRaises(InvalidKeyCurveError, ECKey.generate_key, "Invalid")
5458

5559
key = ECKey.generate_key(private=True)
5660
self.assertTrue(key.is_private)

0 commit comments

Comments
 (0)