@@ -10,7 +10,7 @@ mod pkcs8;
1010
1111use crate :: { Curve , Error , FieldBytes , Result , ScalarValue } ;
1212use array:: typenum:: Unsigned ;
13- use common:: Generate ;
13+ use common:: { Generate , InvalidKey , KeySizeUser , TryKeyInit } ;
1414use core:: fmt:: { self , Debug } ;
1515use rand_core:: { CryptoRng , TryCryptoRng } ;
1616use subtle:: { Choice , ConstantTimeEq , CtOption } ;
@@ -276,8 +276,6 @@ where
276276 }
277277}
278278
279- impl < C > ZeroizeOnDrop for SecretKey < C > where C : Curve { }
280-
281279impl < C > Drop for SecretKey < C >
282280where
283281 C : Curve ,
@@ -286,6 +284,7 @@ where
286284 self . inner . zeroize ( ) ;
287285 }
288286}
287+ impl < C > ZeroizeOnDrop for SecretKey < C > where C : Curve { }
289288
290289impl < C : Curve > Eq for SecretKey < C > { }
291290
@@ -298,7 +297,10 @@ where
298297 }
299298}
300299
301- impl < C : Curve > Generate for SecretKey < C > {
300+ impl < C > Generate for SecretKey < C >
301+ where
302+ C : Curve ,
303+ {
302304 fn try_generate_from_rng < R : TryCryptoRng + ?Sized > (
303305 rng : & mut R ,
304306 ) -> core:: result:: Result < Self , R :: Error > {
@@ -308,6 +310,22 @@ impl<C: Curve> Generate for SecretKey<C> {
308310 }
309311}
310312
313+ impl < C > KeySizeUser for SecretKey < C >
314+ where
315+ C : Curve ,
316+ {
317+ type KeySize = C :: FieldBytesSize ;
318+ }
319+
320+ impl < C > TryKeyInit for SecretKey < C >
321+ where
322+ C : Curve ,
323+ {
324+ fn new ( key_bytes : & FieldBytes < C > ) -> core:: result:: Result < Self , InvalidKey > {
325+ Self :: from_bytes ( key_bytes) . map_err ( |_| InvalidKey )
326+ }
327+ }
328+
311329#[ cfg( feature = "sec1" ) ]
312330impl < C > sec1:: DecodeEcPrivateKey for SecretKey < C >
313331where
0 commit comments