datautil

package
v0.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 4, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package datautil provides utilities for randomness, encode/decode, etc.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Crc32ChecksumBytes

func Crc32ChecksumBytes(s string) []byte

Crc32ChecksumBytes calculates a CRC32 checksum of the given string, returning the bytes of the checksum.

func DecodeBase62

func DecodeBase62(s string, length int, invertAlphabet bool) ([]byte, bool)

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

func EncodeBase62(bytes []byte, invertAlphabet bool) string

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

func GenerateCrc32Uint32(s string) uint32

GenerateCrc32Uint32 calculates a CRC32 checksum of the given string, returning the checksum as uint32.

func GenerateSecureRandomBytes

func GenerateSecureRandomBytes(length int) []byte

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

func SelectInsecureRandomInt(vals ...int) int

SelectInsecureRandomInt selects a random value from the given arguments using insecure randomness. Returns 0 if no arguments are given.

func SelectInsecureRandomStr

func SelectInsecureRandomStr(vals ...string) string

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL