diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2020-12-09 12:57:54 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2020-12-09 14:52:09 +0100 |
commit | 757638df78813c5f8c5872b2818221a7ed689f4b (patch) | |
tree | c8ca82706b4b731655d2b5708f1a2a4921d4c9f1 /src | |
parent | 900719e3b89476c7134d0be4b3b90f1725671e2b (diff) |
Change implementation to return Ok(()) on success
This changes the source file hash verification mechanism to return an
Ok(()) on success and an Err(_) on failure.
Returning a bool seems to be the right way, but it is not because if the
verification fails, we print the error message anyways, so there is no
point in having a bool around.
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'src')
-rw-r--r-- | src/package/source.rs | 9 | ||||
-rw-r--r-- | src/source/mod.rs | 2 |
2 files changed, 8 insertions, 3 deletions
diff --git a/src/package/source.rs b/src/package/source.rs index 9b5ed4a..8ec3a52 100644 --- a/src/package/source.rs +++ b/src/package/source.rs @@ -1,3 +1,4 @@ +use anyhow::anyhow; use anyhow::Result; use getset::Getters; use serde::Deserialize; @@ -31,9 +32,13 @@ pub struct SourceHash { } impl SourceHash { - pub fn matches_hash_of(&self, buf: &[u8]) -> Result<bool> { + pub fn matches_hash_of(&self, buf: &[u8]) -> Result<()> { let h = self.hashtype.hash_buffer(&buf)?; - Ok(h == self.value) + if h == self.value { + Ok(()) + } else { + Err(anyhow!("Hash mismatch, expected '{}', got '{}'", self.value, h)) + } } #[cfg(test)] diff --git a/src/source/mod.rs b/src/source/mod.rs index 77f7f14..cf96f33 100644 --- a/src/source/mod.rs +++ b/src/source/mod.rs @@ -80,7 +80,7 @@ impl SourceEntry { Ok(()) } - pub async fn verify_hash(&self) -> Result<bool> { + pub async fn verify_hash(&self) -> Result<()> { use tokio::io::AsyncReadExt; let p = self.source_file_path(); |