Add RandomHexString for unguessable identifiers and tokens #13
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Session tokens, temporary filenames and request identifiers all need a random
string, and the version people reach for first tends to use
math/rand, whichis predictable and unsafe for anything a stranger should not be able to guess.
A single obvious function that reads from the system random source makes the
safe choice the default one.
Definition of done:
RandomHexString(byteLength int) (string, error)returnsbyteLength random bytes from
crypto/randwritten as lowercase hexadecimal, sothe string is twice as long as byteLength, and returns an error for a negative
length or if the random source fails. It has a doc comment and table-driven
tests covering the length of the result for several sizes, a length of zero, a
negative length, and that two calls do not return the same string.
Model: opus-5