use std::{fs::File, io, path::Path};
use digest_io::IoWrapper;
use md5::Md5;
use sha2::{Digest, Sha256, Sha512};
pub fn sha256sum<P>(path: P) -> io::Result<String>
where
P: AsRef<Path>,
{
let mut file = File::open(path)?;
let mut hasher = IoWrapper(Sha256::new());
io::copy(&mut file, &mut hasher)?;
Ok(hex::encode(hasher.0.finalize()))
}
pub fn sha512sum<P>(path: P) -> io::Result<String>
where
P: AsRef<Path>,
{
let mut file = File::open(path)?;
let mut hasher = IoWrapper(Sha512::new());
io::copy(&mut file, &mut hasher)?;
Ok(hex::encode(hasher.0.finalize()))
}
pub fn md5sum<P>(path: P) -> io::Result<String>
where
P: AsRef<Path>,
{
let mut file = File::open(path)?;
let mut hasher = IoWrapper(Md5::new());
io::copy(&mut file, &mut hasher)?;
Ok(hex::encode(hasher.0.finalize()))
}