mirror of
https://github.com/fluencelabs/trust-graph
synced 2024-12-04 15:20:19 +00:00
clippy
This commit is contained in:
parent
b10726032e
commit
feac5dadf6
@ -144,8 +144,8 @@ impl<'de> serde::Deserialize<'de> for KeyPair {
|
||||
|
||||
impl Clone for KeyPair {
|
||||
fn clone(&self) -> KeyPair {
|
||||
let mut sk_bytes = self.key_pair.secret.to_bytes();
|
||||
let secret = ed25519_dalek::SecretKey::from_bytes(&mut sk_bytes)
|
||||
let sk_bytes = self.key_pair.secret.to_bytes();
|
||||
let secret = ed25519_dalek::SecretKey::from_bytes(&sk_bytes)
|
||||
.expect("ed25519::SecretKey::from_bytes(to_bytes(k)) != k");
|
||||
let public = ed25519_dalek::PublicKey::from_bytes(&self.key_pair.public.to_bytes())
|
||||
.expect("ed25519::PublicKey::from_bytes(to_bytes(k)) != k");
|
||||
|
@ -109,11 +109,7 @@ impl Certificate {
|
||||
}
|
||||
|
||||
// first, verify given certificate
|
||||
Certificate::verify(
|
||||
extend_cert,
|
||||
&[extend_cert.chain[0].issued_for.clone()],
|
||||
cur_time,
|
||||
)?;
|
||||
Certificate::verify(extend_cert, &[extend_cert.chain[0].issued_for], cur_time)?;
|
||||
|
||||
let issued_by_pk = issued_by.public_key();
|
||||
|
||||
@ -157,7 +153,7 @@ impl Certificate {
|
||||
|
||||
// check root trust and its existence in trusted roots list
|
||||
let root = &chain[0];
|
||||
Trust::verify(root, &root.issued_for, cur_time).map_err(|e| MalformedRoot(e))?;
|
||||
Trust::verify(root, &root.issued_for, cur_time).map_err(MalformedRoot)?;
|
||||
if !trusted_roots.contains(&root.issued_for) {
|
||||
return Err(NoTrustedRoot);
|
||||
}
|
||||
@ -214,7 +210,7 @@ impl Certificate {
|
||||
let from = i * TRUST_LEN + 6;
|
||||
let to = (i + 1) * TRUST_LEN + 6;
|
||||
let slice = &arr[from..to];
|
||||
let t = Trust::decode(slice).map_err(|e| DecodeError(e))?;
|
||||
let t = Trust::decode(slice).map_err(DecodeError)?;
|
||||
chain.push(t);
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,7 @@ impl Revoke {
|
||||
revoke
|
||||
.revoked_by
|
||||
.verify_strict(msg.as_slice(), &revoke.signature)
|
||||
.map_err(|err| IncorrectSignature(err))
|
||||
.map_err(IncorrectSignature)
|
||||
}
|
||||
}
|
||||
|
||||
|
12
src/trust.rs
12
src/trust.rs
@ -119,7 +119,7 @@ impl Trust {
|
||||
let msg: &[u8] =
|
||||
&Self::metadata_bytes(&trust.issued_for, trust.expires_at, trust.issued_at);
|
||||
|
||||
KeyPair::verify(issued_by, msg, &trust.signature).map_err(|e| SignatureError(e))?;
|
||||
KeyPair::verify(issued_by, msg, &trust.signature).map_err(SignatureError)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@ -166,9 +166,8 @@ impl Trust {
|
||||
})?;
|
||||
|
||||
let signature = &arr[PK_LEN..PK_LEN + SIG_LEN];
|
||||
let signature = Signature::from_bytes(signature).map_err(|err| {
|
||||
DecodeError(format!("Cannot decode a signature: {}", err.to_string()))
|
||||
})?;
|
||||
let signature = Signature::from_bytes(signature)
|
||||
.map_err(|err| DecodeError(format!("Cannot decode a signature: {}", err)))?;
|
||||
|
||||
let expiration_bytes = &arr[PK_LEN + SIG_LEN..PK_LEN + SIG_LEN + EXPIRATION_LEN];
|
||||
let expiration_date = u64::from_le_bytes(expiration_bytes.try_into().unwrap());
|
||||
@ -180,7 +179,7 @@ impl Trust {
|
||||
|
||||
Ok(Self {
|
||||
issued_for: pk,
|
||||
signature: signature,
|
||||
signature,
|
||||
expires_at: expiration_date,
|
||||
issued_at: issued_date,
|
||||
})
|
||||
@ -222,8 +221,7 @@ impl Trust {
|
||||
|
||||
// 64 bytes signature
|
||||
let signature = Self::bs58_str_to_vec(signature, "signature")?;
|
||||
let signature =
|
||||
Signature::from_bytes(&signature).map_err(|err| DecodeError(err.to_string()))?;
|
||||
let signature = Signature::from_bytes(&signature).map_err(DecodeError)?;
|
||||
|
||||
// Duration
|
||||
let expires_at = Self::str_to_duration(expires_at, "expires_at")?;
|
||||
|
@ -92,7 +92,7 @@ where
|
||||
S: Storage,
|
||||
{
|
||||
pub fn new(storage: Box<S>) -> Self {
|
||||
Self { storage: storage }
|
||||
Self { storage }
|
||||
}
|
||||
|
||||
/// Insert new root weight
|
||||
@ -131,10 +131,10 @@ where
|
||||
|
||||
// Insert new TrustNode for this root_pk if there wasn't one
|
||||
if self.storage.get(&root_pk)?.is_none() {
|
||||
let mut trust_node = TrustNode::new(root_trust.issued_for.clone(), cur_time);
|
||||
let mut trust_node = TrustNode::new(root_trust.issued_for, cur_time);
|
||||
let root_auth = Auth {
|
||||
trust: root_trust.clone(),
|
||||
issued_by: root_trust.issued_for.clone(),
|
||||
issued_by: root_trust.issued_for,
|
||||
};
|
||||
trust_node.update_auth(root_auth);
|
||||
self.storage.insert(root_pk, trust_node)?;
|
||||
@ -147,7 +147,7 @@ where
|
||||
|
||||
let auth = Auth {
|
||||
trust: trust.clone(),
|
||||
issued_by: previous_trust.issued_for.clone(),
|
||||
issued_by: previous_trust.issued_for,
|
||||
};
|
||||
|
||||
self.storage
|
||||
|
@ -45,7 +45,7 @@ impl InMemoryStorage {
|
||||
.collect();
|
||||
Self {
|
||||
nodes: HashMap::new(),
|
||||
root_weights: root_weights,
|
||||
root_weights,
|
||||
}
|
||||
}
|
||||
|
||||
@ -74,7 +74,7 @@ impl Storage for InMemoryStorage {
|
||||
}
|
||||
|
||||
fn insert(&mut self, pk: PK, node: TrustNode) -> Result<(), Self::Error> {
|
||||
&self.nodes.insert(pk, node);
|
||||
self.nodes.insert(pk, node);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -83,8 +83,8 @@ impl Storage for InMemoryStorage {
|
||||
}
|
||||
|
||||
fn add_root_weight(&mut self, pk: PK, weight: Weight) -> Result<(), Self::Error> {
|
||||
&self.root_weights.insert(pk, weight);
|
||||
Ok({})
|
||||
self.root_weights.insert(pk, weight);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn root_keys(&self) -> Result<Vec<PK>, Self::Error> {
|
||||
@ -113,13 +113,13 @@ impl Storage for InMemoryStorage {
|
||||
match self.nodes.get_mut(&pk) {
|
||||
Some(trust_node) => {
|
||||
trust_node.update_auth(auth);
|
||||
Ok({})
|
||||
Ok(())
|
||||
}
|
||||
None => {
|
||||
let mut trust_node = TrustNode::new(issued_for.clone(), cur_time);
|
||||
let mut trust_node = TrustNode::new(*issued_for, cur_time);
|
||||
trust_node.update_auth(auth);
|
||||
self.nodes.insert(pk.clone(), trust_node);
|
||||
Ok({})
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user