From 847ee944fc847eab23b5465c31b3a245efd0df16 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Sun, 27 Jun 2021 20:06:00 +0200 Subject: [PATCH 1/2] Using serde/alloc and serde/std with corresponding features --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e545b2ee9..1c80b0093 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,9 +19,9 @@ features = [ "rand", "rand-std", "serde", "recovery" ] [features] unstable = ["recovery", "rand-std"] default = ["std"] -std = ["secp256k1-sys/std"] +std = ["secp256k1-sys/std", "serde/std"] # allow use of Secp256k1::new and related API that requires an allocator -alloc = [] +alloc = ["serde/alloc"] rand-std = ["rand/std"] recovery = ["secp256k1-sys/recovery"] lowmemory = ["secp256k1-sys/lowmemory"] From 24b674901063824a90b92340a73123da44e66126 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Sun, 27 Jun 2021 20:23:59 +0200 Subject: [PATCH 2/2] Fixing formatting --- src/lib.rs | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index a32a2afe2..fe9340c6c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -177,31 +177,31 @@ pub struct SerializedSignature { } impl fmt::Debug for Signature { -fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - fmt::Display::fmt(self, f) -} + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Display::fmt(self, f) + } } impl fmt::Display for Signature { -fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let sig = self.serialize_der(); - for v in sig.iter() { - write!(f, "{:02x}", v)?; + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let sig = self.serialize_der(); + for v in sig.iter() { + write!(f, "{:02x}", v)?; + } + Ok(()) } - Ok(()) -} } impl str::FromStr for Signature { -type Err = Error; -fn from_str(s: &str) -> Result { - let mut res = [0; 72]; - match from_hex(s, &mut res) { - Ok(x) => Signature::from_der(&res[0..x]), - _ => Err(Error::InvalidSignature), + type Err = Error; + fn from_str(s: &str) -> Result { + let mut res = [0; 72]; + match from_hex(s, &mut res) { + Ok(x) => Signature::from_der(&res[0..x]), + _ => Err(Error::InvalidSignature), + } } } -} /// Trait describing something that promises to be a 32-byte random number; in particular, /// it has negligible probability of being zero or overflowing the group order. Such objects @@ -270,7 +270,7 @@ impl SerializedSignature { } impl Signature { -#[inline] + #[inline] /// Converts a DER-encoded byte slice to a signature pub fn from_der(data: &[u8]) -> Result { if data.is_empty() {return Err(Error::InvalidSignature);}