From a790679b729480b049dffca49a316edb6ef53a83 Mon Sep 17 00:00:00 2001 From: arnaucube Date: Sun, 10 Jul 2022 15:42:47 +0200 Subject: [PATCH] Add err handling on sign --- src/lib.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0edd2f7..30a67d2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -40,7 +40,7 @@ impl KeyPair { hash_to_point(self.pk).mul(self.sk.into_repr()) } - pub fn sign(&self, ring: Vec, m: Vec) -> Signature { + pub fn sign(&self, ring: Vec, m: Vec) -> Result { let ring_size = ring.len(); // determine pi (the position of signer's public key in R let mut pi = 0; @@ -54,8 +54,7 @@ impl KeyPair { } } if !found { - // error - println!("key not found in the ring"); + return Err("key not found in the ring".to_string()); } let mut rng = ark_std::rand::thread_rng(); @@ -97,7 +96,7 @@ impl KeyPair { // compute r_pi r[pi] = a - c[pi] * self.sk; - (c[0], r) + Ok((c[0], r)) } } @@ -112,7 +111,6 @@ pub fn verify( let c1 = sig.0; let r = sig.1; if ring_size != r.len() { - println!("ERROR"); // TODO return false; } // TODO check that key_image \in G (EC), by l * key_image == 0 @@ -190,7 +188,7 @@ mod tests { ring[pi] = k_pi.pk; let m: Vec = vec![1, 2, 3, 4]; - let sig = k_pi.sign(ring.clone(), m.clone()); + let sig = k_pi.sign(ring.clone(), m.clone()).unwrap(); println!("sig {:?}", sig); let key_image = k_pi.key_image();