Documentation ¶
Overview ¶
Package datautil provides utilities for randomness, encode/decode, etc.
Index ¶
- func Crc32ChecksumBytes(s string) []byte
- func DecodeBase62(s string, length int, invertAlphabet bool) ([]byte, bool)
- func EncodeBase62(bytes []byte, invertAlphabet bool) string
- func GenerateCrc32Uint32(s string) uint32
- func GenerateSecureRandomBytes(length int) []byte
- func SelectInsecureRandomInt(vals ...int) int
- func SelectInsecureRandomStr(vals ...string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Crc32ChecksumBytes ¶
Crc32ChecksumBytes calculates a CRC32 checksum of the given string, returning the bytes of the checksum.
func DecodeBase62 ¶
DecodeBase62 decodes a base62 encoded string, returning a byte slice of the given length; if the given length is < 1, the length of the returned byte is not guaranteed; if the given length is >= 1, the length of the returned byte slice will be of the given length; if the data cannot fit in a byte of the given length, a zeroed byte slice of the given length and false will be returned; if a decoding error is encountered, a nil byte slice and false will be returned; for toggling letter case of input string if producer's alphabet is different than Golang's big.Int alphabet; this is the dumb way of switching between 0-9,a-z,A-Z and 0-9,A-Z,a-z alphabets.
func EncodeBase62 ¶
EncodeBase62 encodes bytes into a base62 encoded string, returning the encoded string; allows for toggling letter case of output string if consumer's alphabet is different than Golang's big.Int alphabet; this is the dumb way of switching between 0-9,a-z,A-Z and 0-9,A-Z,a-z alphabets.
func GenerateCrc32Uint32 ¶
GenerateCrc32Uint32 calculates a CRC32 checksum of the given string, returning the checksum as uint32.
func GenerateSecureRandomBytes ¶
GenerateSecureRandomBytes returns a byte slice of the given length w/ cryptographically secure random data; if an error is encountered while attempting to generate secure random data (resulting in a partially filled buffter), then the rest of the buffer is filled with insecurely generated random data.
func SelectInsecureRandomInt ¶
SelectInsecureRandomInt selects a random value from the given arguments using insecure randomness. Returns 0 if no arguments are given.
func SelectInsecureRandomStr ¶
SelectInsecureRandomStr selects a random value from the given arguments using insecure randomness. Returns empty string if no arguments are given.
Types ¶
This section is empty.