From b48e574a47e56521802010b2fbb3ca5e6f2b3d1c Mon Sep 17 00:00:00 2001 From: mauricefisher64 <92736594+mauricefisher64@users.noreply.github.com> Date: Fri, 4 Oct 2024 17:07:18 -0400 Subject: [PATCH] fix: Make sure algorithm is being respected in data_hash.rs (#613) Make sure algorithm is being respected in data_hash.rs --- sdk/src/assertions/data_hash.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/sdk/src/assertions/data_hash.rs b/sdk/src/assertions/data_hash.rs index 4d75ceff8..8f4737613 100644 --- a/sdk/src/assertions/data_hash.rs +++ b/sdk/src/assertions/data_hash.rs @@ -219,11 +219,17 @@ impl DataHash { return Err(Error::BadParam("asset hash is remote".to_owned())); } - let curr_alg = alg.unwrap_or("sha256"); + let curr_alg = match &self.alg { + Some(a) => a.clone(), + None => match alg { + Some(a) => a.to_owned(), + None => return Err(Error::HashMismatch("no alg specified".to_owned())), + }, + }; let exclusions = self.exclusions.as_ref().cloned(); - if verify_asset_by_alg(curr_alg, &self.hash, asset_path, exclusions) { + if verify_asset_by_alg(&curr_alg, &self.hash, asset_path, exclusions) { Ok(()) } else { Err(Error::HashMismatch("Hashes do not match".to_owned())) @@ -240,7 +246,7 @@ impl DataHash { Some(a) => a.clone(), None => match alg { Some(a) => a.to_owned(), - None => "sha256".to_string(), + None => return Err(Error::HashMismatch("no alg specified".to_owned())), }, };