@@ -27,6 +27,11 @@ class ECDSAECKey(Key):
27
27
SHA384 : ecdsa .curves .NIST384p ,
28
28
SHA512 : ecdsa .curves .NIST521p ,
29
29
}
30
+ CURVE_NAMES = (
31
+ (ecdsa .curves .NIST256p , "P-256" ),
32
+ (ecdsa .curves .NIST384p , "P-384" ),
33
+ (ecdsa .curves .NIST521p , "P-521" ),
34
+ )
30
35
31
36
def __init__ (self , key , algorithm ):
32
37
if algorithm not in ALGORITHMS .EC :
@@ -119,12 +124,12 @@ def to_dict(self):
119
124
public_key = self .prepared_key .get_verifying_key ()
120
125
else :
121
126
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 } " )
128
133
129
134
# Calculate the key size in bytes. Section 6.2.1.2 and 6.2.1.3 of
130
135
# RFC7518 prescribes that the 'x', 'y' and 'd' parameters of the curve
0 commit comments