7
7
"crypto/rand"
8
8
"crypto/sha256"
9
9
"errors"
10
- "fmt"
11
10
"io"
12
11
13
12
"github.com/carry0987/FileTree-API/internal/utils"
@@ -57,11 +56,11 @@ func Decrypt(encryptedMessage string) (string, error) {
57
56
}
58
57
59
58
// 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 {
61
60
// Decode the signature to get the HMAC
62
- signatureDecoded , err := utils .Base64UrlDecode (signature )
61
+ decodedSignature , err := utils .Base64UrlDecode (signature )
63
62
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 )
65
64
return false
66
65
}
67
66
@@ -72,21 +71,6 @@ func VerifySignatures(signature, encryptedPath string) bool {
72
71
expectedMAC := mac .Sum (nil )
73
72
74
73
// 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
-
90
74
return hmac .Equal (decodedSignature , expectedMAC )
91
75
}
92
76
0 commit comments