From 8a19376edc61a4a68208f3663482d0954a02440f Mon Sep 17 00:00:00 2001 From: Ian Goldberg Date: Sat, 1 May 2021 15:21:50 -0400 Subject: [PATCH] Moved protocol modules into submodules of "proto" module instead of all being at the top level --- crates/lox-library/src/lib.rs | 19 +++++++++++---- .../lox-library/src/{ => proto}/migration.rs | 8 +++---- .../src/{ => proto}/open_invite.rs | 24 +++++++++---------- .../src/{ => proto}/trust_promotion.rs | 12 +++++----- crates/lox-library/src/tests.rs | 1 + 5 files changed, 38 insertions(+), 26 deletions(-) rename crates/lox-library/src/{ => proto}/migration.rs (99%) rename crates/lox-library/src/{ => proto}/open_invite.rs (95%) rename crates/lox-library/src/{ => proto}/trust_promotion.rs (98%) diff --git a/crates/lox-library/src/lib.rs b/crates/lox-library/src/lib.rs index ae2fcd7..2b481c9 100644 --- a/crates/lox-library/src/lib.rs +++ b/crates/lox-library/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. +pub mod proto { + pub mod migration; + pub mod open_invite; + pub mod trust_promotion; +} // Unit tests #[cfg(test)] diff --git a/crates/lox-library/src/migration.rs b/crates/lox-library/src/proto/migration.rs similarity index 99% rename from crates/lox-library/src/migration.rs rename to crates/lox-library/src/proto/migration.rs index 8e096fb..72964ee 100644 --- a/crates/lox-library/src/migration.rs +++ b/crates/lox-library/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 diff --git a/crates/lox-library/src/open_invite.rs b/crates/lox-library/src/proto/open_invite.rs similarity index 95% rename from crates/lox-library/src/open_invite.rs rename to crates/lox-library/src/proto/open_invite.rs index b5e47ed..b88f66e 100644 --- a/crates/lox-library/src/open_invite.rs +++ b/crates/lox-library/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 diff --git a/crates/lox-library/src/trust_promotion.rs b/crates/lox-library/src/proto/trust_promotion.rs similarity index 98% rename from crates/lox-library/src/trust_promotion.rs rename to crates/lox-library/src/proto/trust_promotion.rs index 93ee51f..b84a80b 100644 --- a/crates/lox-library/src/trust_promotion.rs +++ b/crates/lox-library/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 diff --git a/crates/lox-library/src/tests.rs b/crates/lox-library/src/tests.rs index 3d2db6e..aec5c37 100644 --- a/crates/lox-library/src/tests.rs +++ b/crates/lox-library/src/tests.rs @@ -2,6 +2,7 @@ BridgeLine::random() or private fields */ use super::bridge_table::BridgeLine; +use super::proto::*; use super::*; #[test]