@@ -9,6 +9,15 @@ use crate::{
99use log:: error;
1010use std:: convert:: { TryFrom , TryInto } ;
1111
12+ #[ cfg( feature = "abstraction" ) ]
13+ use {
14+ ecdsa:: SignatureSize ,
15+ elliptic_curve:: {
16+ generic_array:: { typenum:: Unsigned , ArrayLength } ,
17+ FieldBytes , FieldBytesSize , PrimeCurve ,
18+ } ,
19+ } ;
20+
1221/// Type holding RSA signature information.
1322///
1423/// For more information about the contents of `signature` see Annex B
@@ -143,3 +152,31 @@ impl TryFrom<TPMS_SIGNATURE_ECC> for EccSignature {
143152 } )
144153 }
145154}
155+
156+ #[ cfg( feature = "abstraction" ) ]
157+ impl < C > TryFrom < EccSignature > for ecdsa:: Signature < C >
158+ where
159+ C : PrimeCurve ,
160+ SignatureSize < C > : ArrayLength < u8 > ,
161+ {
162+ type Error = Error ;
163+
164+ fn try_from ( signature : EccSignature ) -> Result < Self > {
165+ let r = signature. signature_r ( ) . as_slice ( ) ;
166+ let s = signature. signature_s ( ) . as_slice ( ) ;
167+
168+ if r. len ( ) != FieldBytesSize :: < C > :: USIZE {
169+ return Err ( Error :: local_error ( WrapperErrorKind :: InvalidParam ) ) ;
170+ }
171+ if s. len ( ) != FieldBytesSize :: < C > :: USIZE {
172+ return Err ( Error :: local_error ( WrapperErrorKind :: InvalidParam ) ) ;
173+ }
174+
175+ let signature = ecdsa:: Signature :: from_scalars (
176+ FieldBytes :: < C > :: from_slice ( r) . clone ( ) ,
177+ FieldBytes :: < C > :: from_slice ( s) . clone ( ) ,
178+ )
179+ . map_err ( |_| Error :: local_error ( WrapperErrorKind :: InvalidParam ) ) ?;
180+ Ok ( signature)
181+ }
182+ }
0 commit comments