Outsource hashing itself so that we can re-use it
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
parent
b2fbf1e462
commit
d32f41aeab
1 changed files with 7 additions and 2 deletions
|
@ -42,12 +42,17 @@ pub mod sha1 {
|
||||||
|
|
||||||
pub struct Sha1Hasher;
|
pub struct Sha1Hasher;
|
||||||
|
|
||||||
|
impl Sha1Hasher {
|
||||||
|
pub fn sha1_hash(s: &str) -> String {
|
||||||
|
format!("{:x}", Sha1::digest(s.as_bytes())) // TODO: Ugh...
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Hasher for Sha1Hasher {
|
impl Hasher for Sha1Hasher {
|
||||||
const NAME : &'static str = "sha1";
|
const NAME : &'static str = "sha1";
|
||||||
|
|
||||||
fn hash<P: AsRef<Path>>(path: P) -> Result<String> {
|
fn hash<P: AsRef<Path>>(path: P) -> Result<String> {
|
||||||
let digest = Sha1::digest(::std::fs::read_to_string(path)?.as_bytes());
|
Ok(Sha1Hasher::sha1_hash(&::std::fs::read_to_string(path)?))
|
||||||
Ok(format!("{:x}", digest)) // TODO: Ugh...
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue