Skip to content

Commit 84a4c09

Browse files
committed
fix: Standarize/disambiguate return from Parse
1 parent bde1400 commit 84a4c09

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

digest.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ var (
8080
// be returned if the format is invalid.
8181
func Parse(s string) (Digest, error) {
8282
d := Digest(s)
83-
return d, d.Validate()
83+
if err := d.Validate(); err != nil {
84+
return "", err
85+
}
86+
return d, nil
8487
}
8588

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

140-
// Hex is deprecated. Please use Digest.Encoded.
143+
// Deprecated: Hex has been deprecated in favor of Digest.Encoded
141144
func (d Digest) Hex() string {
142145
return d.Encoded()
143146
}

digestset/set.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,17 @@ func (dst *Set) Lookup(d string) (digest.Digest, error) {
9191
searchFunc func(int) bool
9292
alg digest.Algorithm
9393
hex string
94+
dgst digest.Digest
9495
)
95-
dgst, err := digest.Parse(d)
96-
if err == digest.ErrDigestInvalidFormat {
96+
97+
dgst = digest.Digest(d)
98+
if err := dgst.Validate(); err == digest.ErrDigestInvalidFormat {
9799
hex = d
98100
searchFunc = func(i int) bool {
99101
return dst.entries[i].val >= d
100102
}
101-
} else {
102-
hex = dgst.Hex()
103+
} else { // Note: `err` is not necessarily `nil` here
104+
hex = dgst.Encoded()
103105
alg = dgst.Algorithm()
104106
searchFunc = func(i int) bool {
105107
if dst.entries[i].val == hex {

0 commit comments

Comments
 (0)