Skip to content

Commit

Permalink
Merge pull request opencontainers#696 from wking/go-digest-unsupported
Browse files Browse the repository at this point in the history
schema/validator: Punt sha256/sha512 hex-validation to go-digest
  • Loading branch information
vbatts authored Jun 16, 2017
2 parents df6f3c5 + fa09f5b commit d207df4
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions schema/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"fmt"
"io"
"io/ioutil"
"regexp"

digest "github.com/opencontainers/go-digest"
"github.com/opencontainers/image-spec/specs-go/v1"
Expand Down Expand Up @@ -125,11 +124,6 @@ func validateManifest(r io.Reader) error {
return nil
}

var (
sha256EncodedRegexp = regexp.MustCompile(`^[a-f0-9]{64}$`)
sha512EncodedRegexp = regexp.MustCompile(`^[a-f0-9]{128}$`)
)

func validateDescriptor(r io.Reader) error {
header := v1.Descriptor{}

Expand All @@ -143,22 +137,13 @@ func validateDescriptor(r io.Reader) error {
return errors.Wrap(err, "descriptor format mismatch")
}

if header.Digest.Validate() != nil {
err = header.Digest.Validate()
if err == digest.ErrDigestUnsupported {
// we ignore unsupported algorithms
fmt.Printf("warning: unsupported digest: %q: %v\n", header.Digest, err)
return nil
}
switch header.Digest.Algorithm() {
case digest.SHA256:
if !sha256EncodedRegexp.MatchString(header.Digest.Hex()) {
return errors.Errorf("unexpected sha256 digest: %q", header.Digest)
}
case digest.SHA512:
if !sha512EncodedRegexp.MatchString(header.Digest.Hex()) {
return errors.Errorf("unexpected sha512 digest: %q", header.Digest)
}
}
return nil
return err
}

func validateIndex(r io.Reader) error {
Expand Down

0 comments on commit d207df4

Please sign in to comment.