token

package
v0.0.0-...-41cd4ca Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2022 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidLength is returned when a token's data is an invalid length.
	ErrInvalidLength = errors.New("invalid length")
	// ErrSaltEmpty is returned when a token's data is an invalid length.
	ErrSaltEmpty = errors.New("salt empty")
)

Functions

This section is empty.

Types

type Kind

type Kind int64

Kind represents the kind of model to encode a token for.

const (
	// KindInstance is a token that represents a federated social instance.
	KindInstance Kind = 1 + iota
	// KindAccount is a token that represents a federated social account.
	KindAccount
)

This order can not change else all external urls with tokens will become invalid.

func (Kind) String

func (k Kind) String() string

type Tokenizer

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

Tokenizer generates public tokens for database IDs to obfuscate the database IDs.

func New

func New() (*Tokenizer, error)

New returns a new tokenizer.

func (*Tokenizer) DecodeToken

func (t *Tokenizer) DecodeToken(token string) (Kind, int64, error)

DecodeToken returns the kind and id number of a provided token.

func (*Tokenizer) EncodeToken

func (t *Tokenizer) EncodeToken(kind Kind, id int64) (string, error)

EncodeToken turns a model kind and id into a token.

func (*Tokenizer) GetToken

func (t *Tokenizer) GetToken(o interface{}) string

GetToken returns a token for a known model type.

Jump to

Keyboard shortcuts

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