Documentation ¶
Overview ¶
Package crockford implements the Crockford base 32 encoding
Index ¶
- Constants
- Variables
- func Append(e *base32.Encoding, dst, src []byte) []byte
- func AppendMD5(e *base32.Encoding, dst, src []byte) []byte
- func AppendNormalized(dst, src []byte) []byte
- func AppendPartition(dst, src []byte, gap int) []byte
- func AppendRandom(e *base32.Encoding, dst []byte) []byte
- func AppendTime(e *base32.Encoding, t time.Time, dst []byte) []byte
- func Checksum(body []byte, uppercase bool) byte
- func MD5(e *base32.Encoding, src []byte) string
- func Normalized(s string) string
- func Partition(s string, gap int) string
- func Random(e *base32.Encoding) string
- func Time(e *base32.Encoding, t time.Time) string
Examples ¶
Constants ¶
const ( LowercaseAlphabet = "0123456789abcdefghjkmnpqrstvwxyz" UppercaseAlphabet = "0123456789ABCDEFGHJKMNPQRSTVWXYZ" UppercaseChecksum = UppercaseAlphabet + "*~$=U" LowercaseChecksum = LowercaseAlphabet + "*~$=u" )
Base32 alphabets
const ( LenTime = 8 // length returned by AppendTime LenRandom = 8 // length returned by AppendRandom LenMD5 = 26 // length returned by AppendMD5 )
Buffer lengths
Variables ¶
var ( Lower = base32.NewEncoding(LowercaseAlphabet).WithPadding(base32.NoPadding) Upper = base32.NewEncoding(UppercaseAlphabet).WithPadding(base32.NoPadding) )
Base32 encodings
Functions ¶
func Append ¶ added in v0.22.2
Append returns a slice with the encoded version of src appended onto dst.
func AppendMD5 ¶ added in v0.0.2
AppendMD5 appends LenMD (26) encoded bytes generated by MD5 hashing src onto dst.
func AppendNormalized ¶
AppendNormalized appends a normalized version of Crockford encoded bytes of src onto dst and returns the resulting slice. It replaces I and L with 1, o with 0, and removes invalid characters such as hyphens. The resulting slice is uppercase.
func AppendPartition ¶ added in v0.22.2
AppendPartition appends onto dst the result of partitioning src with hyphens ("-") every gap bytes.
func AppendRandom ¶
AppendRandom appends LenRandom (8) encoded bytes generated by crypto/rand onto dst.
func AppendTime ¶ added in v0.21.1
AppendTime appends onto dst LenTime bytes with the Unix time encoded as a 40-bit number. The resulting slice is big endian and suitable for lexicographic sorting.
func Normalized ¶ added in v0.21.2
Normalized returns a normalized version of Crockford encoded bytes of src onto dst and returns the resulting slice. It replaces I and L with 1, o with 0, and removes invalid characters such as hyphens. The resulting slice is uppercase.
func Partition ¶ added in v0.22.2
Partition s with hyphens ("-") to every gap bytes to increase readability. Partition is not Unicode aware because it is made to work with encoded strings.
Example ¶
package main import ( "fmt" "time" "github.com/carlmjohnson/crockford" ) func main() { t := time.Date(1969, 7, 24, 16, 50, 35, 0, time.UTC) s := crockford.Time(crockford.Lower, t) fmt.Println(crockford.Partition(s, 4)) }
Output: zzzj-satv
Types ¶
This section is empty.