DaGenix / rust-crypto

A (mostly) pure-Rust implementation of various cryptographic algorithms.
Apache License 2.0
1.4k stars 298 forks source link

feature request: Provide a type that wraps a Write and updates a digest when it's written to #472

Closed dzfranklin closed 3 years ago

dzfranklin commented 3 years ago

I want to write a bunch of things to a file and then write the digest of everything I've written. I thought it might be nice to have an API like so:

let mut file = File::open("foo.txt")?;
let mut digest = Sha1::new();
let mut out = WithDigest::new(&mut file, &mut digest);

for thingy in things_to_write {
    out.write_all(&thingy)?;
}

let mut digest_bytes = Vec::with_capacity(digest.output_bytes());
digest.result(&mut digest_bytes);
file.write_all(&digest_bytes)?;

file.flush()?

I wrote a rough untested draft of how this could be implemented. What would you think of a PR?

dzfranklin commented 3 years ago

Nevermind, I just learned this is unmaintained.