digest: better test coverage

Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
Stephen J Day 2016-12-15 17:21:57 -08:00
parent 6a74c94bf8
commit ecb2ee3824
No known key found for this signature in database
GPG key ID: FB5F6B2905D7ECF3
4 changed files with 116 additions and 11 deletions

View file

@ -94,17 +94,10 @@ func FromString(s string) Digest {
func (d Digest) Validate() error {
s := string(d)
if !DigestRegexpAnchored.MatchString(s) {
return ErrDigestInvalidFormat
}
i := strings.Index(s, ":")
if i < 0 {
return ErrDigestInvalidFormat
}
// case: "sha256:" with no hex.
if i+1 == len(s) {
// validate i then run through regexp
if i < 0 || i+1 == len(s) || !DigestRegexpAnchored.MatchString(s) {
return ErrDigestInvalidFormat
}