Skip to content

Commit efe41c3

Browse files
authored
Fix compatibility issue - ecdsa Curve is not hashable. (#261)
1 parent e724fa0 commit efe41c3

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

jose/backends/ecdsa_backend.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ class ECDSAECKey(Key):
2727
SHA384: ecdsa.curves.NIST384p,
2828
SHA512: ecdsa.curves.NIST521p,
2929
}
30+
CURVE_NAMES = (
31+
(ecdsa.curves.NIST256p, "P-256"),
32+
(ecdsa.curves.NIST384p, "P-384"),
33+
(ecdsa.curves.NIST521p, "P-521"),
34+
)
3035

3136
def __init__(self, key, algorithm):
3237
if algorithm not in ALGORITHMS.EC:
@@ -119,12 +124,12 @@ def to_dict(self):
119124
public_key = self.prepared_key.get_verifying_key()
120125
else:
121126
public_key = self.prepared_key
122-
123-
crv = {
124-
ecdsa.curves.NIST256p: "P-256",
125-
ecdsa.curves.NIST384p: "P-384",
126-
ecdsa.curves.NIST521p: "P-521",
127-
}[self.prepared_key.curve]
127+
crv = None
128+
for key, value in self.CURVE_NAMES:
129+
if key == self.prepared_key.curve:
130+
crv = value
131+
if not crv:
132+
raise KeyError(f"Can't match {self.prepared_key.curve}")
128133

129134
# Calculate the key size in bytes. Section 6.2.1.2 and 6.2.1.3 of
130135
# RFC7518 prescribes that the 'x', 'y' and 'd' parameters of the curve

0 commit comments

Comments
 (0)