StoreBackEnd/pkg/utils/crypto/CryptoSource.go

30 lines
501 B
Go
Raw Permalink Normal View History

package crypto
import (
"crypto/rand"
"encoding/binary"
"log"
)
// Source : https://programming.guide/go/crypto-rand-int.html
type CryptoSource struct{}
func NewCryptoSource() *CryptoSource {
return &CryptoSource{}
}
func (s CryptoSource) Int63() int64 {
return int64(s.Uint64() & ^uint64(1<<63))
}
func (s CryptoSource) Seed(seed int64) {}
func (s CryptoSource) Uint64() (v uint64) {
err := binary.Read(rand.Reader, binary.BigEndian, &v)
if err != nil {
log.Fatal(err)
}
return v
}