Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions digest.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ var (
// be returned if the format is invalid.
func Parse(s string) (Digest, error) {
d := Digest(s)
return d, d.Validate()
if err := d.Validate(); err != nil {
return "", err
}
return d, nil
}

// FromReader consumes the content of rd until io.EOF, returning canonical digest.
Expand Down Expand Up @@ -137,7 +140,7 @@ func (d Digest) Encoded() string {
return string(d[d.sepIndex()+1:])
}

// Hex is deprecated. Please use Digest.Encoded.
// Deprecated: Hex has been deprecated in favor of Digest.Encoded
func (d Digest) Hex() string {
return d.Encoded()
}
Expand Down
10 changes: 6 additions & 4 deletions digestset/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,17 @@ func (dst *Set) Lookup(d string) (digest.Digest, error) {
searchFunc func(int) bool
alg digest.Algorithm
hex string
dgst digest.Digest
)
dgst, err := digest.Parse(d)
if err == digest.ErrDigestInvalidFormat {

dgst = digest.Digest(d)
if err := dgst.Validate(); err == digest.ErrDigestInvalidFormat {
hex = d
searchFunc = func(i int) bool {
return dst.entries[i].val >= d
}
} else {
hex = dgst.Hex()
} else { // Note: `err` is not necessarily `nil` here
hex = dgst.Encoded()
alg = dgst.Algorithm()
searchFunc = func(i int) bool {
if dst.entries[i].val == hex {
Expand Down