Crate write_hasher

source ·
Expand description

A hasher that will be a wrapper over any
std::io::Write /
[futures::io::AsyncWrite][futures::io::AsyncWrite] /
[tokio::io::AsyncWrite][tokio::io::AsyncWrite] object

You can wrap any of the previous trait object inside and that will transparently hash the data that is being written to it.

The object should implement AsyncRead so that it can wrap some data and then read from that transparently while offloading the hashing to another thread.

extern crate sha2;
use write_hasher::{WriteHasher, MinDigest};
let mut src = std::fs::File::open(".gitignore").unwrap();
let sink = std::io::sink();
let mut hasher = WriteHasher::<sha2::Sha256, _>::new(sink);
std::io::copy(&mut src, &mut hasher).unwrap();
let x = hasher.finalize();
let x = format!("{:x}", x);
assert_eq!(
    "c1e953ee360e77de57f7b02f1b7880bd6a3dc22d1a69e953c2ac2c52cc52d247",
    x
);

Modules

Structs

  • A hasher that will be a wrapper over any Write / AsyncWrite object and transparently calculate hash for any data written to it

Traits

  • A minimal version of [Digest][digest::digest] trait that is used to implement the WriteHasher and all implementations of the Digest trait.