Skip to content

Commit

Permalink
fix: bug in v2 gap comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
elmurci committed Feb 11, 2025
1 parent 47c304c commit 2f78504
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
13 changes: 9 additions & 4 deletions src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ pub fn get_timestamp() -> Result<u64> {

pub fn blobs_have_no_time_gaps(mut blobs: Vec<BlobV2>) -> Result<bool> {
// Sort by start date
blobs.sort_by_key(|blob| blob.decoded_blob.as_ref().unwrap().effective.unwrap());
blobs.sort_by_key(|blob| {
blob.decoded_blob
.as_ref()
.and_then(|decoded| decoded.effective)
.unwrap_or_default()
});

// Early return if empty or only one blob
if blobs.len() < 2 {
Expand All @@ -51,13 +56,13 @@ pub fn blobs_have_no_time_gaps(mut blobs: Vec<BlobV2>) -> Result<bool> {
if next
.decoded_blob
.as_ref()
.context("Could not get Decoded Blob")?
.context("Could not get next Decoded Blob")?
.effective
.context("Could not get Effectivate date")?
.context("Could not get next Effectivate date")?
> current
.decoded_blob
.as_ref()
.context("Could not get Decoded Blob")?
.context("Could not get current Decoded Blob")?
.expiration
{
return Ok(false);
Expand Down
10 changes: 6 additions & 4 deletions src/vl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,7 @@ pub async fn sign_vl(
} else {
anyhow::bail!(VlValidationError::MalformedVl);
}
// Make sure there is no gap when generating new UNLs
if !blobs_have_no_time_gaps(v.blobs_v2.context("Missing blobs_v2")?)? {
anyhow::bail!(VlValidationError::HasGaps);
}

}

let mut vl = v2_vl.clone().unwrap_or_default();
Expand Down Expand Up @@ -343,6 +340,11 @@ pub async fn sign_vl(
blob_verification: None,
});
vl.version = 2;

// Make sure there is no gap when generating new UNLs
if !blobs_have_no_time_gaps(decode_vl_v2(&vl.clone())?.decoded_blobs_v2.context("Could not get blobs v2")?)? {
anyhow::bail!(VlValidationError::HasGaps);
}
}

Ok(vl)
Expand Down

0 comments on commit 2f78504

Please sign in to comment.