Skip to content

Commit

Permalink
use math/rand/v2 package to generate uuids
Browse files Browse the repository at this point in the history
Signed-off-by: Tariq Ibrahim <[email protected]>
  • Loading branch information
tariq1890 committed Oct 17, 2024
1 parent f11cc01 commit 10471a0
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions internal/lm/fabric.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ package lm

import (
"bufio"
"crypto/sha256"
"fmt"
"io"
"math/rand" // nolint:gosec
"math/rand/v2"
"net"
"os"
"sort"
Expand Down Expand Up @@ -142,18 +143,13 @@ func getImexDomainID(r io.Reader) (string, error) {
}

func generateContentUUID(seed string) string {
// nolint:gosec
rand := rand.New(rand.NewSource(hash(seed)))
r := rand.NewChaCha8(hash(seed))
charset := make([]byte, 16)
rand.Read(charset)
uuid, _ := uuid.FromBytes(charset)
return uuid.String()
r.Read(charset)

Check failure on line 148 in internal/lm/fabric.go

View workflow job for this annotation

GitHub Actions / check

Error return value of `r.Read` is not checked (errcheck)
u, _ := uuid.FromBytes(charset)
return u.String()
}

func hash(s string) int64 {
h := int64(0)
for _, c := range s {
h = 31*h + int64(c)
}
return h
func hash(s string) [32]byte {
return sha256.Sum256([]byte(s))
}

0 comments on commit 10471a0

Please sign in to comment.