diff --git a/Cargo.lock b/Cargo.lock index d7fea29..8405525 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1252,6 +1252,7 @@ dependencies = [ "rand 0.8.5", "serde", "serde_with", + "sha1", "sha2", "statistical", "subtle", diff --git a/crates/lox-library/Cargo.toml b/crates/lox-library/Cargo.toml index 9d75bb1..0075670 100644 --- a/crates/lox-library/Cargo.toml +++ b/crates/lox-library/Cargo.toml @@ -21,6 +21,7 @@ chrono = "0.4.38" rand = { version = "0.8", features = ["std_rng"]} serde = "1.0.197" serde_with = {version = "3.7.0", features = ["json"]} +sha1 = "0.10" sha2 = "0.10" statistical = "1.0.0" lazy_static = "1" diff --git a/crates/lox-library/src/bridge_table.rs b/crates/lox-library/src/bridge_table.rs index da660d0..fa3ff33 100644 --- a/crates/lox-library/src/bridge_table.rs +++ b/crates/lox-library/src/bridge_table.rs @@ -20,6 +20,7 @@ use curve25519_dalek::scalar::Scalar; use rand::RngCore; use serde::{Deserialize, Serialize}; use serde_with::serde_as; +use sha1::{Digest, Sha1}; use std::collections::{HashMap, HashSet}; use std::convert::{TryFrom, TryInto}; use subtle::ConstantTimeEq; @@ -50,13 +51,23 @@ pub struct BridgeLine { /// fingerprint pub uid_fingerprint: u64, /// unhashed fingerprint (20-byte bridge ID) - pub fingerprint: [u8; 20], + pub fingerprint: [u8; 20], // may be changed to a string later /// other protocol information, including pluggable transport, /// public key, etc. #[serde_as(as = "[_; BRIDGE_INFO_BYTES]")] pub info: [u8; BRIDGE_INFO_BYTES], } +impl BridgeLine { + pub fn get_hashed_fingerprint(&self) -> [u8; 20] { + let mut hasher = Sha1::new(); + hasher.update(&self.fingerprint); + // If the fingerprint gets changed to a string: + //hasher.update(array_bytes::hex2array(&self.fingerprint).unwrap()); + hasher.finalize().into() + } +} + /// A bucket contains MAX_BRIDGES_PER_BUCKET bridges plus the /// information needed to construct a Bucket Reachability credential, /// which is a 4-byte date, and a (P,Q) MAC