Skip to content

Commit

Permalink
fix!: string
Browse files Browse the repository at this point in the history
  • Loading branch information
brokeyourbike committed Feb 18, 2024
1 parent a37f18d commit 9b499e5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions webhook/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

type Verifier interface {
Verify(ctx context.Context, message []byte, signature string) error
Verify(ctx context.Context, message, signature string) error
}

type verifier struct {
Expand All @@ -19,11 +19,11 @@ func NewVerifier(secrets []string) *verifier {
return &verifier{secrets: secrets}
}

func (v *verifier) Verify(ctx context.Context, message []byte, signature string) error {
func (v *verifier) Verify(ctx context.Context, message, signature string) error {
var pass bool
for _, secret := range v.secrets {
digest := hmac.New(sha256.New, []byte(secret))
digest.Write(message)
digest.Write([]byte(message))
computed := fmt.Sprintf("%x", digest.Sum(nil))

if computed == signature {
Expand Down
2 changes: 1 addition & 1 deletion webhook/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ func TestVerifier(t *testing.T) {
signature := "0dcab73ddd20062616d104231c7439657546a5c24e4691977da93bb854c31e25"

v := webhook.NewVerifier([]string{"abc", "abcdef12-abcd-abcd-abcd-abcdef012345", "cde"})
assert.NoError(t, v.Verify(context.Background(), []byte(message), signature))
assert.NoError(t, v.Verify(context.Background(), message, signature))
}

0 comments on commit 9b499e5

Please sign in to comment.