Skip to content

Commit

Permalink
refactor: Move ShortDigest out of display package (#1373)
Browse files Browse the repository at this point in the history
Signed-off-by: Terry Howe <[email protected]>
  • Loading branch information
Terry Howe authored May 6, 2024
1 parent 979dbd7 commit 6e525ce
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 33 deletions.
32 changes: 0 additions & 32 deletions cmd/oras/internal/display/status/convert.go

This file was deleted.

3 changes: 2 additions & 1 deletion cmd/oras/internal/display/status/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"context"
"fmt"
"io"
"oras.land/oras/internal/descriptor"
"sync"

ocispec "github.com/opencontainers/image-spec/specs-go/v1"
Expand Down Expand Up @@ -57,7 +58,7 @@ func (p *Printer) PrintStatus(desc ocispec.Descriptor, status string, verbose bo
}
name = desc.MediaType
}
return p.Println(status, ShortDigest(desc), name)
return p.Println(status, descriptor.ShortDigest(desc), name)
}

// StatusPrinter returns a tracking function for transfer status.
Expand Down
12 changes: 12 additions & 0 deletions internal/descriptor/descriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.
package descriptor

import (
"github.com/opencontainers/go-digest"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"

"oras.land/oras/internal/docker"
Expand All @@ -25,3 +26,14 @@ import (
func IsImageManifest(desc ocispec.Descriptor) bool {
return desc.MediaType == docker.MediaTypeManifest || desc.MediaType == ocispec.MediaTypeImageManifest
}

// ShortDigest converts the digest of the descriptor to a short form for displaying.
func ShortDigest(desc ocispec.Descriptor) (digestString string) {
digestString = desc.Digest.String()
if err := desc.Digest.Validate(); err == nil {
if algo := desc.Digest.Algorithm(); algo == digest.SHA256 {
digestString = desc.Digest.Encoded()[:12]
}
}
return digestString
}

0 comments on commit 6e525ce

Please sign in to comment.