summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2019-02-22 11:23:57 +0100
committerMatthias Beyer <mail@beyermatthias.de>2019-02-22 11:23:57 +0100
commitd32f41aeab89a8b97c3233f2c763fbb18f169c5b (patch)
treed8379f7de4f4c740b183a4190114ed9a3543a3dc
parentb2fbf1e4629fd05b37ac5636379efb709b060a1e (diff)
downloadimag-d32f41aeab89a8b97c3233f2c763fbb18f169c5b.zip
imag-d32f41aeab89a8b97c3233f2c763fbb18f169c5b.tar.gz
Outsource hashing itself so that we can re-use it
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--lib/entry/libimagentryref/src/hasher.rs9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/entry/libimagentryref/src/hasher.rs b/lib/entry/libimagentryref/src/hasher.rs
index aec7eeb..adadd60 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<P: AsRef<Path>>(path: P) -> Result<String> {
- 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)?))
}
}