77 "crypto/rand"
88 "crypto/sha256"
99 "errors"
10- "fmt"
1110 "io"
1211
1312 "github.com/carry0987/FileTree-API/internal/utils"
@@ -57,11 +56,11 @@ func Decrypt(encryptedMessage string) (string, error) {
5756}
5857
5958// Compare the HMAC created from the message and salt with the one provided by the client
60- func VerifySignatures (signature , encryptedPath string ) bool {
59+ func VerifySignature (signature , encryptedPath string ) bool {
6160 // Decode the signature to get the HMAC
62- signatureDecoded , err := utils .Base64UrlDecode (signature )
61+ decodedSignature , err := utils .Base64UrlDecode (signature )
6362 if err != nil {
64- utils .OutputMessage (nil , utils .LogOutput , 0 , "Invalid: %v" , signature )
63+ utils .OutputMessage (nil , utils .LogOutput , 0 , "Invalid signature : %v\n " , signature )
6564 return false
6665 }
6766
@@ -72,21 +71,6 @@ func VerifySignatures(signature, encryptedPath string) bool {
7271 expectedMAC := mac .Sum (nil )
7372
7473 // Compare the client's HMAC with the expected HMAC
75- return hmac .Equal (signatureDecoded , expectedMAC )
76- }
77-
78- func VerifySignature (signature , encryptedPath string ) bool {
79- decodedSignature , err := utils .Base64UrlDecode (signature )
80- if err != nil {
81- fmt .Printf ("Invalid signature decode error: %v\n " , err )
82- return false
83- }
84-
85- mac := hmac .New (sha256 .New , key )
86- mac .Write (salt )
87- mac .Write ([]byte (encryptedPath ))
88- expectedMAC := mac .Sum (nil )
89-
9074 return hmac .Equal (decodedSignature , expectedMAC )
9175}
9276
0 commit comments