crypto

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultTokenLength = 32 // 256 bits
)

Variables

View Source
var (
	ErrTooManyInputAlphabet = errors.New("must only provide 1 set of alphabet")
	ErrAlphabetTooLong      = errors.New("alphabet must contain no more than 255 characters")
	ErrAlphabetTooShort     = errors.New("alphabet must contain at least 8 characters")
	ErrAlphabetInvalidUTF8  = errors.New("alphabet must contain valid UTF-8")
	ErrAlphabetNotASCII     = errors.New("alphabet must contain only ASCII characters")
)
View Source
var (
	ErrTooManyArgs = errors.New("too many arguments. expected only 1")
)

Functions

func HashToken

func HashToken(token string) string

func VerifyToken

func VerifyToken(token, storedHash string) (bool, error)

Types

type Argon2

type Argon2 struct {
	Memory      uint32 // Memory cost in KiB
	Iterations  uint32 // Number of iterations (time cost)
	Parallelism uint8  // Number of parallel threads
	SaltLength  uint32 // Length of random salt. Ignored during Verify()
	KeyLength   uint32 // Length of generated key
}

func (*Argon2) Hash

func (a *Argon2) Hash(password string) (string, error)

func (*Argon2) Verify

func (a *Argon2) Verify(password, encodedHash string) (bool, error)

type NanoIDGenerator

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

func NewNanoID

func NewNanoID(a ...string) (*NanoIDGenerator, error)

func (*NanoIDGenerator) Generate

func (n *NanoIDGenerator) Generate(length ...int) (string, error)

type PasswordHandler

type PasswordHandler interface {
	Hash(password string) (string, error)
	Verify(password, hash string) (bool, error)
}

type TokenPair

type TokenPair struct {
	Token string // value returned to client
	Hash  string // value in storage
}

func GenerateHashedToken

func GenerateHashedToken(byteLength ...int) (*TokenPair, error)

Jump to

Keyboard shortcuts

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