mirror of
https://github.com/NotAShelf/watchdog.git
synced 2026-04-19 00:20:05 +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"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -71,8 +72,13 @@ func generateSalt(t time.Time, rotation string) string {
|
||||||
|
|
||||||
// Creates a privacy-preserving hash of visitor identity
|
// Creates a privacy-preserving hash of visitor identity
|
||||||
func hashVisitor(ip, userAgent, salt string) string {
|
func hashVisitor(ip, userAgent, salt string) string {
|
||||||
combined := ip + "|" + userAgent + "|" + salt
|
var sb strings.Builder
|
||||||
h := sha256.Sum256([]byte(combined))
|
sb.WriteString(ip)
|
||||||
|
sb.WriteString("|")
|
||||||
|
sb.WriteString(userAgent)
|
||||||
|
sb.WriteString("|")
|
||||||
|
sb.WriteString(salt)
|
||||||
|
h := sha256.Sum256([]byte(sb.String()))
|
||||||
return hex.EncodeToString(h[:])
|
return hex.EncodeToString(h[:])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue