Procházet zdrojové kódy

Moved protocol modules into submodules of "proto" module instead of all being at the top level

Ian Goldberg před 3 roky
rodič
revize
c26fe16563
5 změnil soubory, kde provedl 38 přidání a 26 odebrání
  1. 15 4
      src/lib.rs
  2. 4 4
      src/proto/migration.rs
  3. 12 12
      src/proto/open_invite.rs
  4. 6 6
      src/proto/trust_promotion.rs
  5. 1 0
      src/tests.rs

+ 15 - 4
src/lib.rs

@@ -318,10 +318,21 @@ pub fn pt_dbl(P: &RistrettoPoint) -> RistrettoPoint {
     P + P
 }
 
-// The protocol modules
-pub mod migration;
-pub mod open_invite;
-pub mod trust_promotion;
+/// The protocol modules.
+///
+/// Each protocol lives in a submodule.  Each submodule defines structs
+/// for Request (the message from the client to the bridge authority),
+/// State (the state held by the client while waiting for the reply),
+/// and Response (the message from the bridge authority to the client).
+/// Each submodule defines functions request, which produces a (Request,
+/// State) pair, and handle_response, which consumes a State and a
+/// Response.  It also adds a handle_* function to the BridgeAuth struct
+/// that consumes a Request and produces a Result<Response, ProofError>.
+pub mod proto {
+    pub mod migration;
+    pub mod open_invite;
+    pub mod trust_promotion;
+}
 
 // Unit tests
 #[cfg(test)]

+ 4 - 4
src/migration.rs → src/proto/migration.rs

@@ -40,10 +40,10 @@ use zkp::CompactProof;
 use zkp::ProofError;
 use zkp::Transcript;
 
-use super::cred;
-use super::dup_filter::SeenType;
-use super::{BridgeAuth, IssuerPubKey};
-use super::{CMZ_A, CMZ_A_TABLE, CMZ_B, CMZ_B_TABLE};
+use super::super::cred;
+use super::super::dup_filter::SeenType;
+use super::super::{BridgeAuth, IssuerPubKey};
+use super::super::{CMZ_A, CMZ_A_TABLE, CMZ_B, CMZ_B_TABLE};
 
 pub struct Request {
     // Fields for blind showing the Lox credential

+ 12 - 12
src/open_invite.rs → src/proto/open_invite.rs

@@ -22,15 +22,16 @@ use zkp::CompactProof;
 use zkp::ProofError;
 use zkp::Transcript;
 
-use super::bridge_table;
-use super::cred;
-use super::dup_filter::SeenType;
-use super::{BridgeAuth, IssuerPubKey};
-use super::{CMZ_A, CMZ_A_TABLE, CMZ_B, CMZ_B_TABLE};
+use super::super::bridge_table;
+use super::super::cred;
+use super::super::dup_filter::SeenType;
+use super::super::OPENINV_LENGTH;
+use super::super::{BridgeAuth, BridgeDb, IssuerPubKey};
+use super::super::{CMZ_A, CMZ_A_TABLE, CMZ_B, CMZ_B_TABLE};
 
 /// The request message for this protocol
 pub struct Request {
-    invite: [u8; super::OPENINV_LENGTH],
+    invite: [u8; OPENINV_LENGTH],
     D: RistrettoPoint,
     EncIdClient: (RistrettoPoint, RistrettoPoint),
     piUserBlinding: CompactProof,
@@ -104,7 +105,7 @@ define_proof! {
 
 /// Submit an open invitation issued by the BridgeDb to receive your
 /// first Lox credential
-pub fn request(invite: &[u8; super::OPENINV_LENGTH]) -> (Request, State) {
+pub fn request(invite: &[u8; OPENINV_LENGTH]) -> (Request, State) {
     let B: &RistrettoPoint = &CMZ_B;
     let Btable: &RistrettoBasepointTable = &CMZ_B_TABLE;
 
@@ -159,11 +160,10 @@ impl BridgeAuth {
         // Check the signature on the open_invite.  We manually match
         // here because we're changing the Err type from SignatureError
         // to ProofError
-        let (invite_id, bucket_id_u32) =
-            match super::BridgeDb::verify(req.invite, self.bridgedb_pub) {
-                Ok(res) => res,
-                Err(_) => return Err(ProofError::VerificationFailure),
-            };
+        let (invite_id, bucket_id_u32) = match BridgeDb::verify(req.invite, self.bridgedb_pub) {
+            Ok(res) => res,
+            Err(_) => return Err(ProofError::VerificationFailure),
+        };
         let bucket_id: usize = bucket_id_u32 as usize;
 
         // Only proceed if the invite_id is fresh

+ 6 - 6
src/trust_promotion.rs → src/proto/trust_promotion.rs

@@ -38,12 +38,12 @@ use zkp::Transcript;
 
 use std::collections::HashMap;
 
-use super::cred;
-use super::dup_filter::SeenType;
-use super::migration_table;
-use super::{pt_dbl, scalar_dbl, scalar_u64};
-use super::{BridgeAuth, IssuerPubKey};
-use super::{CMZ_A, CMZ_A_TABLE, CMZ_B, CMZ_B_TABLE};
+use super::super::cred;
+use super::super::dup_filter::SeenType;
+use super::super::migration_table;
+use super::super::{pt_dbl, scalar_dbl, scalar_u64};
+use super::super::{BridgeAuth, IssuerPubKey};
+use super::super::{CMZ_A, CMZ_A_TABLE, CMZ_B, CMZ_B_TABLE};
 
 /// The minimum number of days a user has to be at trust level 0
 /// (untrusted) with their (single) bridge unblocked before they can

+ 1 - 0
src/tests.rs

@@ -2,6 +2,7 @@
 BridgeLine::random() or private fields */
 
 use super::bridge_table::BridgeLine;
+use super::proto::*;
 use super::*;
 
 #[test]