diff --git a/cmd/oras/internal/display/status/convert.go b/cmd/oras/internal/display/status/convert.go deleted file mode 100644 index b34ff383e..000000000 --- a/cmd/oras/internal/display/status/convert.go +++ /dev/null @@ -1,32 +0,0 @@ -/* -Copyright The ORAS Authors. -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package status - -import ( - "github.com/opencontainers/go-digest" - ocispec "github.com/opencontainers/image-spec/specs-go/v1" -) - -// 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 -} diff --git a/cmd/oras/internal/display/status/print.go b/cmd/oras/internal/display/status/print.go index ac55e9fa6..b2094964a 100644 --- a/cmd/oras/internal/display/status/print.go +++ b/cmd/oras/internal/display/status/print.go @@ -19,6 +19,7 @@ import ( "context" "fmt" "io" + "oras.land/oras/internal/descriptor" "sync" ocispec "github.com/opencontainers/image-spec/specs-go/v1" @@ -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. diff --git a/internal/descriptor/descriptor.go b/internal/descriptor/descriptor.go index 6e9aaa674..3bcf28cb9 100644 --- a/internal/descriptor/descriptor.go +++ b/internal/descriptor/descriptor.go @@ -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" @@ -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 +}