rust-crypto
rust-crypto copied to clipboard
Add `Digest::as_write()` method
@apoelstra I think, this change is better then #294 because this change affects all digests (SHA1, SHA256, MD5, HMAC etc).
Usage example:
use crypto::digest::Digest;
use crypto::md5::Md5;
use std::io;
use std::io::{Error, Read, Write};
pub fn stream_md5<R: Read>(reader: &mut R) -> Result<String, Error> {
let mut hash = Md5::new();
try! (io::copy(reader, &mut hash.as_write()));
Ok(hash.result_str())
}