Skip to content

Commit

Permalink
Fix all clippy warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
matheus23 committed Jun 22, 2023
1 parent e4fc088 commit 5d70a1d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 20 deletions.
6 changes: 3 additions & 3 deletions wnfs-nameaccumulator/src/uint256_serde_le.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ pub(crate) fn serialize<S>(uint: &BigUint, serializer: S) -> Result<S::Ok, S::Er
where
S: Serializer,
{
serde_bytes::serialize(to_bytes_helper(uint).as_ref(), serializer)
serde_bytes::serialize(to_bytes_helper::<256>(uint).as_ref(), serializer)
}

pub(crate) fn to_bytes_helper(state: &BigUint) -> [u8; 256] {
pub(crate) fn to_bytes_helper<const N: usize>(state: &BigUint) -> [u8; N] {
let vec = state.to_bytes_le();
let mut bytes = [0u8; 256];
let mut bytes = [0u8; N];
bytes[..vec.len()].copy_from_slice(&vec);
bytes
}
14 changes: 7 additions & 7 deletions wnfs/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use semver::Version;
use skip_ratchet::PreviousErr;
use thiserror::Error;
use wnfs_common::{HashOutput, NodeType};
use wnfs_common::NodeType;

//--------------------------------------------------------------------------------------------------
// Type Definitions
Expand Down Expand Up @@ -51,8 +51,8 @@ pub enum FsError {
#[error("Cannot merge or compare forests, incompatible accumulator setups")]
IncompatibleAccumulatorSetups,

#[error("Mismatch between PrivateNode name {0:x?} and its mountpoint {0:x?}")]
MountPointAndDeserializedNameMismatch([u8; 256], [u8; 256]),
#[error("Mismatch between PrivateNode name {0} and its mountpoint {0}")]
MountPointAndDeserializedNameMismatch(String, String),

#[error("Cannot find private ref with specified root path")]
PrivateRefNotFound,
Expand Down Expand Up @@ -97,9 +97,9 @@ pub enum RsaError {

#[derive(Debug, Error)]
pub enum VerificationError {
#[error("Couldn't verify write for label {0:?}")]
UnverifiedWrite(HashOutput),
#[error("Couldn't verify write for label {0}")]
UnverifiedWrite(String),

#[error("Write to disallowed base {0:x?}")]
WriteToDisallowedBase([u8; 256]),
#[error("Write to disallowed base {0}")]
WriteToDisallowedBase(String),
}
13 changes: 9 additions & 4 deletions wnfs/src/private/forest/hamt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use anyhow::Result;
use async_trait::async_trait;
use libipld::{Cid, Ipld};
use rand_core::RngCore;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use serde::{
de::Error as DeError, ser::Error as SerError, Deserialize, Deserializer, Serialize, Serializer,
};
use sha3::Sha3_256;
use std::{collections::BTreeSet, rc::Rc};
use wnfs_common::{AsyncSerialize, BlockStore, HashOutput, Link};
Expand Down Expand Up @@ -323,7 +325,8 @@ impl AsyncSerialize for HamtForest {
.map_err(serde::ser::Error::custom)?;

let Ipld::Map(mut ipld_map) = hamt_ipld else {
return todo!(); // TODO(matheus23) probably use `Node::AsyncSerialize` instead of `Hamt`
let msg = format!("Expected HAMT root to serialize to an IPLD map, but got {hamt_ipld:#?}");
return Err(SerError::custom(FsError::InvalidDeserialization(msg)));
};

ipld_map.insert("accumulator".into(), accumulator_ipld);
Expand All @@ -340,10 +343,12 @@ impl<'de> Deserialize<'de> for HamtForest {
let ipld: Ipld = Deserialize::deserialize(deserializer)?;
let hamt = Hamt::deserialize(ipld.clone()).map_err(serde::de::Error::custom)?;
let Ipld::Map(ipld_map) = ipld else {
return todo!(); // TODO(matheus23)
let msg = format!("Expected IPLD Map representing a private forest, but got {ipld:#?}");
return Err(DeError::custom(FsError::InvalidDeserialization(msg)));
};
let Some(accumulator_ipld) = ipld_map.get("accumulator").cloned() else {
return todo!(); // TODO(matheus23)
let msg = "IPLD Map entry for 'accumulator' missing in private forest".to_string();
return Err(DeError::custom(FsError::InvalidDeserialization(msg)));
};
let accumulator =
AccumulatorSetup::deserialize(accumulator_ipld).map_err(serde::de::Error::custom)?;
Expand Down
7 changes: 3 additions & 4 deletions wnfs/src/private/forest/proofs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ use crate::error::{FsError, VerificationError};
use anyhow::Result;
use async_trait::async_trait;
use libipld::Cid;
use sha3::Sha3_256;
use std::{
collections::{BTreeSet, HashMap},
rc::Rc,
};
use wnfs_common::{BlockStore, HashOutput};
use wnfs_hamt::{Hasher, Pair};
use wnfs_hamt::Pair;
use wnfs_nameaccumulator::{
AccumulatorSetup, BatchedProofPart, BatchedProofVerification, Name, NameAccumulator,
UnbatchableProofPart,
Expand Down Expand Up @@ -94,13 +93,13 @@ impl ProvingHamtForest {
// Verify that there exists a proof for the changed label & obtain the base that
// was proven from.
let Some((base, _)) = self.proofs.proofs_by_commitment.get(&change.key) else {
return Err(VerificationError::UnverifiedWrite(Sha3_256::hash(&change.key)).into());
return Err(VerificationError::UnverifiedWrite(format!("{:?}", change.key)).into());
};

// Verify that the base is allowed to be written to (e.g. has been signed by a party
// with a signature chain up to the root owner).
if !allowed_bases.contains(base) {
return Err(VerificationError::WriteToDisallowedBase(*base.as_bytes()).into());
return Err(VerificationError::WriteToDisallowedBase(format!("{base:?}")).into());
}
}

Expand Down
4 changes: 2 additions & 2 deletions wnfs/src/private/node/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ impl PrivateNodeHeader {
let name_acc = header.name.as_accumulator(setup);
if mounted_acc != name_acc {
return Err(FsError::MountPointAndDeserializedNameMismatch(
*mounted_acc.as_bytes(),
*name_acc.as_bytes(),
format!("{mounted_acc:?}"),
format!("{name_acc:?}"),
)
.into());
}
Expand Down

0 comments on commit 5d70a1d

Please sign in to comment.