Expose raw hasher and add raw hash equality function
This commit is contained in:
parent
12f5da337c
commit
7566eefcd7
2 changed files with 12 additions and 0 deletions
|
@ -127,6 +127,11 @@ func (a Algorithm) String() string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RawHasher returns a new raw hasher of the algorithm.
|
||||||
|
func (a Algorithm) RawHasher() hash.Hash {
|
||||||
|
return a.new()
|
||||||
|
}
|
||||||
|
|
||||||
// Digest creates a new labeled hash and digests the given data.
|
// Digest creates a new labeled hash and digests the given data.
|
||||||
func (a Algorithm) Digest(data []byte) *LabeledHash {
|
func (a Algorithm) Digest(data []byte) *LabeledHash {
|
||||||
return Digest(a, data)
|
return Digest(a, data)
|
||||||
|
|
|
@ -168,6 +168,13 @@ func (lh *LabeledHash) Equal(other *LabeledHash) bool {
|
||||||
subtle.ConstantTimeCompare(lh.digest, other.digest) == 1
|
subtle.ConstantTimeCompare(lh.digest, other.digest) == 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EqualRaw returns true if the given raw hash digest is equal.
|
||||||
|
// Equality is checked by comparing both the digest value only.
|
||||||
|
// The caller must make sure the same algorithm is used.
|
||||||
|
func (lh *LabeledHash) EqualRaw(otherDigest []byte) bool {
|
||||||
|
return subtle.ConstantTimeCompare(lh.digest, otherDigest) == 1
|
||||||
|
}
|
||||||
|
|
||||||
// MatchesString returns true if the digest of the given string matches the hash.
|
// MatchesString returns true if the digest of the given string matches the hash.
|
||||||
func (lh *LabeledHash) MatchesString(s string) bool {
|
func (lh *LabeledHash) MatchesString(s string) bool {
|
||||||
return lh.MatchesData([]byte(s))
|
return lh.MatchesData([]byte(s))
|
||||||
|
|
Loading…
Add table
Reference in a new issue