Skip to content

Commit

Permalink
refactor: Removing math/rand for generating uuid
Browse files Browse the repository at this point in the history
  • Loading branch information
ViBiOh committed Feb 12, 2021
1 parent 8b5ce9b commit 513556d
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions pkg/ketchup/token.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package ketchup

import (
"crypto/rand"
"fmt"
"math/rand"
"sync"
"time"

"github.com/ViBiOh/httputils/v3/pkg/logger"
)

// TokenStore stores single usage token
Expand All @@ -16,15 +18,12 @@ type TokenStore interface {
}

type tokenStore struct {
rand *rand.Rand
store sync.Map
}

// NewTokenStore creates a new token store
func NewTokenStore() TokenStore {
return &tokenStore{
rand: rand.New(rand.NewSource(time.Now().UnixNano())),
}
return &tokenStore{}
}

type mapValue struct {
Expand Down Expand Up @@ -79,7 +78,10 @@ func (t *tokenStore) Clean(_ time.Time) error {

func (t *tokenStore) uuid() string {
raw := make([]byte, 16)
t.rand.Read(raw)
if _, err := rand.Read(raw); err != nil {
logger.Fatal(err)
return ""
}

raw[8] = raw[8]&^0xc0 | 0x80
raw[6] = raw[6]&^0xf0 | 0x40
Expand Down

0 comments on commit 513556d

Please sign in to comment.