@@ -86,6 +86,67 @@ fn ecdsa_from_pkcs8_test() {
8686 ) ;
8787}
8888
89+ #[ test]
90+ fn ecdsa_from_der_test ( ) {
91+ test:: run (
92+ test_file ! ( "ecdsa_from_der_tests.txt" ) ,
93+ |section, test_case| {
94+ assert_eq ! ( section, "" ) ;
95+
96+ let curve_name = test_case. consume_string ( "Curve" ) ;
97+ let ( ( this_fixed, this_asn1) , ( other_fixed, other_asn1) ) = match curve_name. as_str ( ) {
98+ "P-256" => (
99+ (
100+ & signature:: ECDSA_P256_SHA256_FIXED_SIGNING ,
101+ & signature:: ECDSA_P256_SHA256_ASN1_SIGNING ,
102+ ) ,
103+ (
104+ & signature:: ECDSA_P384_SHA384_FIXED_SIGNING ,
105+ & signature:: ECDSA_P384_SHA384_ASN1_SIGNING ,
106+ ) ,
107+ ) ,
108+ "P-384" => (
109+ (
110+ & signature:: ECDSA_P384_SHA384_FIXED_SIGNING ,
111+ & signature:: ECDSA_P384_SHA384_ASN1_SIGNING ,
112+ ) ,
113+ (
114+ & signature:: ECDSA_P256_SHA256_FIXED_SIGNING ,
115+ & signature:: ECDSA_P256_SHA256_ASN1_SIGNING ,
116+ ) ,
117+ ) ,
118+ _ => unreachable ! ( ) ,
119+ } ;
120+
121+ let input = test_case. consume_bytes ( "Input" ) ;
122+
123+ let error = test_case. consume_optional_string ( "Error" ) ;
124+
125+ match (
126+ signature:: EcdsaKeyPair :: from_der ( this_fixed, & input) ,
127+ error. clone ( ) ,
128+ ) {
129+ ( Ok ( _) , None ) => ( ) ,
130+ ( Err ( e) , None ) => panic ! ( "Failed with error \" {}\" , but expected to succeed" , e) ,
131+ ( Ok ( _) , Some ( e) ) => panic ! ( "Succeeded, but expected error \" {}\" " , e) ,
132+ ( Err ( actual) , Some ( expected) ) => assert_eq ! ( format!( "{}" , actual) , expected) ,
133+ } ;
134+
135+ match ( signature:: EcdsaKeyPair :: from_der ( this_asn1, & input) , error) {
136+ ( Ok ( _) , None ) => ( ) ,
137+ ( Err ( e) , None ) => panic ! ( "Failed with error \" {}\" , but expected to succeed" , e) ,
138+ ( Ok ( _) , Some ( e) ) => panic ! ( "Succeeded, but expected error \" {}\" " , e) ,
139+ ( Err ( actual) , Some ( expected) ) => assert_eq ! ( format!( "{}" , actual) , expected) ,
140+ } ;
141+
142+ assert ! ( signature:: EcdsaKeyPair :: from_der( other_fixed, & input) . is_err( ) ) ;
143+ assert ! ( signature:: EcdsaKeyPair :: from_der( other_asn1, & input) . is_err( ) ) ;
144+
145+ Ok ( ( ) )
146+ } ,
147+ ) ;
148+ }
149+
89150// Verify that, at least, we generate PKCS#8 documents that we can read.
90151#[ test]
91152fn ecdsa_generate_pkcs8_test ( ) {
0 commit comments