idcodec

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultAlphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"

Variables

View Source
var (
	ErrInvalidLength     = errors.New("idcodec: invalid length")
	ErrVersionMismatch   = errors.New("idcodec: version mismatch")
	ErrMACVerification   = errors.New("idcodec: MAC verification failed")
	ErrInvalidBase62Char = errors.New("idcodec: invalid base62 character")
	ErrBadConfig         = errors.New("idcodec: bad config")
)

Functions

This section is empty.

Types

type Codec

type Codec struct {
	// contains filtered or unexported fields
}

func MustNewCodecFromSecret

func MustNewCodecFromSecret(cfg Config) *Codec

func NewCodec

func NewCodec(masterKey [32]byte, version uint8, macLen int) (*Codec, error)

func NewCodecFromSecret

func NewCodecFromSecret(cfg Config) (*Codec, error)

func (*Codec) DecodeBodyOnly

func (c *Codec) DecodeBodyOnly(s string) (uint64, error)

func (*Codec) DecodeToUint64

func (c *Codec) DecodeToUint64(s string) (uint64, error)

func (*Codec) DecodeToUint64WithKind

func (c *Codec) DecodeToUint64WithKind(s string, kind *byte) (uint64, error)

func (*Codec) EncodeUint64

func (c *Codec) EncodeUint64(id uint64) string

func (*Codec) EncodeUint64WithKind

func (c *Codec) EncodeUint64WithKind(id uint64, kind *byte) string

func (*Codec) MustDecodeToUint64

func (c *Codec) MustDecodeToUint64(s string) uint64

func (*Codec) MustEncodeUint64

func (c *Codec) MustEncodeUint64(id uint64) string

func (*Codec) Validate

func (c *Codec) Validate(s string) error

type Config

type Config struct {
	Secret   []byte
	Version  uint8
	MacLen   int
	Alphabet string
	Domain   []byte
	Kind     *byte
}

type MultiCodec

type MultiCodec struct {
	Cur *Codec
	Old []*Codec
}

func (MultiCodec) DecodeToUint64

func (m MultiCodec) DecodeToUint64(s string) (uint64, error)

func (MultiCodec) EncodeUint64

func (m MultiCodec) EncodeUint64(id uint64) string

Jump to

Keyboard shortcuts

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