scheme

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2025 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

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

Package scheme defines the core interfaces for hash algorithm implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AlgorithmConfig

type AlgorithmConfig func() *types.Config

AlgorithmConfig defines a function that returns a Config object for a specific algorithm.

func (AlgorithmConfig) Config

func (c AlgorithmConfig) Config() *types.Config

Config implements the AlgorithmConfig interface.

type AlgorithmCreator

type AlgorithmCreator func(algSpec types.Spec, cfg *types.Config) (Scheme, error)

AlgorithmCreator is a function that creates an instance of Scheme given its type and configuration.

func (AlgorithmCreator) Create

func (c AlgorithmCreator) Create(spec types.Spec, cfg *types.Config) (Scheme, error)

Create implements the Factory interface.

type AlgorithmResolver

type AlgorithmResolver func(algSpec types.Spec) (types.Spec, error)

func (AlgorithmResolver) ResolveSpec

func (r AlgorithmResolver) ResolveSpec(algSpec types.Spec) (types.Spec, error)

type Factory

type Factory interface {
	// Config returns the default configuration for this factory.
	Config() *types.Config
	// Create uses a unified Config object to create a Scheme instance.
	Create(spec types.Spec, cfg *types.Config) (Scheme, error)
	// ResolveSpec resolves a spec string to a types.Spec object using the internal alias map.
	ResolveSpec(types.Spec) (types.Spec, error)
}

Factory defines the contract for creating Scheme instances. This is the sole entry point for creating any Scheme, used by both NewCrypto and Verify.

type Scheme

type Scheme interface {
	// Spec returns the unique, structured specification of this scheme.
	Spec() types.Spec

	// Hash generates a hash for the given password, creating a new salt internally.
	Hash(password string) (*types.HashParts, error)

	// HashWithSalt generates a hash for the given password with a specified salt.
	HashWithSalt(password string, salt []byte) (*types.HashParts, error)

	// Verify checks if the given password matches the information stored in HashParts.
	// The implementation should rely on the configuration of the Scheme instance it is called on,
	// which is expected to be created by the factory with the correct parameters from the original hash.
	Verify(parts *types.HashParts, password string) error
}

Scheme defines the interface for a specific, configured cryptographic hash algorithm. An instance of a Scheme is expected to be immutable once created.

type SpecResolver

type SpecResolver interface {
	ResolveSpec(algSpec types.Spec) (types.Spec, error)
}

Jump to

Keyboard shortcuts

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