From d32f41aeab89a8b97c3233f2c763fbb18f169c5b Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 22 Feb 2019 11:23:57 +0100 Subject: [PATCH] Outsource hashing itself so that we can re-use it Signed-off-by: Matthias Beyer --- lib/entry/libimagentryref/src/hasher.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/entry/libimagentryref/src/hasher.rs b/lib/entry/libimagentryref/src/hasher.rs index aec7eebc..adadd606 100644 --- a/lib/entry/libimagentryref/src/hasher.rs +++ b/lib/entry/libimagentryref/src/hasher.rs @@ -42,12 +42,17 @@ pub mod sha1 { 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 { const NAME : &'static str = "sha1"; fn hash>(path: P) -> Result { - let digest = Sha1::digest(::std::fs::read_to_string(path)?.as_bytes()); - Ok(format!("{:x}", digest)) // TODO: Ugh... + Ok(Sha1Hasher::sha1_hash(&::std::fs::read_to_string(path)?)) } }