Skip to content

Commit

Permalink
fix deprecation of NewDigestFromHex and Digest.Hex
Browse files Browse the repository at this point in the history
Both of these were deprecated in 55f6758, but
the format of the GoDoc comments didn't follow the correct format, which causes
them not being picked up by tools as "deprecated".

This patch:

- Fixes the comments to be in the right format.
- Updates uses in the codebase to use the alternatives.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
  • Loading branch information
thaJeztah committed Nov 8, 2022
1 parent 718acf6 commit 50500bc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 7 additions & 2 deletions digest.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ func NewDigestFromBytes(alg Algorithm, p []byte) Digest {
return NewDigestFromEncoded(alg, alg.Encode(p))
}

// NewDigestFromHex is deprecated. Please use NewDigestFromEncoded.
// NewDigestFromHex returns a Digest from alg and the hex encoded digest.
//
// Deprecated: use [NewDigestFromEncoded] instead.
func NewDigestFromHex(alg, hex string) Digest {
return NewDigestFromEncoded(Algorithm(alg), hex)
}
Expand Down Expand Up @@ -137,7 +139,10 @@ func (d Digest) Encoded() string {
return string(d[d.sepIndex()+1:])
}

// Hex is deprecated. Please use Digest.Encoded.
// Hex returns the encoded portion of the digest. This will panic if the
// underlying digest is not in a valid format.
//
// Deprecated: [Digest.Encoded] instead.
func (d Digest) Hex() string {
return d.Encoded()
}
Expand Down
6 changes: 3 additions & 3 deletions digestset/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (dst *Set) Lookup(d string) (digest.Digest, error) {
return dst.entries[i].val >= d
}
} else {
hex = dgst.Hex()
hex = dgst.Encoded()
alg = dgst.Algorithm()
searchFunc = func(i int) bool {
if dst.entries[i].val == hex {
Expand Down Expand Up @@ -131,7 +131,7 @@ func (dst *Set) Add(d digest.Digest) error {
}
dst.mutex.Lock()
defer dst.mutex.Unlock()
entry := &digestEntry{alg: d.Algorithm(), val: d.Hex(), digest: d}
entry := &digestEntry{alg: d.Algorithm(), val: d.Encoded(), digest: d}
searchFunc := func(i int) bool {
if dst.entries[i].val == entry.val {
return dst.entries[i].alg >= entry.alg
Expand Down Expand Up @@ -162,7 +162,7 @@ func (dst *Set) Remove(d digest.Digest) error {
}
dst.mutex.Lock()
defer dst.mutex.Unlock()
entry := &digestEntry{alg: d.Algorithm(), val: d.Hex(), digest: d}
entry := &digestEntry{alg: d.Algorithm(), val: d.Encoded(), digest: d}
searchFunc := func(i int) bool {
if dst.entries[i].val == entry.val {
return dst.entries[i].alg >= entry.alg
Expand Down

0 comments on commit 50500bc

Please sign in to comment.