crockford

package module
v0.23.1 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2023 License: MIT Imports: 4 Imported by: 2

README

Crockford GoDoc Go Report Card

Crockford implements the Crockford base 32 encoding in Go.

See https://www.crockford.com/base32.html

Documentation

Overview

Package crockford implements the Crockford base 32 encoding

See https://www.crockford.com/base32.html

Index

Examples

Constants

View Source
const (
	LowercaseAlphabet = "0123456789abcdefghjkmnpqrstvwxyz"
	UppercaseAlphabet = "0123456789ABCDEFGHJKMNPQRSTVWXYZ"
	UppercaseChecksum = UppercaseAlphabet + "*~$=U"
	LowercaseChecksum = LowercaseAlphabet + "*~$=u"
)

Base32 alphabets

View Source
const (
	LenTime   = 8  // length returned by AppendTime
	LenRandom = 8  // length returned by AppendRandom
	LenMD5    = 26 // length returned by AppendMD5
)

Buffer lengths

Variables

Base32 encodings

Functions

func Append added in v0.22.2

func Append(e *base32.Encoding, dst, src []byte) []byte

Append returns a slice with the encoded version of src appended onto dst.

See https://github.com/golang/go/issues/53693.

func AppendMD5 added in v0.0.2

func AppendMD5(e *base32.Encoding, dst, src []byte) []byte

AppendMD5 appends LenMD (26) encoded bytes generated by MD5 hashing src onto dst.

func AppendNormalized

func AppendNormalized(dst, src []byte) []byte

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

func AppendPartition(dst, src []byte, gap int) []byte

AppendPartition appends onto dst the result of partitioning src with hyphens ("-") every gap bytes.

func AppendRandom

func AppendRandom(e *base32.Encoding, dst []byte) []byte

AppendRandom appends LenRandom (8) encoded bytes generated by crypto/rand onto dst.

func AppendTime added in v0.21.1

func AppendTime(e *base32.Encoding, t time.Time, dst []byte) []byte

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 Checksum

func Checksum(body []byte, uppercase bool) byte

Checksum returns the checksum byte for an unencoded body.

func MD5 added in v0.21.2

func MD5(e *base32.Encoding, src []byte) string

MD5 returns encoded bytes generated by MD5 hashing src.

func Normalized added in v0.21.2

func Normalized(s string) string

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

func Partition(s string, gap int) string

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

func Random added in v0.21.2

func Random(e *base32.Encoding) string

Random returns LenRandom (8) encoded bytes generated by crypto/rand.

func Time

func Time(e *base32.Encoding, t time.Time) string

Time encodes the Unix time as a 40-bit number. The resulting string is big endian and suitable for lexicographic sorting.

Types

This section is empty.

Jump to

Keyboard shortcuts

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