ratio-spoof/internal/generator/key.go
2021-03-12 23:15:18 -03:00

27 lines
493 B
Go

package generator
import (
"crypto/rand"
"encoding/hex"
"strings"
)
type KeyGenerator interface {
Key() string
}
func NewKeyGenerator(generatorCode string) (KeyGenerator, error) {
randomBytes := make([]byte, 4)
rand.Read(randomBytes)
str := hex.EncodeToString(randomBytes)
result := strings.ToUpper(str)
return &DefaultKeyGenerator{generated: result}, nil
}
type DefaultKeyGenerator struct {
generated string
}
func (d *DefaultKeyGenerator) Key() string {
return d.generated
}