Skip to content

feat(pack): add a digest algorithm option to PackManifest - #1494

Merged
TerryHowe merged 2 commits into
oras-project:mainfrom
Rohilalala:feat/pack-digest-algorithm
Oct 2, 2026
Merged

TerryHowe merged 2 commits into
oras-project:mainfrom
Rohilalala:feat/pack-digest-algorithm

Conversation

@Rohilalala

@Rohilalala Rohilalala commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Part of #1491: lets callers choose the digest algorithm when packing (item 1), restricted to an allowlist (item 2).

PackManifest built every descriptor with digest.Canonical, so its output was always SHA-256.

  • PackManifestOptions.DigestAlgorithm selects the algorithm for the manifest and for the config and empty blobs that PackManifest generates. Descriptors passed in Subject, Layers and ConfigDescriptor keep their own digests.
  • content.NewDescriptorFromBytesWithAlgorithm is the matching descriptor helper.
  • Empty means digest.Canonical, so existing output is unchanged.
  • Only SHA-256, SHA-384 and SHA-512 are accepted (internal/descriptor.IsSupportedAlgorithm, which the OCI store's GC now uses too). Anything else, or an algorithm whose hash package is not linked, returns errdef.ErrUnsupported before anything is pushed.

Not in this PR:

  • The existing Available() checks in registry/remote are not moved to the allowlist.
  • Pushing a non-SHA-256 manifest to a registry that answers with a SHA-256 Docker-Content-Digest still fails the strict check on pushes in registry/remote. That path is untouched.
  • The deprecated Pack keeps using digest.Canonical.

AI-assisted (Claude); I reviewed and tested the change.

PackManifest always built its descriptors with digest.Canonical, so its
output was SHA-256 even where SHA-384 or SHA-512 is the standard.

Add PackManifestOptions.DigestAlgorithm, used for the manifest and for the
config and empty blobs PackManifest generates, and
content.NewDescriptorFromBytesWithAlgorithm. The default stays
digest.Canonical, and an unavailable algorithm returns ErrUnsupported.

Part of oras-project#1491

Signed-off-by: Aditya <205600203+Rohilalala@users.noreply.github.com>
@codecov

codecov Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.55556% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.32%. Comparing base (6ffa9e8) to head (3d5bfc5).

Files with missing lines Patch % Lines
pack.go 92.30% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1494      +/-   ##
==========================================
+ Coverage   91.28%   91.32%   +0.03%     
==========================================
  Files         100      100              
  Lines        7848     7872      +24     
==========================================
+ Hits         7164     7189      +25     
+ Misses        673      672       -1     
  Partials       11       11              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread pack.go Outdated
Comment thread pack.go Outdated
Comment thread pack.go
Accept only SHA-256, SHA-384 and SHA-512 when packing, instead of whatever
go-digest has registered, and share the list with the OCI store. Also note
that non-canonical empty blobs differ from DescriptorEmptyJSON, and wrap
the manifest descriptor error like the marshal error.

Signed-off-by: Aditya <205600203+Rohilalala@users.noreply.github.com>

@TerryHowe TerryHowe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/lgtm

@TerryHowe
TerryHowe merged commit 032974c into oras-project:main Oct 2, 2026
10 checks passed
@TerryHowe

Copy link
Copy Markdown
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants