aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/Cargo.toml2
-rw-r--r--src/util/data.rs24
2 files changed, 25 insertions, 1 deletions
diff --git a/src/util/Cargo.toml b/src/util/Cargo.toml
index cb2baf06..93115843 100644
--- a/src/util/Cargo.toml
+++ b/src/util/Cargo.toml
@@ -16,8 +16,10 @@ path = "lib.rs"
rand = "0.7"
hex = "0.3"
sha2 = "0.8"
+blake2 = "0.9"
err-derive = "0.2.3"
log = "0.4"
+fasthash = "0.4"
sled = "0.31"
diff --git a/src/util/data.rs b/src/util/data.rs
index 657467ba..a1c292e7 100644
--- a/src/util/data.rs
+++ b/src/util/data.rs
@@ -1,7 +1,6 @@
use rand::Rng;
use serde::de::{self, Visitor};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
-use sha2::{Digest, Sha256};
use std::fmt;
use std::time::{SystemTime, UNIX_EPOCH};
@@ -78,6 +77,8 @@ pub type UUID = FixedBytes32;
pub type Hash = FixedBytes32;
pub fn sha256sum(data: &[u8]) -> Hash {
+ use sha2::{Digest, Sha256};
+
let mut hasher = Sha256::new();
hasher.input(data);
let mut hash = [0u8; 32];
@@ -85,6 +86,27 @@ pub fn sha256sum(data: &[u8]) -> Hash {
hash.into()
}
+pub fn blake2sum(data: &[u8]) -> Hash {
+ use blake2::{Blake2b, Digest};
+
+ let mut hasher = Blake2b::new();
+ hasher.update(data);
+ let mut hash = [0u8; 32];
+ hash.copy_from_slice(&hasher.finalize()[..32]);
+ hash.into()
+}
+
+pub type FastHash = u64;
+
+pub fn fasthash(data: &[u8]) -> FastHash {
+ use std::hash::Hasher;
+ use fasthash::{xx::Hasher64, FastHasher};
+
+ let mut h = Hasher64::new();
+ h.write(data);
+ h.finish()
+}
+
pub fn gen_uuid() -> UUID {
rand::thread_rng().gen::<[u8; 32]>().into()
}