mirror of
https://github.com/NotAShelf/watchdog.git
synced 2026-04-15 06:44:20 +00:00
aggreggate/uniques: use string builder for hashing
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I7371a878c05f704feef26c6e86a04b956a6a6964
This commit is contained in:
parent
0f38a062e9
commit
d2f28ded61
1 changed files with 8 additions and 2 deletions
|
|
@ -6,6 +6,7 @@ import (
|
|||
"encoding/hex"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
|
|
@ -71,8 +72,13 @@ func generateSalt(t time.Time, rotation string) string {
|
|||
|
||||
// Creates a privacy-preserving hash of visitor identity
|
||||
func hashVisitor(ip, userAgent, salt string) string {
|
||||
combined := ip + "|" + userAgent + "|" + salt
|
||||
h := sha256.Sum256([]byte(combined))
|
||||
var sb strings.Builder
|
||||
sb.WriteString(ip)
|
||||
sb.WriteString("|")
|
||||
sb.WriteString(userAgent)
|
||||
sb.WriteString("|")
|
||||
sb.WriteString(salt)
|
||||
h := sha256.Sum256([]byte(sb.String()))
|
||||
return hex.EncodeToString(h[:])
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue