Browse Source

Create struct for bridge info which must be externally provided

Vecna 1 year ago
parent
commit
4f88df6171
4 changed files with 40 additions and 16 deletions
  1. 25 0
      src/bridge_info.rs
  2. 1 0
      src/lib.rs
  3. 8 11
      src/negative_report.rs
  4. 6 5
      src/positive_report.rs

+ 25 - 0
src/bridge_info.rs

@@ -0,0 +1,25 @@
+use curve25519_dalek::Scalar;
+use ed25519_dalek::VerifyingKey;
+use lox_library::bridge_table::BridgeLine;
+
+/// Information that needs to be known to verify a Troll Patrol report
+pub struct BridgeInfo {
+    /// BridgeLine for this bridge
+    pub bridge_line: BridgeLine,
+
+    /// Bucket for this bridge if this bridge is a Lox bridge
+    pub bucket: Option<Scalar>,
+
+    /// Key used to verify bridge tokens
+    pub pubkey: Option<VerifyingKey>,
+}
+
+impl BridgeInfo {
+    pub fn new(bl: BridgeLine) -> Self {
+        BridgeInfo {
+            bridge_line: bl,
+            bucket: None,
+            pubkey: None,
+        }
+    }
+}

+ 1 - 0
src/lib.rs

@@ -8,6 +8,7 @@ use std::{
     io::BufReader,
 };
 
+pub mod bridge_info;
 pub mod extra_info;
 pub mod negative_report;
 pub mod positive_report;

+ 8 - 11
src/negative_report.rs

@@ -1,4 +1,4 @@
-use crate::{get_date, COUNTRY_CODES};
+use crate::{bridge_info::BridgeInfo, get_date, COUNTRY_CODES};
 
 use curve25519_dalek::scalar::Scalar;
 use lox_library::{bridge_table::BridgeLine, cred::Lox};
@@ -87,18 +87,15 @@ impl NegativeReport {
 
     /// 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 {
+    pub fn verify(self, bridge_info: &BridgeInfo) -> bool {
         match self.bridge_pok {
-            ProofOfBridgeKnowledge::HashOfBridgeLine(pok) => match bl {
+            ProofOfBridgeKnowledge::HashOfBridgeLine(pok) => {
+                let hash = HashOfBridgeLine::new(&bridge_info.bridge_line);
+                hash == pok
+            }
+            ProofOfBridgeKnowledge::HashOfBucket(pok) => match bridge_info.bucket {
                 Some(b) => {
-                    let hash = HashOfBridgeLine::new(b);
-                    hash == pok
-                }
-                None => false,
-            },
-            ProofOfBridgeKnowledge::HashOfBucket(pok) => match bucket {
-                Some(b) => {
-                    let hash = HashOfBucket::new(b);
+                    let hash = HashOfBucket::new(&b);
                     hash == pok
                 }
                 None => false,

+ 6 - 5
src/positive_report.rs

@@ -1,10 +1,10 @@
 // For Lox-related code where points are uppercase and scalars are lowercase
 #![allow(non_snake_case)]
 
-use crate::{get_date, CONFIG, COUNTRY_CODES};
+use crate::{bridge_info::BridgeInfo, get_date, CONFIG, COUNTRY_CODES};
 
-use curve25519_dalek::{ristretto::RistrettoBasepointTable, Scalar};
-use ed25519_dalek::{Signature, Signer, SigningKey, Verifier, VerifyingKey};
+use curve25519_dalek::ristretto::RistrettoBasepointTable;
+use ed25519_dalek::{Signature, Signer, SigningKey, Verifier};
 use lox_library::{cred::Lox, proto::positive_report as lox_pr, IssuerPubKey};
 use serde::{Deserialize, Serialize};
 use sha1::{Digest, Sha1};
@@ -111,13 +111,13 @@ impl PositiveReport {
     /// the fingerprint listed in the report.
     pub fn verify_excluding_lox_proof(
         self,
-        bucket: Scalar,
+        bridge_info: &BridgeInfo,
         Htable: &RistrettoBasepointTable,
-        bridge_key: Option<VerifyingKey>,
     ) -> bool {
         // Verify bridge token
         if CONFIG.require_bridge_token {
             let bridge_token = self.bridge_token.unwrap();
+            let bridge_key = bridge_info.pubkey;
             if bridge_key.is_none() {
                 return false;
             }
@@ -133,6 +133,7 @@ impl PositiveReport {
             }
         }
         // Verify knowledge of bucket ID
+        let bucket = bridge_info.bucket.unwrap();
         let BP = self.lox_proof.BP;
         if &bucket * Htable != BP {
             return false;