Skip to content

Commit aa96125

Browse files
committed
feat: Add two abstraction helper methods
These methods are `IsIdenticalTo` and `IsEmpty`.
1 parent bde1400 commit aa96125

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

digest.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
//
3131
// The following is an example of the contents of Digest types:
3232
//
33-
// sha256:7173b809ca12ec5dee4506cd86be934c4596dd234ee82c0662eac04a8c2c71dc
33+
// sha256:7173b809ca12ec5dee4506cd86be934c4596dd234ee82c0662eac04a8c2c71dc
3434
//
3535
// This allows to abstract the digest behind this type and work only in those
3636
// terms.
@@ -146,6 +146,16 @@ func (d Digest) String() string {
146146
return string(d)
147147
}
148148

149+
// IsIdenticalTo compares this digest to any other, inclusive of the hashing algorithm used
150+
func (d Digest) IsIdenticalTo(o Digest) bool {
151+
return string(d) == string(o)
152+
}
153+
154+
// IsEmpty does what it says (an empty digest is an empty string)
155+
func (d Digest) IsEmpty() bool {
156+
return len(d) == 0
157+
}
158+
149159
func (d Digest) sepIndex() int {
150160
i := strings.Index(string(d), ":")
151161

0 commit comments

Comments
 (0)