From 9e74777fe56560978c7366016cf3863365ac232b Mon Sep 17 00:00:00 2001 From: DieMyst Date: Mon, 18 Jan 2021 18:26:17 +0300 Subject: [PATCH] fmt --- src/lib.rs | 2 +- src/trust_graph.rs | 30 ++++++++++++++++-------------- src/trust_graph_storage.rs | 29 +++++++++++++++++++++-------- 3 files changed, 38 insertions(+), 23 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 06eab78..e338c14 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,8 +34,8 @@ mod public_key_hashable; mod revoke; mod trust; mod trust_graph; -mod trust_node; mod trust_graph_storage; +mod trust_node; pub(crate) use libp2p_core::identity::ed25519; diff --git a/src/trust_graph.rs b/src/trust_graph.rs index a468ac6..44ef933 100644 --- a/src/trust_graph.rs +++ b/src/trust_graph.rs @@ -19,8 +19,8 @@ use crate::ed25519::PublicKey; use crate::public_key_hashable::PublicKeyHashable; use crate::revoke::Revoke; use crate::trust::Trust; -use crate::trust_node::{Auth, TrustNode}; use crate::trust_graph_storage::Storage; +use crate::trust_node::{Auth, TrustNode}; use std::borrow::Borrow; use std::collections::{HashSet, VecDeque}; use std::time::Duration; @@ -33,15 +33,13 @@ pub type Weight = u32; /// TODO export a certificate from graph #[allow(dead_code)] pub struct TrustGraph { - storage: Box + storage: Box, } #[allow(dead_code)] impl TrustGraph { pub fn new(storage: Box) -> Self { - Self { - storage: storage - } + Self { storage: storage } } /// Insert new root weight @@ -60,7 +58,13 @@ impl TrustGraph { where C: Borrow, { - let roots: Vec = self.storage.root_keys().iter().cloned().map(Into::into).collect(); + let roots: Vec = self + .storage + .root_keys() + .iter() + .cloned() + .map(Into::into) + .collect(); // Check that certificate is valid and converges to one of the known roots Certificate::verify(cert.borrow(), roots.as_slice(), cur_time)?; @@ -89,7 +93,8 @@ impl TrustGraph { issued_by: previous_trust.issued_for.clone(), }; - self.storage.update_auth(&pk, auth, &root_trust.issued_for, cur_time); + self.storage + .update_auth(&pk, auth, &root_trust.issued_for, cur_time); previous_trust = trust; } @@ -275,9 +280,9 @@ mod tests { use super::*; use crate::key_pair::KeyPair; use crate::misc::current_time; + use crate::trust_graph_storage::InMemoryStorage; use failure::_core::time::Duration; use std::collections::HashMap; - use crate::trust_graph_storage::InMemoryStorage; pub fn one_minute() -> Duration { Duration::new(60, 0) @@ -526,12 +531,9 @@ mod tests { let st = Box::new(InMemoryStorage::new()); let mut graph = TrustGraph::new(st); // add first and last trusts as roots - graph - .add_root_weight(cert.chain[0].clone().issued_for.into(), 1); - graph - .add_root_weight(cert.chain[3].clone().issued_for.into(), 1); - graph - .add_root_weight(cert.chain[5].clone().issued_for.into(), 1); + graph.add_root_weight(cert.chain[0].clone().issued_for.into(), 1); + graph.add_root_weight(cert.chain[3].clone().issued_for.into(), 1); + graph.add_root_weight(cert.chain[5].clone().issued_for.into(), 1); graph.add(cert.clone(), current_time()).unwrap(); diff --git a/src/trust_graph_storage.rs b/src/trust_graph_storage.rs index e51d789..aa2eae6 100644 --- a/src/trust_graph_storage.rs +++ b/src/trust_graph_storage.rs @@ -1,10 +1,10 @@ -use crate::trust_node::{Auth, TrustNode}; use crate::public_key_hashable::PublicKeyHashable; -use crate::trust_graph::Weight; -use std::collections::{HashMap}; use crate::revoke::Revoke; -use std::time::Duration; +use crate::trust_graph::Weight; +use crate::trust_node::{Auth, TrustNode}; use libp2p_core::identity::ed25519::PublicKey; +use std::collections::HashMap; +use std::time::Duration; pub trait Storage { fn get(&self, pk: &PublicKeyHashable) -> Option<&TrustNode>; @@ -14,7 +14,13 @@ pub trait Storage { fn add_root_weight(&mut self, pk: PublicKeyHashable, weight: Weight); fn root_keys(&self) -> Vec; fn revoke(&mut self, pk: &PublicKeyHashable, revoke: Revoke) -> Result<(), String>; - fn update_auth(&mut self, pk: &PublicKeyHashable, auth: Auth, issued_for: &PublicKey, cur_time: Duration); + fn update_auth( + &mut self, + pk: &PublicKeyHashable, + auth: Auth, + issued_for: &PublicKey, + cur_time: Duration, + ); } #[derive(Debug, Default)] @@ -26,7 +32,8 @@ pub struct InMemoryStorage { impl InMemoryStorage { #[allow(dead_code)] pub fn new_in_memory(root_weights: Vec<(PublicKey, Weight)>) -> Self { - let root_weights = root_weights.into_iter() + let root_weights = root_weights + .into_iter() .map(|(k, w)| (k.into(), w)) .collect(); Self { @@ -39,7 +46,7 @@ impl InMemoryStorage { pub fn new() -> Self { InMemoryStorage { nodes: HashMap::new(), - root_weights: HashMap::new() + root_weights: HashMap::new(), } } } @@ -75,7 +82,13 @@ impl Storage for InMemoryStorage { } } - fn update_auth(&mut self, pk: &PublicKeyHashable, auth: Auth, issued_for: &PublicKey, cur_time: Duration) { + fn update_auth( + &mut self, + pk: &PublicKeyHashable, + auth: Auth, + issued_for: &PublicKey, + cur_time: Duration, + ) { match self.nodes.get_mut(&pk) { Some(trust_node) => { trust_node.update_auth(auth);