Skip to content

Commit

Permalink
use blake3 for hashing
Browse files Browse the repository at this point in the history
  • Loading branch information
radumarias committed May 18, 2024
1 parent 789482f commit baf5435
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 26 deletions.
81 changes: 59 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] }
tracing-appender = "0.2.3"
tracing-test = "0.2.4"
ctrlc = { version = "3.1.9", features = ["termination"] }
sha2 = "0.10.8"
strum = "0.26.2"
strum_macros = "0.26.2"
rpassword = "7.3.1"
Expand All @@ -55,6 +54,7 @@ okaywal = "0.3.1"
atomic-write-file = "0.1.4"
tempfile = "3.10.1"
async-trait = "0.1.80"
blake3 = "=0.1.3"

[target.'cfg(unix)'.dependencies]
fuse3 = { version = "0.7.1", features = ["tokio-runtime", "unprivileged"] }
Expand Down
5 changes: 2 additions & 3 deletions src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use rand_chacha::ChaCha20Rng;
use ring::aead::{AES_256_GCM, CHACHA20_POLY1305};
use secrecy::{ExposeSecret, SecretString, SecretVec};
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
use strum_macros::{Display, EnumIter, EnumString};
use thiserror::Error;
use tokio::sync::RwLock;
Expand Down Expand Up @@ -268,14 +267,14 @@ pub fn hash_file_name(name: &SecretString) -> FsResult<String> {

#[must_use]
pub fn hash(data: &[u8]) -> [u8; 32] {
let mut hasher = Sha256::new();
let mut hasher = blake3::Hasher::new();
hasher.update(data);
hasher.finalize().into()
}

#[allow(clippy::missing_panics_doc)]
pub fn hash_reader<R: Read + ?Sized>(r: &mut R) -> io::Result<[u8; 32]> {
let mut hasher = Sha256::new();
let mut hasher = blake3::Hasher::new();
let mut reader = io::BufReader::new(r);
io::copy(&mut reader, &mut hasher)?;
Ok(hasher.finalize().into())
Expand Down

0 comments on commit baf5435

Please sign in to comment.