Fix formatting
This commit is contained in:
parent
7a24fdfa06
commit
d98ae40879
|
@ -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<u8>", into="Vec<u8>")]
|
||||
#[serde(try_from = "Vec<u8>", into = "Vec<u8>")]
|
||||
pub struct EncryptedBucket([u8; ENC_BUCKET_BYTES]);
|
||||
|
||||
impl From<EncryptedBucket> for Vec<u8> {
|
||||
|
@ -221,7 +221,9 @@ pub struct WrongSliceLengthError;
|
|||
impl TryFrom<Vec<u8>> for EncryptedBucket {
|
||||
type Error = WrongSliceLengthError;
|
||||
fn try_from(v: Vec<u8>) -> Result<EncryptedBucket, Self::Error> {
|
||||
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<u8> = cipher.decrypt(nonce,k.encbucket.0[12..].as_ref())?;
|
||||
let plaintext: Vec<u8> = 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<Bucket, aead::Error> {
|
||||
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"),
|
||||
};
|
||||
|
|
|
@ -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<u32, EncryptedBucket>{
|
||||
pub fn enc_bridge_table(&mut self) -> &HashMap<u32, EncryptedBucket> {
|
||||
let today = self.today();
|
||||
if self.bridge_table.date_last_enc != today {
|
||||
self.bridge_table
|
||||
|
|
|
@ -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!(
|
||||
|
|
Loading…
Reference in New Issue