From ffd5664c080613757b2069f7c182df3e7fb29f58 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Wed, 3 Apr 2024 12:33:30 +1100 Subject: [PATCH] Do not panic if input_index is out of bounds There is no need to panic if input index is out of bounds because we have a function to check the validity of the `input_index` argument and use it in other places already. --- bitcoin/src/psbt/mod.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/bitcoin/src/psbt/mod.rs b/bitcoin/src/psbt/mod.rs index 274fa225..b6028c32 100644 --- a/bitcoin/src/psbt/mod.rs +++ b/bitcoin/src/psbt/mod.rs @@ -402,8 +402,7 @@ impl Psbt { /// # Returns /// /// - Ok: A list of the public keys used in signing. - /// - Err: Error encountered trying to calculate the sighash AND we had the signing key. Also panics - /// if input_index is out of bounds. + /// - Err: Error encountered trying to calculate the sighash AND we had the signing key. fn bip32_sign_schnorr( &mut self, k: &K, @@ -416,7 +415,7 @@ impl Psbt { T: Borrow, K: GetKey, { - let mut input = self.inputs[input_index].clone(); + let mut input = self.checked_input(input_index)?.clone(); let mut used = vec![]; // List of pubkeys used to sign the input. @@ -487,7 +486,7 @@ impl Psbt { } } - self.inputs[input_index] = input; + self.inputs[input_index] = input; // input_index is checked above. Ok(used) }