@@ -40,7 +40,6 @@ use primitives::{H256, H520};
4040use rlp:: { Decodable , DecoderError , Encodable , RlpStream , UntrustedRlp } ;
4141use rustc_hex:: { FromHex , ToHex } ;
4242use secp256k1:: { key, Error as SecpError , Message as SecpMessage , RecoverableSignature , RecoveryId } ;
43- use serde:: de:: Error as SerdeError ;
4443use serde:: { Deserialize , Deserializer , Serialize , Serializer } ;
4544
4645use super :: { public_to_address, Address , Error , Message , Private , Public , SECP256K1 } ;
@@ -199,39 +198,31 @@ impl Serialize for ECDSASignature {
199198 fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
200199 where
201200 S : Serializer , {
202- serializer. serialize_str ( & self . 0 . to_hex ( ) )
201+ let data: H520 = self . 0 . into ( ) ;
202+ data. serialize ( serializer)
203203 }
204204}
205205
206206impl < ' a > Deserialize < ' a > for ECDSASignature {
207207 fn deserialize < D > ( deserializer : D ) -> Result < Self , D :: Error >
208208 where
209209 D : Deserializer < ' a > , {
210- let s = String :: deserialize ( deserializer) ?;
211- let data = s. from_hex ( ) . map_err ( |e| SerdeError :: custom ( format ! ( "Invalid signature {}" , e) ) ) ?;
212- if data. len ( ) != 65 {
213- return Err ( SerdeError :: custom ( format ! ( "Invalid signature" ) ) )
214- }
215- let bytes = {
216- let mut array = [ 0 ; 65 ] ;
217- array. copy_from_slice ( & data) ;
218- array
219- } ;
220- Ok ( ECDSASignature ( bytes) )
210+ let data = H520 :: deserialize ( deserializer) ?;
211+ Ok ( Self :: from ( data) )
221212 }
222213}
223214
224215impl Encodable for ECDSASignature {
225216 fn rlp_append ( & self , s : & mut RlpStream ) {
226217 let data: H520 = self . 0 . into ( ) ;
227- s . append_single_value ( & data ) ;
218+ data . rlp_append ( s ) ;
228219 }
229220}
230221
231222impl Decodable for ECDSASignature {
232223 fn decode ( rlp : & UntrustedRlp ) -> Result < Self , DecoderError > {
233- let data: H520 = rlp . as_val ( ) ?;
234- Ok ( ECDSASignature :: from ( data) )
224+ let data = H520 :: decode ( rlp ) ?;
225+ Ok ( Self :: from ( data) )
235226 }
236227}
237228
0 commit comments