core

package
v0.2.13 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ENV environment variable name
	ENV = "ORIGADMIN_HASH_TYPE"
	// DefaultType default hash type
	DefaultType = "argon2"
	// DefaultVersion default hash version
	DefaultVersion = "v1"
	// DefaultSaltLength default salt length
	DefaultSaltLength = 16
	// DefaultTimeCost default time cost for Argon2
	DefaultTimeCost = 3
	// DefaultMemoryCost default memory cost for Argon2
	DefaultMemoryCost = 64 * 1024 // 64MB
	// DefaultThreads default number of threads for Argon2
	DefaultThreads = 4
	// DefaultCost default cost for bcrypt
	DefaultCost = 10
)

Variables

View Source
var (
	// ErrPasswordNotMatch error when password not match
	ErrPasswordNotMatch = errors.String("password not match")
	// ErrAlgorithmMismatch error when algorithm mismatch
	ErrAlgorithmMismatch = errors.String("algorithm mismatch")
	// ErrInvalidHashFormat error when invalid hash format
	ErrInvalidHashFormat = errors.String("invalid hash format")
	// ErrSaltLengthTooShort error when salt length too short
	ErrSaltLengthTooShort = errors.String("salt length must be at least 8 bytes")
	// ErrCostOutOfRange error when cost out of range
	ErrCostOutOfRange = errors.String("cost must be between 4 and 31")
)

Functions

func NewCodec

func NewCodec(algorithm types.Type, opts ...CodecOption) interfaces.Codec

NewCodec creates a new codec

Types

type Codec

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

Codec implements a generic hash codec

func (*Codec) Decode

func (e *Codec) Decode(encoded string) (*types.HashParts, error)

Decode implements the core decoding method

func (*Codec) Encode

func (e *Codec) Encode(salt []byte, hash []byte, params ...string) string

Encode implements the core encoding method

type CodecOption

type CodecOption func(*Codec)

CodecOption defines configuration options for the codec

func WithVersion

func WithVersion(version string) CodecOption

WithVersion sets the version number

Jump to

Keyboard shortcuts

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