validator

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package validator provides a common interface for algorithm-specific parameters.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateConfig

func ValidateConfig(cfg *types.Config) (*types.Config, error)

ValidateConfig validates the configuration without any algorithm-specific parameters. It returns a validated and potentially default-filled configuration.

func WithValidator

func WithValidator(cfg *types.Config, v func(cfg *types.Config) error) (*types.Config, error)

WithValidator runs the provided Validator on the configuration.

Types

type Parameters

type Parameters interface {
	// Validate checks if the parameters are valid within the context of the given configuration.
	Validate(cfg *types.Config) error
	// FromMap populates the parameter struct from a map of key-value strings.
	// IMPORTANT: This method must have a pointer receiver to ensure that the calling
	// struct is modified. This also ensures that only pointer types satisfy this interface.
	FromMap(params map[string]string) error
	// ToMap converts the parameter struct back into a map of key-value strings.
	ToMap() map[string]string
	// String returns a string representation of the parameters.
	String() string
	// IsNil checks if the underlying pointer is nil. This method must also have
	// a pointer receiver to be invoked on a nil receiver without panicking.
	IsNil() bool
}

Parameters defines the interface for algorithm-specific parameter validation and handling. This interface needs to be implemented by parameter structs for different hashing algorithms.

type ValidateFunc

type ValidateFunc func(cfg *types.Config) error

func (ValidateFunc) Validate

func (v ValidateFunc) Validate(cfg *types.Config) error

type Validated

type Validated[T Parameters] struct {
	// Params holds the validated and populated algorithm-specific parameters.
	// It will be the zero value of its type (e.g., nil) if the input was nil.
	Params T
	// Config holds the validated and potentially default-filled configuration.
	Config *types.Config
}

Validated holds the results of a successful validation operation on parameters.

func ValidateParams

func ValidateParams[T Parameters](cfg *types.Config, p T) (*Validated[T], error)

ValidateParams decodes the parameter string from the configuration, populates the provided parameters object, and then runs the algorithm-specific validation. It returns a Validated struct containing the final parameters and configuration. The provided parameter 'p' must be a pointer to a struct that implements the Parameters interface. Use ValidateConfig for parameter-less validation.

type Validator

type Validator interface {
	Validate(cfg *types.Config) error
}

Jump to

Keyboard shortcuts

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