diff --git a/crates/lox-library/src/bridge_table.rs b/crates/lox-library/src/bridge_table.rs index 708945d..1b81435 100644 --- a/crates/lox-library/src/bridge_table.rs +++ b/crates/lox-library/src/bridge_table.rs @@ -20,7 +20,7 @@ use rand::RngCore; use serde::{Deserialize, Serialize}; use serde_with::serde_as; use std::collections::{HashMap, HashSet}; -use std::convert::{TryInto, TryFrom}; +use std::convert::{TryFrom, TryInto}; use subtle::ConstantTimeEq; /// Each bridge information line is serialized into this many bytes @@ -205,7 +205,7 @@ impl BridgeLine { } #[derive(Debug, Clone, Copy, Serialize, Deserialize)] -#[serde(try_from="Vec", into="Vec")] +#[serde(try_from = "Vec", into = "Vec")] pub struct EncryptedBucket([u8; ENC_BUCKET_BYTES]); impl From for Vec { @@ -221,7 +221,9 @@ pub struct WrongSliceLengthError; impl TryFrom> for EncryptedBucket { type Error = WrongSliceLengthError; fn try_from(v: Vec) -> Result { - Ok(EncryptedBucket(*Box::<[u8; ENC_BUCKET_BYTES]>::try_from(v).map_err(|_| WrongSliceLengthError)?)) + Ok(EncryptedBucket( + *Box::<[u8; ENC_BUCKET_BYTES]>::try_from(v).map_err(|_| WrongSliceLengthError)?, + )) } } @@ -230,7 +232,6 @@ struct K { encbucket: EncryptedBucket, } - /// A BridgeTable is the internal structure holding the buckets /// containing the bridges, the keys used to encrypt the buckets, and /// the encrypted buckets. The encrypted buckets will be exposed to the @@ -346,7 +347,7 @@ impl BridgeTable { let aeskey = GenericArray::from_slice(key); // Decrypt let cipher = Aes128Gcm::new(aeskey); - let plaintext: Vec = cipher.decrypt(nonce,k.encbucket.0[12..].as_ref())?; + let plaintext: Vec = cipher.decrypt(nonce, k.encbucket.0[12..].as_ref())?; // Convert the plaintext bytes to an array of BridgeLines Ok(BridgeLine::bucket_decode( plaintext.as_slice().try_into().unwrap(), @@ -356,7 +357,7 @@ impl BridgeTable { /// Decrypt an individual encrypted bucket, given its id and key pub fn decrypt_bucket_id(&self, id: u32, key: &[u8; 16]) -> Result { - let encbucket:&EncryptedBucket = match self.encbuckets.get(&id) { + let encbucket: &EncryptedBucket = match self.encbuckets.get(&id) { Some(encbucket) => encbucket, None => panic!("Provided ID not found"), }; diff --git a/crates/lox-library/src/lib.rs b/crates/lox-library/src/lib.rs index 34c546c..b69e63e 100644 --- a/crates/lox-library/src/lib.rs +++ b/crates/lox-library/src/lib.rs @@ -24,16 +24,16 @@ pub mod migration_table; use sha2::Sha512; -use rand::rngs::OsRng; -use rand::Rng; -use std::convert::{TryFrom, TryInto}; -use std::collections::HashMap; use curve25519_dalek::constants as dalek_constants; use curve25519_dalek::ristretto::RistrettoBasepointTable; use curve25519_dalek::ristretto::RistrettoPoint; use curve25519_dalek::scalar::Scalar; #[cfg(test)] use curve25519_dalek::traits::IsIdentity; +use rand::rngs::OsRng; +use rand::Rng; +use std::collections::HashMap; +use std::convert::{TryFrom, TryInto}; use ed25519_dalek::{Keypair, PublicKey, Signature, SignatureError, Signer, Verifier}; use subtle::ConstantTimeEq; @@ -620,7 +620,7 @@ impl BridgeAuth { /// Be sure to call this function when you want the latest version /// of the table, since it will put fresh Bucket Reachability /// credentials in the buckets each day. - pub fn enc_bridge_table(&mut self) -> &HashMap{ + pub fn enc_bridge_table(&mut self) -> &HashMap { let today = self.today(); if self.bridge_table.date_last_enc != today { self.bridge_table diff --git a/crates/lox-library/src/tests.rs b/crates/lox-library/src/tests.rs index 8297ded..1fcbeff 100644 --- a/crates/lox-library/src/tests.rs +++ b/crates/lox-library/src/tests.rs @@ -171,7 +171,8 @@ impl TestHarness { let (id, key) = bridge_table::from_scalar(cred.bucket).unwrap(); let encbuckets = self.ba.enc_bridge_table(); let bucket = - bridge_table::BridgeTable::decrypt_bucket(id, &key, encbuckets.get(&id).unwrap()).unwrap(); + bridge_table::BridgeTable::decrypt_bucket(id, &key, encbuckets.get(&id).unwrap()) + .unwrap(); let reachcred = bucket.1.unwrap(); // Use the Bucket Reachability credential to advance to the next @@ -219,7 +220,8 @@ impl TestHarness { let (id, key) = bridge_table::from_scalar(cred.bucket).unwrap(); let encbuckets = self.ba.enc_bridge_table(); let bucket = - bridge_table::BridgeTable::decrypt_bucket(id, &key, encbuckets.get(&id).unwrap()).unwrap(); + bridge_table::BridgeTable::decrypt_bucket(id, &key, encbuckets.get(&id).unwrap()) + .unwrap(); let reachcred = bucket.1.unwrap(); let req_start = Instant::now(); @@ -741,7 +743,7 @@ fn test_bridge_replace() { let mut num = 100000; while !th.ba.bridge_table.buckets.contains_key(&num) { num = rand::thread_rng().gen_range(0, th.ba.bridge_table.counter) as u32; - }; + } let replaceable_bucket = th.ba.bridge_table.buckets.get(&num).unwrap().clone(); let replacement_bridge = &replaceable_bucket[0]; assert!( @@ -869,7 +871,7 @@ fn test_bridge_replace() { ); // Remove a spare bucket to replace bridge, buckets decrease by 1 assert!( - (table_size -1) == th.ba.bridge_table.buckets.len(), + (table_size - 1) == th.ba.bridge_table.buckets.len(), "Number of buckets changed size" ); assert!(