Browse Source

Use one function for verifying negative reports

Vecna 1 year ago
parent
commit
495f196107
1 changed files with 17 additions and 18 deletions
  1. 17 18
      src/negative_report.rs

+ 17 - 18
src/negative_report.rs

@@ -85,25 +85,24 @@ impl NegativeReport {
         }
     }
 
-    /// Verify report if proof of bridge knowledge is bridge line hash
-    pub fn verify_with_hash_of_bridge_line(self, bl: &BridgeLine) -> bool {
+    /// Verify report. Caller must pass Some of the bridge knowledge proof type
+    /// in the report.
+    pub fn verify(self, bl: Option<&BridgeLine>, bucket: Option<&Scalar>) -> bool {
         match self.bridge_pok {
-            ProofOfBridgeKnowledge::HashOfBridgeLine(pok) => {
-                let hash = HashOfBridgeLine::new(bl);
-                hash == pok
-            }
-            _ => false,
-        }
-    }
-
-    /// Verify report if proof of bridge knowledge is bucket hash
-    pub fn verify_with_hash_of_bucket(self, bucket: &Scalar) -> bool {
-        match self.bridge_pok {
-            ProofOfBridgeKnowledge::HashOfBucket(pok) => {
-                let hash = HashOfBucket::new(bucket);
-                hash == pok
-            }
-            _ => false,
+            ProofOfBridgeKnowledge::HashOfBridgeLine(pok) => match bl {
+                Some(b) => {
+                    let hash = HashOfBridgeLine::new(b);
+                    hash == pok
+                }
+                None => false,
+            },
+            ProofOfBridgeKnowledge::HashOfBucket(pok) => match bucket {
+                Some(b) => {
+                    let hash = HashOfBucket::new(b);
+                    hash == pok
+                }
+                None => false,
+            },
         }
     }
 }