types

package
v0.3.23 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TypeHash added in v0.3.18

func TypeHash(subAlg string) (stdhash.Hash, error)

TypeHash is a helper function that might need to be refactored depending on how stdhash.ParseHash is updated to handle the new Type struct. For now, it assumes subAlg is a simple string.

Types

type AlgorithmResolver added in v0.3.18

type AlgorithmResolver interface {
	ResolveType(t Type) (Type, error)
}

AlgorithmResolver defines an interface for resolving and normalizing algorithm types.

type Config

type Config struct {
	SaltLength  int    `env:"HASH_SALTLENGTH"`
	ParamConfig string `env:"HASH_PARAM_CONFIG"`
}

Config represents the configuration for hash algorithms

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig return to the default configuration

type HashParts

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

HashParts represents the parts of a hash

func NewHashParts added in v0.3.18

func NewHashParts(p Type) *HashParts

func NewHashPartsFull added in v0.3.18

func NewHashPartsFull(p Type, hash []byte, salt []byte, params map[string]string) *HashParts

func NewHashPartsWithHashSalt added in v0.3.18

func NewHashPartsWithHashSalt(p Type, hash []byte, salt []byte) *HashParts

func (*HashParts) String added in v0.3.18

func (h *HashParts) String() string

func (*HashParts) WithAlgorithm added in v0.3.18

func (h *HashParts) WithAlgorithm(algorithm string) *HashParts

func (*HashParts) WithHash added in v0.3.18

func (h *HashParts) WithHash(hash []byte) *HashParts

func (*HashParts) WithHashSalt added in v0.3.18

func (h *HashParts) WithHashSalt(hash []byte, salt []byte) *HashParts

func (*HashParts) WithParams added in v0.3.18

func (h *HashParts) WithParams(params map[string]string) *HashParts

func (*HashParts) WithSalt added in v0.3.18

func (h *HashParts) WithSalt(salt []byte) *HashParts

func (*HashParts) WithVersion added in v0.3.18

func (h *HashParts) WithVersion(version string) *HashParts

type Option

type Option func(*Config)

Option is a function that modifies a Config

func WithParamConfig added in v0.2.17

func WithParamConfig(fn func(string) string) Option

func WithParams

func WithParams(params ParamStringer) Option

func WithParamsString

func WithParamsString(paramConfig string) Option

func WithSaltLength

func WithSaltLength(length int) Option

WithSaltLength sets the salt length

type ParamStringer added in v0.3.18

type ParamStringer interface {
	String() string
}

ParamStringer defines an interface for types that can be converted to a string representation of parameters.

type Params added in v0.3.18

type Params map[string]string

Params is a map of string keys and string values.

type Type

type Type struct {
	// Name is the main algorithm's name, e.g., "hmac", "pbkdf2", "sha256".
	// This is the key field for logical dispatch.
	Name string

	// Underlying is the full string representation of the underlying hash algorithm.
	// For simple hashes, this field is empty.
	// For composite hashes, it specifies the hash function to be used,
	// e.g., "sha256" for "hmac-sha256", or "sha3-512" for "pbkdf2-sha3-512".
	Underlying string
}

Type represents a structured hash algorithm definition. It separates the main algorithm from its underlying hash function, allowing for clear and extensible handling of composite algorithms like HMAC and PBKDF2.

func NewType added in v0.3.18

func NewType(name string, underlying ...string) Type

NewType creates a new Type instance with the specified name and underlying hash.

func ParseType

func ParseType(algorithm string) (Type, error)

ParseType parses an algorithm string into its structured Type. It handles common aliases and composite algorithm formats.

func (Type) Is

func (t Type) Is(t2 Type) bool

Is compares two Type instances for equality.

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