aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/google/go-containerregistry/pkg/name/digest.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2022-09-09 15:08:46 +0200
committerGitHub <noreply@github.com>2022-09-09 15:08:46 +0200
commit04270a080d4a06e671da9d2d7e6e15f6108338d9 (patch)
tree49116c6281fc4ab6cfac6bb5c9fb9600cdcd4573 /vendor/github.com/google/go-containerregistry/pkg/name/digest.go
parent8a2ab7c387928782d8a1893c99974638054a0ad0 (diff)
parent8e1aa7af3a3d4fac1aefa94ed4a4455ac190ead9 (diff)
downloadpodman-04270a080d4a06e671da9d2d7e6e15f6108338d9.tar.gz
podman-04270a080d4a06e671da9d2d7e6e15f6108338d9.tar.bz2
podman-04270a080d4a06e671da9d2d7e6e15f6108338d9.zip
Merge pull request #15695 from Luap99/update-buildah
Update buildah and c/common to latest
Diffstat (limited to 'vendor/github.com/google/go-containerregistry/pkg/name/digest.go')
-rw-r--r--vendor/github.com/google/go-containerregistry/pkg/name/digest.go27
1 files changed, 12 insertions, 15 deletions
diff --git a/vendor/github.com/google/go-containerregistry/pkg/name/digest.go b/vendor/github.com/google/go-containerregistry/pkg/name/digest.go
index e465aef49..c4a2e693e 100644
--- a/vendor/github.com/google/go-containerregistry/pkg/name/digest.go
+++ b/vendor/github.com/google/go-containerregistry/pkg/name/digest.go
@@ -15,16 +15,14 @@
package name
import (
+ _ "crypto/sha256" // Recommended by go-digest.
"strings"
-)
-const (
- // These have the form: sha256:<hex string>
- // TODO(dekkagaijin): replace with opencontainers/go-digest or docker/distribution's validation.
- digestChars = "sh:0123456789abcdef"
- digestDelim = "@"
+ "github.com/opencontainers/go-digest"
)
+const digestDelim = "@"
+
// Digest stores a digest name in a structured form.
type Digest struct {
Repository
@@ -60,10 +58,6 @@ func (d Digest) String() string {
return d.original
}
-func checkDigest(name string) error {
- return checkElement("digest", name, digestChars, 7+64, 7+64)
-}
-
// NewDigest returns a new Digest representing the given name.
func NewDigest(name string, opts ...Option) (Digest, error) {
// Split on "@"
@@ -72,10 +66,13 @@ func NewDigest(name string, opts ...Option) (Digest, error) {
return Digest{}, newErrBadName("a digest must contain exactly one '@' separator (e.g. registry/repository@digest) saw: %s", name)
}
base := parts[0]
- digest := parts[1]
-
- // Always check that the digest is valid.
- if err := checkDigest(digest); err != nil {
+ dig := parts[1]
+ prefix := digest.Canonical.String() + ":"
+ if !strings.HasPrefix(dig, prefix) {
+ return Digest{}, newErrBadName("unsupported digest algorithm: %s", dig)
+ }
+ hex := strings.TrimPrefix(dig, prefix)
+ if err := digest.Canonical.Validate(hex); err != nil {
return Digest{}, err
}
@@ -90,7 +87,7 @@ func NewDigest(name string, opts ...Option) (Digest, error) {
}
return Digest{
Repository: repo,
- digest: digest,
+ digest: dig,
original: name,
}, nil
}