Skip to content
This repository has been archived by the owner on Nov 7, 2024. It is now read-only.

Fix digest usage #666

Merged
merged 1 commit into from
Sep 24, 2024
Merged

Fix digest usage #666

merged 1 commit into from
Sep 24, 2024

Conversation

cgwalters
Copy link
Member

In some places we started doing .digest().digest() which drops the algorithm. Some basic unit tests
would have caught this - I added one. We also need an "upgrade from previous" test.

Trying to fix this revealed a bunch more places where we had String and not Digest.

Fixing those gets us type safety and points out the problem areas. Since we're breaking API as this will be the real first 0.15 release,

  • Drop unnecessary ManifestLayerState wrappering
  • Fix the manifest digest members of various structs to be a Digest

@cgwalters
Copy link
Member Author

.digest().digest()

In other words this one should be a big red flag in code - it's never right to just ignore the algorithm. What's the most common though is a pattern like:

  • Assert that the algorithm is sha256
  • If so return that digest and use it in a place that wants "plain" sha256 without the algorithm prefix

We could look at adding a helper for that.

In some places we started doing `.digest().digest()`
which drops the algorithm. Some basic unit tests
would have caught this - I added one. We also need an
"upgrade from previous" test.

Trying to fix this revealed a bunch more places where we
had `String` and not `Digest`.

Fixing those gets us type safety and points out the problem
areas.  Since we're breaking API as this will be the real first 0.15
release,

- Drop unnecessary ManifestLayerState wrappering
- Fix the manifest digest members of various structs to be a Digest
@jeckersb jeckersb self-assigned this Sep 24, 2024
Copy link
Contributor

@jeckersb jeckersb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I definitely relied entirely too much on the compiler and tests to sanity check the original patch. Some of this is really obvious in retrospect!

use super::*;

#[test]
fn test_ref_for_descriptor() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

@@ -21,7 +21,7 @@ use flate2::Compression;
use fn_error_context::context;
use futures_util::TryFutureExt;
use oci_spec::image::{
self as oci_image, Arch, Descriptor, History, ImageConfiguration, ImageManifest,
self as oci_image, Arch, Descriptor, Digest, History, ImageConfiguration, ImageManifest,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still use oci_image::Digest in a bunch of places, not a big deal but I can do a followup PR after this merges just so we're consistent everywhere.

@jeckersb
Copy link
Contributor

Obligatory acknowledgement that the bootc build test is failing because we need to do the CI dance to get both updated in-tandem.

@cgwalters cgwalters merged commit 0427aa9 into ostreedev:main Sep 24, 2024
9 of 10 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants