From 9699c622fcbbf20a90d8a92e748a84f0c5e84c9a Mon Sep 17 00:00:00 2001 From: Steven Roose Date: Fri, 23 Oct 2020 17:21:11 +0100 Subject: [PATCH 1/2] Return Result<(), io::Error> from PublicKey::write_into --- src/util/address.rs | 6 +++--- src/util/bip32.rs | 2 +- src/util/key.rs | 8 ++++---- src/util/psbt/serialize.rs | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/util/address.rs b/src/util/address.rs index 917fa4d5..24174499 100644 --- a/src/util/address.rs +++ b/src/util/address.rs @@ -222,7 +222,7 @@ impl Address { #[inline] pub fn p2pkh(pk: &key::PublicKey, network: Network) -> Address { let mut hash_engine = PubkeyHash::engine(); - pk.write_into(&mut hash_engine); + pk.write_into(&mut hash_engine).expect("engines don't error"); Address { network: network, @@ -250,7 +250,7 @@ impl Address { } let mut hash_engine = WPubkeyHash::engine(); - pk.write_into(&mut hash_engine); + pk.write_into(&mut hash_engine).expect("engines don't error"); Ok(Address { network: network, @@ -271,7 +271,7 @@ impl Address { } let mut hash_engine = WPubkeyHash::engine(); - pk.write_into(&mut hash_engine); + pk.write_into(&mut hash_engine).expect("engines don't error"); let builder = script::Builder::new() .push_int(0) diff --git a/src/util/bip32.rs b/src/util/bip32.rs index 0b13c3d9..aec7c4a9 100644 --- a/src/util/bip32.rs +++ b/src/util/bip32.rs @@ -575,7 +575,7 @@ impl ExtendedPubKey { /// Returns the HASH160 of the public key of the xpub pub fn identifier(&self) -> XpubIdentifier { let mut engine = XpubIdentifier::engine(); - self.public_key.write_into(&mut engine); + self.public_key.write_into(&mut engine).expect("engines don't error"); XpubIdentifier::from_engine(engine) } diff --git a/src/util/key.rs b/src/util/key.rs index 2c4e6a35..d0cf0a21 100644 --- a/src/util/key.rs +++ b/src/util/key.rs @@ -101,18 +101,18 @@ impl PublicKey { } /// Write the public key into a writer - pub fn write_into(&self, mut writer: W) { - let _: io::Result<()> = if self.compressed { + pub fn write_into(&self, mut writer: W) -> Result<(), io::Error> { + if self.compressed { writer.write_all(&self.key.serialize()) } else { writer.write_all(&self.key.serialize_uncompressed()) - }; + } } /// Serialize the public key to bytes pub fn to_bytes(&self) -> Vec { let mut buf = Vec::new(); - self.write_into(&mut buf); + self.write_into(&mut buf).expect("vecs don't error"); buf } diff --git a/src/util/psbt/serialize.rs b/src/util/psbt/serialize.rs index 19167a21..d59e409d 100644 --- a/src/util/psbt/serialize.rs +++ b/src/util/psbt/serialize.rs @@ -58,7 +58,7 @@ impl Deserialize for Script { impl Serialize for PublicKey { fn serialize(&self) -> Vec { let mut buf = Vec::new(); - self.write_into(&mut buf); + self.write_into(&mut buf).expect("vecs don't error"); buf } } From aed4e02e38797bbc514f3249ce7dfd38ae392b16 Mon Sep 17 00:00:00 2001 From: Steven Roose Date: Fri, 23 Oct 2020 17:21:54 +0100 Subject: [PATCH 2/2] Add #![deny(unused_must_use)] to avoid not checking Errs --- src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.rs b/src/lib.rs index 8215418c..790b6182 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -35,6 +35,7 @@ #![deny(dead_code)] #![deny(unused_imports)] #![deny(missing_docs)] +#![deny(unused_must_use)] // Re-exported dependencies. #[macro_use] pub extern crate bitcoin_hashes as hashes;