Add function to BridgeLine to get hashed fingerprint

This commit is contained in:
Vecna 2024-04-30 01:22:32 -04:00
parent 4a515ecb15
commit 69f8fdc1e4
3 changed files with 14 additions and 1 deletions

1
Cargo.lock generated
View File

@ -1252,6 +1252,7 @@ dependencies = [
"rand 0.8.5",
"serde",
"serde_with",
"sha1",
"sha2",
"statistical",
"subtle",

View File

@ -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"

View File

@ -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