diff --git a/cmd/skopeo/inspect.go b/cmd/skopeo/inspect.go index 6b8f897b..de00c6a6 100644 --- a/cmd/skopeo/inspect.go +++ b/cmd/skopeo/inspect.go @@ -7,6 +7,7 @@ import ( "github.com/containers/image/docker" "github.com/containers/image/manifest" + "github.com/docker/distribution/digest" "github.com/urfave/cli" ) @@ -14,7 +15,7 @@ import ( type inspectOutput struct { Name string `json:",omitempty"` Tag string `json:",omitempty"` - Digest string + Digest digest.Digest RepoTags []string Created time.Time DockerVersion string diff --git a/cmd/skopeo/layers.go b/cmd/skopeo/layers.go index 5728f0cc..7d01475a 100644 --- a/cmd/skopeo/layers.go +++ b/cmd/skopeo/layers.go @@ -11,6 +11,7 @@ import ( "github.com/containers/image/image" "github.com/containers/image/manifest" "github.com/containers/image/types" + "github.com/docker/distribution/digest" "github.com/urfave/cli" ) @@ -39,10 +40,21 @@ var layersCmd = cli.Command{ } defer src.Close() - blobDigests := c.Args().Tail() + var blobDigests []digest.Digest + for _, dString := range c.Args().Tail() { + if !strings.HasPrefix(dString, "sha256:") { + dString = "sha256:" + dString + } + d, err := digest.ParseDigest(dString) + if err != nil { + return err + } + blobDigests = append(blobDigests, d) + } + if len(blobDigests) == 0 { layers := src.LayerInfos() - seenLayers := map[string]struct{}{} + seenLayers := map[digest.Digest]struct{}{} for _, info := range layers { if _, ok := seenLayers[info.Digest]; !ok { blobDigests = append(blobDigests, info.Digest) @@ -70,9 +82,6 @@ var layersCmd = cli.Command{ defer dest.Close() for _, digest := range blobDigests { - if !strings.HasPrefix(digest, "sha256:") { - digest = "sha256:" + digest - } r, blobSize, err := rawSource.GetBlob(digest) if err != nil { return err diff --git a/cmd/skopeo/manifest_test.go b/cmd/skopeo/manifest_test.go index eab9f386..a28273b5 100644 --- a/cmd/skopeo/manifest_test.go +++ b/cmd/skopeo/manifest_test.go @@ -27,5 +27,5 @@ func TestManifestDigest(t *testing.T) { // Success out, err = runSkopeo("manifest-digest", "fixtures/image.manifest.json") assert.NoError(t, err) - assert.Equal(t, fixturesTestImageManifestDigest+"\n", out) + assert.Equal(t, fixturesTestImageManifestDigest.String()+"\n", out) } diff --git a/cmd/skopeo/signing_test.go b/cmd/skopeo/signing_test.go index 9662f23e..ea6bd6c6 100644 --- a/cmd/skopeo/signing_test.go +++ b/cmd/skopeo/signing_test.go @@ -6,13 +6,14 @@ import ( "testing" "github.com/containers/image/signature" + "github.com/docker/distribution/digest" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) const ( // fixturesTestImageManifestDigest is the Docker manifest digest of "image.manifest.json" - fixturesTestImageManifestDigest = "sha256:20bf21ed457b390829cdbeec8795a7bea1626991fda603e0d01b4e7f60427e55" + fixturesTestImageManifestDigest = digest.Digest("sha256:20bf21ed457b390829cdbeec8795a7bea1626991fda603e0d01b4e7f60427e55") // fixturesTestKeyFingerprint is the fingerprint of the private key. fixturesTestKeyFingerprint = "1D8230F6CDB6A06716E414C1DB72F2188BB46CC8" ) @@ -122,5 +123,5 @@ func TestStandaloneVerify(t *testing.T) { out, err = runSkopeo("standalone-verify", manifestPath, dockerReference, fixturesTestKeyFingerprint, signaturePath) assert.NoError(t, err) - assert.Equal(t, "Signature verified, digest "+fixturesTestImageManifestDigest+"\n", out) + assert.Equal(t, "Signature verified, digest "+fixturesTestImageManifestDigest.String()+"\n", out) } diff --git a/integration/copy_test.go b/integration/copy_test.go index f0e0b39c..bbb303d9 100644 --- a/integration/copy_test.go +++ b/integration/copy_test.go @@ -11,6 +11,7 @@ import ( "strings" "github.com/containers/image/manifest" + "github.com/docker/distribution/digest" "github.com/go-check/check" ) @@ -167,7 +168,7 @@ func (s *CopySuite) TestCopyStreaming(c *check.C) { assertSkopeoSucceeds(c, "", "--tls-verify=false", "copy", "atomic:localhost:5000/myns/unsigned:streaming", "dir:"+dir2) // The manifests will have different JWS signatures; so, compare the manifests by digests, which // strips the signatures, and remove them, comparing the rest file by file. - digests := []string{} + digests := []digest.Digest{} for _, dir := range []string{dir1, dir2} { manifestPath := filepath.Join(dir, "manifest.json") m, err := ioutil.ReadFile(manifestPath)