Commit 2ef1c0c

mo khan <mo@mokhan.ca>
2025-05-06 20:15:11
refactor: inline usage of GenerateHMAC function
1 parent e77ddb1
Changed files (2)
pkg/cookie/option_test.go
@@ -2,6 +2,7 @@ package cookie
 
 import (
 	"crypto/hmac"
+	"crypto/sha256"
 	"fmt"
 	"net/http"
 	"testing"
@@ -10,7 +11,6 @@ import (
 	"github.com/stretchr/testify/assert"
 	"github.com/stretchr/testify/require"
 	"github.com/xlgmokha/x/pkg/crypt"
-	"github.com/xlgmokha/x/pkg/pls"
 )
 
 func TestOption(t *testing.T) {
@@ -66,7 +66,10 @@ func TestOption(t *testing.T) {
 		assert.NotEqual(t, "1", cookie.Value)
 		assert.NotEmpty(t, cookie.Value)
 
-		signature := pls.GenerateHMAC256([]byte(secret), []byte(value))
+		mac := hmac.New(sha256.New, []byte(secret))
+		mac.Write([]byte(value))
+		signature := mac.Sum(nil)
+
 		expected := fmt.Sprintf("%v--%v", value, string(signature))
 
 		assert.Equal(t, expected, cookie.Value)
pkg/pls/hmac.go
@@ -1,12 +0,0 @@
-package pls
-
-import (
-	"crypto/hmac"
-	"crypto/sha256"
-)
-
-func GenerateHMAC256(key, value []byte) []byte {
-	mac := hmac.New(sha256.New, key)
-	mac.Write(value)
-	return mac.Sum(nil)
-}