core

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2025 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package core implements the functions, types, and interfaces for the module.

Package core implements the functions, types, and interfaces for the module.

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

	ParamSeparator      = ","
	ParamValueSeparator = ":"
)

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 AlgorithmTypeHash added in v0.3.3

func AlgorithmTypeHash(algorithm types.Type) (types.Type, string)

func IsCustomHash added in v0.2.14

func IsCustomHash(h Hash) bool

func NewCodec

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

NewCodec creates a new codec

func NewMD5SHA1 added in v0.3.3

func NewMD5SHA1() hash.Hash

func ParseParams added in v0.3.3

func ParseParams(params string) (map[string]string, error)

func RegisterHashFunc added in v0.2.14

func RegisterHashFunc(name string, hashFunc func() hash.Hash)

RegisterHashFunc registers a new hash.Hash function

func RegisterOrUpdateHashFunc added in v0.2.14

func RegisterOrUpdateHashFunc(name string, hashFunc func() hash.Hash)

RegisterOrUpdateHashFunc registers a new hash.Hash function if it does not exist, otherwise updates it

func UpdateHashFunc added in v0.2.14

func UpdateHashFunc(hash Hash, hashFunc func() hash.Hash)

UpdateHashFunc updates a hash.Hash function

Types

type Codec

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

Codec implements a generic hash codec

func (*Codec) Decode

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

Decode implements the core decoding method

func (*Codec) Encode

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

Encode implements the core encoding method

func (*Codec) Type added in v0.3.3

func (c *Codec) Type() types.Type

func (*Codec) Version added in v0.3.3

func (c *Codec) Version() string

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

type Hash added in v0.2.14

type Hash uint32
const (
	MD4         Hash = 1 + iota // import golang.org/x/crypto/md4
	MD5                         // import crypto/md5
	SHA1                        // import crypto/sha1
	SHA224                      // import crypto/sha256
	SHA256                      // import crypto/sha256
	SHA384                      // import crypto/sha512
	SHA512                      // import crypto/sha512
	MD5SHA1                     // no implementation; MD5+SHA1 used for TLS RSA
	RIPEMD160                   // import golang.org/x/crypto/ripemd160
	SHA3_224                    // import golang.org/x/crypto/sha3
	SHA3_256                    // import golang.org/x/crypto/sha3
	SHA3_384                    // import golang.org/x/crypto/sha3
	SHA3_512                    // import golang.org/x/crypto/sha3
	SHA512_224                  // import crypto/sha512
	SHA512_256                  // import crypto/sha512
	BLAKE2s_256                 // import golang.org/x/crypto/blake2s
	BLAKE2b_256                 // import golang.org/x/crypto/blake2b
	BLAKE2b_384                 // import golang.org/x/crypto/blake2b
	BLAKE2b_512                 // import golang.org/x/crypto/blake2b

	ADLER32
	CRC32
	CRC32_ISO
	CRC32_CAST
	CRC32_KOOP
	CRC64_ISO
	CRC64_ECMA
	FNV32
	FNV32A
	FNV64
	FNV64A
	FNV128
	FNV128A
	MAPHASH
)

func ParseCryptoHash added in v0.2.14

func ParseCryptoHash(s string) (Hash, bool)

ParseCryptoHash only deals with crypto.Hash supported algorithms

func ParseCustomHash added in v0.2.14

func ParseCustomHash(s string) (Hash, bool)

ParseCustomHash algorithms that handle custom registrations

func ParseHash added in v0.2.14

func ParseHash(s string) (Hash, error)

func ParseInternalHash added in v0.2.14

func ParseInternalHash(s string) (Hash, bool)

ParseInternalHash algorithms that handle internal extensions

func (Hash) New added in v0.2.14

func (h Hash) New() hash.Hash

func (Hash) String added in v0.2.14

func (h Hash) String() string

Jump to

Keyboard shortcuts

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