From fbd24a72d2e1bedf7571101346ea26f4d21bcb75 Mon Sep 17 00:00:00 2001 From: danda Date: Thu, 9 Sep 2021 16:33:05 -0700 Subject: [PATCH] feat: accept Borrow for ::combine_signatures() to ease use of Vec --- src/lib.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2a85a9f..9fc5c8f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -726,12 +726,17 @@ impl PublicKeySet { /// // Validate the main signature. If the shares were valid, this can't fail. /// assert!(pk_set.public_key().verify(&sig, msg)); /// ``` - pub fn combine_signatures<'a, T, I>(&self, shares: I) -> Result + pub fn combine_signatures>( + &self, + shares: I, + ) -> Result where - I: IntoIterator, + I: IntoIterator, T: IntoFr, { - let samples = shares.into_iter().map(|(i, share)| (i, &(share.0).0)); + let samples = shares + .into_iter() + .map(|(i, share)| (i, (share.borrow().0).0)); Ok(Signature(interpolate(self.commit.degree(), samples)?)) } @@ -1026,7 +1031,8 @@ mod tests { let msg = "Totally real news"; // The threshold is 3, so 4 signature shares will suffice to recreate the share. - let sigs: BTreeMap<_, _> = [5, 8, 7, 10] + // note: this tests passing a Vec to ::combine_signatures (instead of BTreeMap) + let sigs: Vec<(_, _)> = [5, 8, 7, 10] .iter() .map(|&i| { let sig = sk_set.secret_key_share(i).sign(msg); @@ -1040,7 +1046,7 @@ mod tests { } // Combined, they produce a signature matching the main public key. - let sig = pk_set.combine_signatures(&sigs).expect("signatures match"); + let sig = pk_set.combine_signatures(sigs).expect("signatures match"); assert!(pk_set.public_key().verify(&sig, msg)); // A different set of signatories produces the same signature.