hasher

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package hasher provides a unified interface for various hash algorithms.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HashFile

func HashFile(path string, hashers []Hasher) (map[string]string, error)

HashFile computes hashes for a file using multiple hashers.

func HashReader

func HashReader(r io.Reader, hashers []Hasher) (map[string]string, error)

HashReader computes hashes from an io.Reader using multiple hashers simultaneously. This reads the data only once, computing all hashes in parallel.

func List

func List() []string

List returns all registered algorithm names in sorted order.

func Register

func Register(h Hasher)

Register adds a hasher to the registry.

Types

type HashResult

type HashResult struct {
	Algorithm string
	Hash      string
	Error     error
}

HashResult holds the hash result for a single algorithm.

type Hasher

type Hasher interface {
	// Name returns the algorithm name (e.g., "md5", "sha256")
	Name() string
	// New creates a new hash.Hash instance
	New() hash.Hash
	// OutputSize returns the size of the hash output in bytes
	OutputSize() int
	// IsBase64 returns true if the hash should be encoded as base64 (e.g., quickxor)
	IsBase64() bool
}

Hasher represents a hash algorithm that can be used to compute checksums.

func Get

func Get(name string) (Hasher, bool)

Get returns a hasher by name.

func Parse

func Parse(names string) ([]Hasher, error)

Parse parses a comma-separated list of algorithm names and returns the corresponding hashers. Example: "md5,sha256,blake3"

Jump to

Keyboard shortcuts

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