Skip to content

Commit

Permalink
Allow empty Merkle proof for last leaf node. (#470)
Browse files Browse the repository at this point in the history
  • Loading branch information
mauricefisher64 authored May 22, 2024
1 parent 8764c54 commit f8c9be3
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions sdk/src/assertions/bmff_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,15 @@ impl MerkleMap {
location: u32,
proof: &Option<VecByteBuf>,
) -> bool {
if location >= self.count {
return false;
}

let mut index = location;
let mut hash = hash.to_vec();
let layers = C2PAMerkleTree::to_layout(self.count as usize);

if let Some(hashes) = proof {
let layers = C2PAMerkleTree::to_layout(self.count as usize);

// playback proof
let mut proof_index = 0;
for layer in layers {
Expand Down Expand Up @@ -199,6 +202,14 @@ impl MerkleMap {
}
}

index /= 2;
}
} else {
//empty proof playback
for layer in layers {
if layer == self.hashes.len() {
break;
}
index /= 2;
}
}
Expand Down Expand Up @@ -408,6 +419,10 @@ impl BmffHash {
if let Some(pos) = boxes.iter().position(|b| b.path == "moof") {
let mut box_list = vec![boxes[pos].clone()];

if pos == 0 {
return moof_list; // this does not contain fragmented content
}

for b in boxes[pos + 1..].iter() {
if b.path == "moof" {
moof_list.push(box_list); // save box list
Expand Down

0 comments on commit f8c9be3

Please sign in to comment.