Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for hashing from a reader #159

Open
wants to merge 8 commits into
base: feat/no-digest
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ use multihash::MultihashCode;
#[derive(Clone, Copy, Debug, Eq, Multihash, PartialEq)]
#[mh(alloc_size = 64)]
pub enum Code {
#[mh(code = 0x01, hasher = multihash::Sha2_256, digest = multihash::Sha2Digest<32>)]
#[mh(code = 0x01, hasher = multihash::Sha2_256)]
Foo,
#[mh(code = 0x02, hasher = multihash::Sha2_512, digest = multihash::Sha2Digest<64>)]
#[mh(code = 0x02, hasher = multihash::Sha2_512)]
Bar,
}

Expand Down
21 changes: 11 additions & 10 deletions benches/multihash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rand::Rng;
use multihash::{
Blake2b256, Blake2b512, Blake2s128, Blake2s256, Blake3_256, Hasher, Keccak224, Keccak256,
Keccak384, Keccak512, Sha1, Sha2_256, Sha2_512, Sha3_224, Sha3_256, Sha3_384, Sha3_512,
StatefulHasher, Strobe256, Strobe512,
Strobe256, Strobe512,
};

macro_rules! group_digest {
Expand All @@ -13,7 +13,9 @@ macro_rules! group_digest {
$(
group.bench_function($id, |b| {
b.iter(|| {
let _ = black_box($hash::digest($input));
let mut hasher = $hash::default();
hasher.update(black_box($input));
let _ = black_box(hasher.finalize());
})
});
)*
Expand All @@ -27,14 +29,13 @@ macro_rules! group_stream {
$(
group.bench_function($id, |b| {
b.iter(|| {
let _ = black_box({
let mut hasher = <$hash>::default();
for i in 0..3 {
let start = i * 256;
hasher.update(&$input[start..(start + 256)]);
}
hasher.finalize()
});
let input = black_box($input);
let mut hasher = <$hash>::default();
for i in 0..3 {
let start = i * 256;
hasher.update(&input[start..(start + 256)]);
}
let _ = black_box(hasher.finalize());
})
});
)*
Expand Down
2 changes: 1 addition & 1 deletion derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ std = []

[dev-dependencies]
pretty_assertions = "1.0.0"
multihash = { path = "..", default-features = false, features = ["derive", "sha2"] }
multihash = { path = "..", default-features = false, features = ["derive", "sha2", "std"] }
4 changes: 2 additions & 2 deletions derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
//! #[derive(Clone, Copy, Debug, Eq, Multihash, PartialEq)]
//! #[mh(alloc_size = 64)]
//! pub enum Code {
//! #[mh(code = 0x01, hasher = multihash::Sha2_256, digest = multihash::Sha2Digest<32>)]
//! #[mh(code = 0x01, hasher = multihash::Sha2_256)]
//! Foo,
//! #[mh(code = 0x02, hasher = multihash::Sha2_512, digest = multihash::Sha2Digest<64>)]
//! #[mh(code = 0x02, hasher = multihash::Sha2_512)]
//! Bar,
//! }
//!
Expand Down
Loading