Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup: Add Digest to the SignedEntity interface. #2960

Merged
merged 1 commit into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/cosign/cli/copy/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func CopyCmd(ctx context.Context, regOpts options.RegistryOptions, srcImg, dstIm

if err := walk.SignedEntity(gctx, root, func(ctx context.Context, se oci.SignedEntity) error {
// Both of the SignedEntity types implement Digest()
h, err := se.(interface{ Digest() (v1.Hash, error) }).Digest()
h, err := se.Digest()
if err != nil {
return err
}
Expand Down Expand Up @@ -119,7 +119,7 @@ func CopyCmd(ctx context.Context, regOpts options.RegistryOptions, srcImg, dstIm
}

// Now that everything has been copied over, update the tag.
h, err := root.(interface{ Digest() (v1.Hash, error) }).Digest()
h, err := root.Digest()
if err != nil {
return err
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/oci/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@

package oci

import v1 "github.com/google/go-containerregistry/pkg/v1"

type SignedEntity interface {
// Digest returns the sha256 of this image's manifest.
Digest() (v1.Hash, error)

// Signatures returns the set of signatures currently associated with this
// entity, or the empty equivalent if none are found.
Signatures() (Signatures, error)
Expand Down
12 changes: 4 additions & 8 deletions pkg/oci/remote/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,8 @@ func suffixTag(ref name.Reference, suffix string, o *options) (name.Tag, error)
return o.TargetRepository.Tag(normalize(h, o.TagPrefix, suffix)), nil
}

type digestable interface {
Digest() (v1.Hash, error)
}

// signatures is a shared implementation of the oci.Signed* Signatures method.
func signatures(digestable digestable, o *options) (oci.Signatures, error) {
func signatures(digestable oci.SignedEntity, o *options) (oci.Signatures, error) {
h, err := digestable.Digest()
if err != nil {
return nil, err
Expand All @@ -137,7 +133,7 @@ func signatures(digestable digestable, o *options) (oci.Signatures, error) {
}

// attestations is a shared implementation of the oci.Signed* Attestations method.
func attestations(digestable digestable, o *options) (oci.Signatures, error) {
func attestations(digestable oci.SignedEntity, o *options) (oci.Signatures, error) {
h, err := digestable.Digest()
if err != nil {
return nil, err
Expand All @@ -146,7 +142,7 @@ func attestations(digestable digestable, o *options) (oci.Signatures, error) {
}

// attachment is a shared implementation of the oci.Signed* Attachment method.
func attachment(digestable digestable, attName string, o *options) (oci.File, error) {
func attachment(digestable oci.SignedEntity, attName string, o *options) (oci.File, error) {
// Try using OCI 1.1 behavior
if file, err := attachmentExperimentalOCI(digestable, attName, o); err == nil {
return file, nil
Expand Down Expand Up @@ -201,7 +197,7 @@ func (f *attached) Payload() ([]byte, error) {
}

// attachmentExperimentalOCI is a shared implementation of the oci.Signed* Attachment method (for OCI 1.1+ behavior).
func attachmentExperimentalOCI(digestable digestable, attName string, o *options) (oci.File, error) {
func attachmentExperimentalOCI(digestable oci.SignedEntity, attName string, o *options) (oci.File, error) {
h, err := digestable.Digest()
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions pkg/oci/remote/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func WriteSignatures(repo name.Repository, se oci.SignedEntity, opts ...Option)
}

// Determine the tag to which these signatures should be published.
h, err := se.(digestable).Digest()
h, err := se.Digest()
if err != nil {
return err
}
Expand All @@ -125,7 +125,7 @@ func WriteAttestations(repo name.Repository, se oci.SignedEntity, opts ...Option
}

// Determine the tag to which these signatures should be published.
h, err := se.(digestable).Digest()
h, err := se.Digest()
if err != nil {
return err
}
Expand Down