Documentation
¶
Overview ¶
Package anyhash provides a unified interface for hash algorithms selected by name.
Unlike Go's standard crypto packages, anyhash lets you specify the algorithm as a string and provides a Clone method to duplicate hash state at any point.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MarshalPHP ¶ added in v0.1.1
MarshalPHP serializes a Hash's internal state into PHP-compatible components.
Types ¶
type Hash ¶
type Hash interface {
hash.Hash
// Clone returns an independent copy of the hash in its current state.
Clone() Hash
}
Hash extends hash.Hash with the ability to clone the current state.
func New ¶
New creates a new Hash for the named algorithm. Algorithm names are case-insensitive and hyphens are ignored, so "SHA-256", "sha256", and "SHA256" all work.
type Options ¶ added in v0.1.4
type Options struct {
Seed uint64 // seed value (murmur3, xxh32, xxh64, xxh3, xxh128)
Secret []byte // custom secret (xxh3, xxh128 only, must be >= 136 bytes)
}
Options configures optional parameters for hash creation. Currently used for seeded hashes (murmur3, xxh32, xxh64) and secret-keyed hashes (xxh3, xxh128).
type PHPMarshaler ¶ added in v0.1.1
type PHPMarshaler interface {
// PHPAlgo returns the PHP-compatible algorithm name (e.g. "sha256", "tiger192,3").
PHPAlgo() string
// MarshalPHP returns the hash state as a PHP-compatible array.
// Elements are int32 or []byte, matching PHP's serialize() format.
MarshalPHP() []any
// UnmarshalPHP restores the hash state from a PHP-compatible array.
UnmarshalPHP(state []any) error
}
PHPMarshaler is implemented by hashes that support PHP-compatible state serialization. The state array elements are int32 (matching PHP integers) or []byte (matching PHP strings). This mirrors PHP's HashContext serialization.