-
-
Notifications
You must be signed in to change notification settings - Fork 6
π‘οΈ Sentinel: [MEDIUM] Add VerifyHMACSha256 for secure HMAC verification #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -326,3 +326,25 @@ func HMACSha256(key []byte, data io.Reader) ([]byte, error) { | |||||
|
|
||||||
| return h.Sum(nil), nil | ||||||
| } | ||||||
|
|
||||||
| // VerifyHMACSha256 verify HMAC by sha256 | ||||||
| // | ||||||
| // # Args: | ||||||
| // - key: secure key, no limit on length | ||||||
| // - data: raw data to verify HMAC | ||||||
| // - signature: HMAC signature to verify | ||||||
| // | ||||||
| // # Returns: | ||||||
| // - err: nil if signature match | ||||||
| func VerifyHMACSha256(key, signature []byte, data io.Reader) error { | ||||||
| h, err := HMACSha256(key, data) | ||||||
| if err != nil { | ||||||
| return errors.Wrap(err, "calculate hmac") | ||||||
| } | ||||||
|
|
||||||
| if !hmac.Equal(h, signature) { | ||||||
| return errors.New("signature not match") | ||||||
|
Comment on lines
+345
to
+346
|
||||||
| return errors.New("signature not match") | |
| return errors.New("hmac not match") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The doc comment for VerifyHMACSha256 lists args in the order
key,data,signature, but the function signature isfunc VerifyHMACSha256(key, signature []byte, data io.Reader). Please update the comment (or reorder parameters) so the documented argument order matches the actual API and avoids misuse by callers.