valid

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package valid holds the shared input-validation rules for F5 coefficients and passwords. It deliberately returns booleans and a Reason enum rather than errors: the rule is shared, but each capability presents failures in its own way (the extract package wraps sentinel errors for errors.Is, the embed package reports plain localized messages). Keeping the rule here and the presentation in each package avoids re-coupling the two.

The package depends only on f5core, so importing it pulls in no localization tables, logger, or JPEG codec.

Index

Constants

View Source
const (
	// CoefficientMin is the minimum valid quantized DCT coefficient value.
	CoefficientMin = f5core.CoefficientMin
	// CoefficientMax is the maximum valid quantized DCT coefficient value.
	CoefficientMax = f5core.CoefficientMax
)

Coefficient bounds, re-exported from f5core so callers validating against the JPEG quantized DCT range need not import f5core directly.

Variables

This section is empty.

Functions

func CoefficientsValid

func CoefficientsValid(coefficients []int16) bool

CoefficientsValid reports whether coefficients is non-empty and every value is within [CoefficientMin, CoefficientMax].

func PasswordValid

func PasswordValid(password string) bool

PasswordValid reports whether password is usable for PRNG seeding, i.e. it is non-empty.

Types

type Reason

type Reason int

Reason classifies why a coefficient slice failed validation. It is an enum so callers can switch over it exhaustively and map each case to their own error type and localized message.

const (
	// OK indicates the input is valid.
	OK Reason = iota
	// EmptyCoefficients indicates the coefficient slice had no elements.
	EmptyCoefficients
	// CoefficientOutOfRange indicates a coefficient fell outside
	// [CoefficientMin, CoefficientMax].
	CoefficientOutOfRange
)

func FirstInvalidReason

func FirstInvalidReason(coefficients []int16) Reason

FirstInvalidReason reports the first validation problem with coefficients, or OK if the slice is valid. It returns on the first out-of-range value so the common valid case still scans the whole slice exactly once.

func (Reason) String

func (r Reason) String() string

String returns a short, stable identifier for the reason, useful in logs and test failures. It is not a user-facing message.

Jump to

Keyboard shortcuts

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