Skip to content

Commit

Permalink
fix: Make sure algorithm is being respected in data_hash.rs (#613)
Browse files Browse the repository at this point in the history
Make sure algorithm is being respected in data_hash.rs
  • Loading branch information
mauricefisher64 authored Oct 4, 2024
1 parent 53a02ea commit b48e574
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions sdk/src/assertions/data_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand All @@ -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())),
},
};

Expand Down

0 comments on commit b48e574

Please # to comment.