@@ -9,6 +9,15 @@ use crate::{
9
9
use log:: error;
10
10
use std:: convert:: { TryFrom , TryInto } ;
11
11
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
+
12
21
/// Type holding RSA signature information.
13
22
///
14
23
/// For more information about the contents of `signature` see Annex B
@@ -143,3 +152,31 @@ impl TryFrom<TPMS_SIGNATURE_ECC> for EccSignature {
143
152
} )
144
153
}
145
154
}
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