types

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: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	TimeCost   uint32 `env:"HASH_TIMECOST"`
	MemoryCost uint32 `env:"HASH_MEMORYCOST"`
	Threads    uint8  `env:"HASH_THREADS"`
	SaltLength int    `env:"HASH_SALTLENGTH"`
	KeyLength  uint32 `env:"HASH_KEYLENGTH"`
	Cost       int    `env:"HASH_COST"` // Cost parameter (for bcrypt)
	Salt       string `env:"HASH_SALT"` // Salt for HMAC
	Scrypt     ScryptConfig
}

Config represents the configuration for hash algorithms

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig 返回默认配置

type ConfigOption

type ConfigOption func(*Config)

ConfigOption is a function that modifies a Config

func WithCost

func WithCost(cost int) ConfigOption

WithCost sets the cost parameter

func WithMemoryCost

func WithMemoryCost(cost uint32) ConfigOption

WithMemoryCost sets the memory cost

func WithSalt

func WithSalt(salt string) ConfigOption

WithSalt sets the salt

func WithSaltLength

func WithSaltLength(length int) ConfigOption

WithSaltLength sets the salt length

func WithScryptConfig

func WithScryptConfig(scrypt ScryptConfig) ConfigOption

WithScryptConfig sets the scrypt configuration

func WithThreads

func WithThreads(threads uint8) ConfigOption

WithThreads sets the number of threads

func WithTimeCost

func WithTimeCost(cost uint32) ConfigOption

WithTimeCost sets the time cost

type HashParts

type HashParts struct {
	Algorithm Type
	Version   string
	Params    string
	Hash      []byte
	Salt      []byte
}

HashParts represents the parts of a hash

type ScryptConfig

type ScryptConfig struct {
	N int `env:"HASH_SCRYPT_N"`
	R int `env:"HASH_SCRYPT_R"`
	P int `env:"HASH_SCRYPT_P"`
}

ScryptConfig represents the configuration for Scrypt algorithm

type Type

type Type string

Type represents the hash algorithm type

const (
	// TypeCustom custom type
	TypeCustom Type = "custom"
	// TypeMD5 md5 type
	TypeMD5 Type = "md5"
	// TypeSha1 sha1 type
	TypeSha1 Type = "sha1"
	// TypeSha256 sha256 type
	TypeSha256 Type = "sha256"
	// TypeSha512 sha512 type
	TypeSha512 Type = "sha512"
	// TypeSha384 sha384 type
	TypeSha384 Type = "sha384"
	// TypeSha3256 sha3-256 type
	TypeSha3256 Type = "sha3-256"
	// TypeArgon2 argon2 type
	TypeArgon2 Type = "argon2"
	// TypeScrypt scrypt type
	TypeScrypt Type = "scrypt"
	// TypeBcrypt bcrypt type
	TypeBcrypt Type = "bcrypt"
	// TypeHMAC256 hmac sha256 type
	TypeHMAC256 Type = "hmac256"
	// TypeHMAC512 hmac sha512 type
	TypeHMAC512 Type = "hmac512"
	// TypePBKDF2 pbkdf2 type
	TypePBKDF2 Type = "pbkdf2"
	// TypePBKDF2SHA256 pbkdf2 sha256 type
	TypePBKDF2SHA256 Type = "pbkdf2-sha256"
	// TypePBKDF2SHA512 pbkdf2 sha512 type
	TypePBKDF2SHA512 Type = "pbkdf2-sha512"
	// TypePBKDF2SHA384 pbkdf2 sha384 type
	TypePBKDF2SHA384 Type = "pbkdf2-sha384"
	// TypePBKDF2SHA3256 pbkdf2 sha3-256 type
	TypePBKDF2SHA3256 Type = "pbkdf2-sha3-256"
	// TypePBKDF2SHA3224 pbkdf2 sha3-224 type
	TypePBKDF2SHA3224 Type = "pbkdf2-sha3-224"
	// TypePBKDF2SHA3384 pbkdf2 sha3-384 type
	TypePBKDF2SHA3384 Type = "pbkdf2-sha3-384"
	// TypePBKDF2SHA3512224 pbkdf2 sha3-512-224 type
	TypePBKDF2SHA3512224 Type = "pbkdf2-sha3-512-224"
	// TypePBKDF2SHA3512256 pbkdf2 sha3-512-256 type
	TypePBKDF2SHA3512256 Type = "pbkdf2-sha3-512-256"
	// TypePBKDF2SHA3512384 pbkdf2 sha3-512-384 type
	TypePBKDF2SHA3512384 Type = "pbkdf2-sha3-512-384"
	// TypePBKDF2SHA3512512 pbkdf2 sha3-512-512 type
	TypePBKDF2SHA3512512 Type = "pbkdf2-sha3-512-512"
	// TypeUnknown unknown type
	TypeUnknown Type = "unknown"
)

func ParseType

func ParseType(s string) Type

ParseType parses a string into a Type

func (Type) String

func (t Type) String() string

String returns the string representation of the type

Jump to

Keyboard shortcuts

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