@@ -11,6 +11,9 @@ use elliptic_curve::{
1111    FieldBytes ,  FieldBytesSize ,  PrimeCurve , 
1212} ; 
1313
14+ #[ cfg( all( feature = "rustcrypto" ,  feature = "rsa" ) ) ]  
15+ use  crate :: structures:: Signature ; 
16+ 
1417impl < C >  TryFrom < EccSignature >  for  ecdsa:: Signature < C > 
1518where 
1619    C :  PrimeCurve , 
3841    } 
3942} 
4043
41- // TODO(baloo): impl TryFrom<RsaSignature> for rsa::pkcs1v15::Signature 
42- // TODO(baloo): impl TryFrom<RsaSignature> for rsa::pss::Signature 
44+ // Note: this does not implement `TryFrom<RsaSignature>` because `RsaSignature` does not carry the 
45+ // information whether the signatures was generated using PKCS#1v1.5 or PSS. 
46+ #[ cfg( all( feature = "rustcrypto" ,  feature = "rsa" ) ) ]  
47+ impl  TryFrom < Signature >  for  rsa:: pkcs1v15:: Signature  { 
48+     type  Error  = Error ; 
49+ 
50+     fn  try_from ( signature :  Signature )  -> Result < Self >  { 
51+         let  Signature :: RsaSsa ( signature)  = signature else  { 
52+             return  Err ( Error :: local_error ( WrapperErrorKind :: InvalidParam ) ) ; 
53+         } ; 
54+ 
55+         Self :: try_from ( signature. signature ( ) . as_bytes ( ) ) 
56+             . map_err ( |_| Error :: local_error ( WrapperErrorKind :: InvalidParam ) ) 
57+     } 
58+ } 
59+ 
60+ // Note: this does not implement `TryFrom<RsaSignature>` because `RsaSignature` does not carry the 
61+ // information whether the signatures was generated using PKCS#1v1.5 or PSS. 
62+ #[ cfg( all( feature = "rustcrypto" ,  feature = "rsa" ) ) ]  
63+ impl  TryFrom < Signature >  for  rsa:: pss:: Signature  { 
64+     type  Error  = Error ; 
65+ 
66+     fn  try_from ( signature :  Signature )  -> Result < Self >  { 
67+         let  Signature :: RsaPss ( signature)  = signature else  { 
68+             return  Err ( Error :: local_error ( WrapperErrorKind :: InvalidParam ) ) ; 
69+         } ; 
70+ 
71+         Self :: try_from ( signature. signature ( ) . as_bytes ( ) ) 
72+             . map_err ( |_| Error :: local_error ( WrapperErrorKind :: InvalidParam ) ) 
73+     } 
74+ } 
0 commit comments