Add distributor enum so we know where to send NRs
For now, I'm not adding this to PRs because PRs are very Lox-specific
This commit is contained in:
parent
548c94f834
commit
4f5bec56ad
|
@ -59,6 +59,11 @@ pub fn get_date() -> u32 {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize)]
|
||||||
|
pub enum BridgeDistributor {
|
||||||
|
Lox,
|
||||||
|
}
|
||||||
|
|
||||||
/// All the info for a bridge, to be stored in the database
|
/// All the info for a bridge, to be stored in the database
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct BridgeInfo {
|
pub struct BridgeInfo {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{bridge_info::BridgeInfo, get_date, COUNTRY_CODES};
|
use crate::{bridge_info::BridgeInfo, get_date, BridgeDistributor, COUNTRY_CODES};
|
||||||
|
|
||||||
use curve25519_dalek::scalar::Scalar;
|
use curve25519_dalek::scalar::Scalar;
|
||||||
use lox_library::{bridge_table::BridgeLine, cred::Lox};
|
use lox_library::{bridge_table::BridgeLine, cred::Lox};
|
||||||
|
@ -16,6 +16,7 @@ pub enum NegativeReportError {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A report that the user was unable to connect to the bridge
|
/// A report that the user was unable to connect to the bridge
|
||||||
|
#[derive(Eq, PartialEq, Ord, PartialOrd)]
|
||||||
pub struct NegativeReport {
|
pub struct NegativeReport {
|
||||||
/// hashed fingerprint (SHA-1 hash of 20-byte bridge ID)
|
/// hashed fingerprint (SHA-1 hash of 20-byte bridge ID)
|
||||||
pub fingerprint: [u8; 20],
|
pub fingerprint: [u8; 20],
|
||||||
|
@ -28,10 +29,18 @@ pub struct NegativeReport {
|
||||||
|
|
||||||
/// today's Julian date
|
/// today's Julian date
|
||||||
pub date: u32,
|
pub date: u32,
|
||||||
|
|
||||||
|
/// the bridge distributor, e.g., Lox, Https, or Moat
|
||||||
|
pub distributor: BridgeDistributor,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NegativeReport {
|
impl NegativeReport {
|
||||||
pub fn new(bridge_id: [u8; 20], bridge_pok: ProofOfBridgeKnowledge, country: String) -> Self {
|
pub fn new(
|
||||||
|
bridge_id: [u8; 20],
|
||||||
|
bridge_pok: ProofOfBridgeKnowledge,
|
||||||
|
country: String,
|
||||||
|
distributor: BridgeDistributor,
|
||||||
|
) -> Self {
|
||||||
let mut hasher = Sha1::new();
|
let mut hasher = Sha1::new();
|
||||||
hasher.update(bridge_id);
|
hasher.update(bridge_id);
|
||||||
let fingerprint: [u8; 20] = hasher.finalize().into();
|
let fingerprint: [u8; 20] = hasher.finalize().into();
|
||||||
|
@ -41,25 +50,30 @@ impl NegativeReport {
|
||||||
bridge_pok,
|
bridge_pok,
|
||||||
country,
|
country,
|
||||||
date,
|
date,
|
||||||
|
distributor,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_bridgeline(bridge_id: [u8; 20], bridgeline: BridgeLine, country: String) -> Self {
|
pub fn from_bridgeline(
|
||||||
|
bridgeline: BridgeLine,
|
||||||
|
country: String,
|
||||||
|
distributor: BridgeDistributor,
|
||||||
|
) -> Self {
|
||||||
let bridge_pok =
|
let bridge_pok =
|
||||||
ProofOfBridgeKnowledge::HashOfBridgeLine(HashOfBridgeLine::new(&bridgeline));
|
ProofOfBridgeKnowledge::HashOfBridgeLine(HashOfBridgeLine::new(&bridgeline));
|
||||||
NegativeReport::new(bridge_id, bridge_pok, country)
|
NegativeReport::new(bridgeline.fingerprint, bridge_pok, country, distributor)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_bucket(bridge_id: [u8; 20], bucket: Scalar, country: String) -> Self {
|
pub fn from_lox_bucket(bridge_id: [u8; 20], bucket: Scalar, country: String) -> Self {
|
||||||
let mut hasher = Sha3_256::new();
|
let mut hasher = Sha3_256::new();
|
||||||
hasher.update(bucket.to_bytes());
|
hasher.update(bucket.to_bytes());
|
||||||
let bucket_hash: [u8; 32] = hasher.finalize().into();
|
let bucket_hash: [u8; 32] = hasher.finalize().into();
|
||||||
let bridge_pok = ProofOfBridgeKnowledge::HashOfBucket(HashOfBucket { hash: bucket_hash });
|
let bridge_pok = ProofOfBridgeKnowledge::HashOfBucket(HashOfBucket { hash: bucket_hash });
|
||||||
NegativeReport::new(bridge_id, bridge_pok, country)
|
NegativeReport::new(bridge_id, bridge_pok, country, BridgeDistributor::Lox)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_lox_credential(bridge_id: [u8; 20], cred: Lox, country: String) -> Self {
|
pub fn from_lox_credential(bridge_id: [u8; 20], cred: Lox, country: String) -> Self {
|
||||||
NegativeReport::from_bucket(bridge_id, cred.bucket, country)
|
NegativeReport::from_lox_bucket(bridge_id, cred.bucket, country)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert report to a serializable version
|
/// Convert report to a serializable version
|
||||||
|
@ -69,6 +83,7 @@ impl NegativeReport {
|
||||||
bridge_pok: self.bridge_pok,
|
bridge_pok: self.bridge_pok,
|
||||||
country: self.country,
|
country: self.country,
|
||||||
date: self.date,
|
date: self.date,
|
||||||
|
distributor: self.distributor,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,6 +126,7 @@ pub struct SerializableNegativeReport {
|
||||||
bridge_pok: ProofOfBridgeKnowledge,
|
bridge_pok: ProofOfBridgeKnowledge,
|
||||||
pub country: String,
|
pub country: String,
|
||||||
pub date: u32,
|
pub date: u32,
|
||||||
|
pub distributor: BridgeDistributor,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SerializableNegativeReport {
|
impl SerializableNegativeReport {
|
||||||
|
@ -129,6 +145,7 @@ impl SerializableNegativeReport {
|
||||||
bridge_pok: self.bridge_pok,
|
bridge_pok: self.bridge_pok,
|
||||||
country: self.country.to_string(),
|
country: self.country.to_string(),
|
||||||
date: self.date.try_into().unwrap(),
|
date: self.date.try_into().unwrap(),
|
||||||
|
distributor: self.distributor,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue