1
0
mirror of https://github.com/golang/go synced 2024-11-12 08:50:22 -07:00

crypto/hmac: change checkhmac to validhmac

Procedure names should reflect what they do; function names
should reflect what they return. Functions are used in
expressions, often in things like if's, so they need
to read appropriately.

        if CheckHMAC(a,b, key)

is unhelpful because we can't deduce whether CheckHMAC
returns true on error or non­error;instead

        if ValidHMAC(x)

https://www.lysator.liu.se/c/pikestyle.html

makes the point clear and makes a future mistake in using the routine less likely.
This commit is contained in:
sevki 2018-11-16 00:37:12 +00:00
parent 14608976db
commit 32199a418b

View File

@ -11,8 +11,8 @@ The receiver verifies the hash by recomputing it using the same key.
Receivers should be careful to use Equal to compare MACs in order to avoid
timing side-channels:
// CheckMAC reports whether messageMAC is a valid HMAC tag for message.
func CheckMAC(message, messageMAC, key []byte) bool {
// ValidMAC reports whether messageMAC is a valid HMAC tag for message.
func ValidMAC(message, messageMAC, key []byte) bool {
mac := hmac.New(sha256.New, key)
mac.Write(message)
expectedMAC := mac.Sum(nil)