diff --git a/digest.go b/digest.go index 518b5e7..41239e7 100644 --- a/digest.go +++ b/digest.go @@ -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. @@ -137,11 +140,21 @@ func (d Digest) Encoded() string { return string(d[d.sepIndex()+1:]) } -// Hex is deprecated. Please use Digest.Encoded. +// IsIdenticalTo compares this digest to any other, inclusive of the hashing algorithm used +func (d Digest) IsIdenticalTo(o Digest) bool { + return string(d) == string(o) +} + +// Deprecated: Hex has been deprecated in favor of Digest.Encoded func (d Digest) Hex() string { return d.Encoded() } +// IsEmpty does what it says (an empty digest is an empty string) +func (d Digest) IsEmpty() bool { + return len(d.String()) == 0 +} + func (d Digest) String() string { return string(d) } diff --git a/digestset/set.go b/digestset/set.go index 71f2418..3e1cc9c 100644 --- a/digestset/set.go +++ b/digestset/set.go @@ -92,13 +92,14 @@ func (dst *Set) Lookup(d string) (digest.Digest, error) { alg digest.Algorithm hex string ) - dgst, err := digest.Parse(d) + _, err := digest.Parse(d) if err == digest.ErrDigestInvalidFormat { hex = d searchFunc = func(i int) bool { return dst.entries[i].val >= d } } else { + dgst := digest.Digest(d) hex = dgst.Hex() alg = dgst.Algorithm() searchFunc = func(i int) bool {