Removed ffi call from Display implementation

This commit is contained in:
Elichai Turkel 2019-05-21 22:02:57 +03:00
parent 0bf88fe444
commit be457afdae
No known key found for this signature in database
GPG Key ID: 5607C93B5F86650C
1 changed files with 3 additions and 13 deletions

View File

@ -179,19 +179,9 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
impl fmt::Display for Signature { impl fmt::Display for Signature {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut v = [0; 72]; let sig = self.serialize_der();
let mut len = v.len() as usize; for v in sig.iter() {
unsafe { write!(f, "{:02x}", v)?;
let err = ffi::secp256k1_ecdsa_signature_serialize_der(
ffi::secp256k1_context_no_precomp,
v.as_mut_ptr(),
&mut len,
self.as_ptr()
);
debug_assert!(err == 1);
}
for i in 0..len {
write!(f, "{:02x}", v[i])?;
} }
Ok(()) Ok(())
} }