diff --git a/lhash/algs.go b/lhash/algs.go index 635555d..e4a15cc 100644 --- a/lhash/algs.go +++ b/lhash/algs.go @@ -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. func (a Algorithm) Digest(data []byte) *LabeledHash { return Digest(a, data) diff --git a/lhash/labeledhash.go b/lhash/labeledhash.go index 58951cd..d0674b1 100644 --- a/lhash/labeledhash.go +++ b/lhash/labeledhash.go @@ -168,6 +168,13 @@ func (lh *LabeledHash) Equal(other *LabeledHash) bool { 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. func (lh *LabeledHash) MatchesString(s string) bool { return lh.MatchesData([]byte(s))