From be457afdae3087d0f78ce69267be1ce5f0ffe5f0 Mon Sep 17 00:00:00 2001 From: Elichai Turkel Date: Tue, 21 May 2019 22:02:57 +0300 Subject: [PATCH] Removed ffi call from Display implementation --- src/lib.rs | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 58c0a4d..b5e458f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -179,19 +179,9 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { impl fmt::Display for Signature { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let mut v = [0; 72]; - let mut len = v.len() as usize; - unsafe { - 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])?; + let sig = self.serialize_der(); + for v in sig.iter() { + write!(f, "{:02x}", v)?; } Ok(()) }