hashing

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package hashing defines the Hasher port and the raw/normalized content-hash helpers Båge uses for drift discipline (SPEC §4.3). RawHash gates byte-offset validity against the live file; NormHash classifies whitespace-only drift.

XXHasher (xxhash.go) is the canonical adapter, matching Hylla's content hash; FNVHasher is a dependency-free fallback. The two-hash semantics are engine-independent, so the drift logic is unaffected by which Hasher is used.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NormHash

func NormHash(h Hasher, raw []byte) string

NormHash returns the digest of raw after normalize.Normalize, classifying whitespace-only drift: when RawHash differs but NormHash matches, the change is whitespace-only and the range can be re-grounded rather than rejected.

func RawHash

func RawHash(h Hasher, raw []byte) string

RawHash returns the digest of raw exactly as given, gating byte-offset validity: a byte range is trustworthy only while the live file's RawHash is unchanged.

Types

type FNVHasher

type FNVHasher struct{}

FNVHasher is the stdlib adapter implementing Hasher with FNV-1a (64-bit), hex-encoded. It is dependency-free and holds no state, so the zero value is ready to use. It is the fallback Hasher; XXHasher is the canonical one shared with Hylla.

func (FNVHasher) Sum

func (FNVHasher) Sum(b []byte) string

Sum returns the lowercase hex-encoded FNV-1a 64-bit digest of b.

type Hasher

type Hasher interface {
	// Sum returns the lowercase hex-encoded digest of b.
	Sum(b []byte) string
}

Hasher computes a stable hex digest of a byte slice. Implementations must be deterministic and free of hidden state so equal inputs always yield equal digests.

type XXHasher

type XXHasher struct{}

XXHasher implements Hasher with xxHash64 — the canonical content hash shared with Hylla. The digest is the 16-character, zero-padded, lowercase hex of the 64-bit sum, so Båge and Hylla produce byte-identical digests for identical inputs. This fixed format IS the cross-system contract: any change to the width or encoding here must be mirrored on the Hylla side.

XXHasher holds no state, so the zero value is ready to use.

func (XXHasher) Sum

func (XXHasher) Sum(b []byte) string

Sum returns the 16-character zero-padded lowercase hex of the xxHash64 of b.

Jump to

Keyboard shortcuts

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