zrok/controller/identity.go

24 lines
532 B
Go
Raw Normal View History

2022-07-25 19:17:52 +02:00
package controller
import (
"crypto/rand"
"encoding/hex"
"github.com/pkg/errors"
)
func generateApiToken() (string, error) {
bytes := make([]byte, 64)
if _, err := rand.Read(bytes); err != nil {
return "", errors.Wrap(err, "error generating random api token")
}
return hex.EncodeToString(bytes), nil
}
2022-07-26 22:21:49 +02:00
func randomId() (string, error) {
bytes := make([]byte, 8)
if _, err := rand.Read(bytes); err != nil {
return "", errors.Wrap(err, "error generating random identity id")
}
return hex.EncodeToString(bytes), nil
}