File tree Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -45,7 +45,8 @@ fn curve_from_py_curve(
45
45
}
46
46
47
47
let py_curve_name = py_curve. getattr ( pyo3:: intern!( py, "name" ) ) ?;
48
- let nid = match & * py_curve_name. extract :: < pyo3:: pybacked:: PyBackedStr > ( ) ? {
48
+ let curve_name = & * py_curve_name. extract :: < pyo3:: pybacked:: PyBackedStr > ( ) ?;
49
+ let nid = match curve_name {
49
50
"secp192r1" => openssl:: nid:: Nid :: X9_62_PRIME192V1 ,
50
51
"secp224r1" => openssl:: nid:: Nid :: SECP224R1 ,
51
52
"secp256r1" => openssl:: nid:: Nid :: X9_62_PRIME256V1 ,
@@ -84,7 +85,12 @@ fn curve_from_py_curve(
84
85
}
85
86
} ;
86
87
87
- Ok ( openssl:: ec:: EcGroup :: from_curve_name ( nid) ?)
88
+ Ok ( openssl:: ec:: EcGroup :: from_curve_name ( nid) . map_err ( |_| {
89
+ exceptions:: UnsupportedAlgorithm :: new_err ( (
90
+ format ! ( "Curve {curve_name} is not supported" ) ,
91
+ exceptions:: Reasons :: UNSUPPORTED_ELLIPTIC_CURVE ,
92
+ ) )
93
+ } ) ?)
88
94
}
89
95
90
96
fn py_curve_from_curve < ' p > (
Original file line number Diff line number Diff line change @@ -331,6 +331,21 @@ def test_generate_unknown_curve(self, backend):
331
331
is False
332
332
)
333
333
334
+ @pytest .mark .skip_fips (
335
+ reason = "Some FIPS curves aren't supported but work anyways"
336
+ )
337
+ @pytest .mark .parametrize ("curve" , ec ._CURVE_TYPES .values ())
338
+ def test_generate_unsupported_curve (
339
+ self , backend , curve : ec .EllipticCurve
340
+ ):
341
+ if backend .elliptic_curve_supported (curve ):
342
+ return
343
+
344
+ with raises_unsupported_algorithm (
345
+ exceptions ._Reasons .UNSUPPORTED_ELLIPTIC_CURVE
346
+ ):
347
+ ec .generate_private_key (curve )
348
+
334
349
def test_unknown_signature_algoritm (self , backend ):
335
350
_skip_curve_unsupported (backend , ec .SECP192R1 ())
336
351
You can’t perform that action at this time.
0 commit comments