NewRandom generates a securely random token.
(t Type)
| 48 | |
| 49 | // NewRandom generates a securely random token. |
| 50 | func NewRandom(t Type) *Token { |
| 51 | tkn := Token{ |
| 52 | Type: t, |
| 53 | ID: uuid.New(), |
| 54 | } |
| 55 | |
| 56 | if _, err := rand.Read(tkn.Secret[:]); err != nil { |
| 57 | panic(err) |
| 58 | } |
| 59 | |
| 60 | return &tkn |
| 61 | } |
| 62 | |
| 63 | // FromString re-creates a token from it's string representation (acquired by calling String()). |
| 64 | // The things I do for pretty tokens. |
no outgoing calls