File tree Expand file tree Collapse file tree 1 file changed +25
-1
lines changed Expand file tree Collapse file tree 1 file changed +25
-1
lines changed Original file line number Diff line number Diff line change 20
20
21
21
use prelude:: * ;
22
22
23
- use io ;
23
+ use :: { EcdsaSig , io } ;
24
24
25
25
use blockdata:: script:: Script ;
26
26
use blockdata:: transaction:: { EcdsaSigHashType , Transaction , TxOut } ;
@@ -89,6 +89,30 @@ impl Deserialize for PublicKey {
89
89
}
90
90
}
91
91
92
+ impl Serialize for EcdsaSig {
93
+ fn serialize ( & self ) -> Vec < u8 > {
94
+ let mut buf = Vec :: with_capacity ( 72 ) ;
95
+ buf. extend ( self . sig . serialize_der ( ) . iter ( ) ) ;
96
+ buf. push ( self . hash_ty as u8 ) ;
97
+ buf
98
+ }
99
+ }
100
+
101
+ impl Deserialize for EcdsaSig {
102
+ fn deserialize ( bytes : & [ u8 ] ) -> Result < Self , encode:: Error > {
103
+ let ( sighash_byte, signature) = bytes. split_last ( )
104
+ . ok_or ( encode:: Error :: ParseFailed ( "empty partial signature data" ) ) ?;
105
+ Ok ( EcdsaSig {
106
+ sig : secp256k1:: ecdsa:: Signature :: from_der ( signature)
107
+ . map_err ( |_| encode:: Error :: ParseFailed ( "non-DER encoded signature" ) ) ?,
108
+ // NB: Since BIP-174 says "the signature as would be pushed to the stack from
109
+ // a scriptSig or witness" we should use a consensus deserialization and do
110
+ // not error on a non-standard values.
111
+ hash_ty : EcdsaSigHashType :: from_u32_consensus ( * sighash_byte as u32 )
112
+ } )
113
+ }
114
+ }
115
+
92
116
impl Serialize for KeySource {
93
117
fn serialize ( & self ) -> Vec < u8 > {
94
118
let mut rv: Vec < u8 > = Vec :: with_capacity ( key_source_len ( & self ) ) ;
You can’t perform that action at this time.
0 commit comments