hash

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2026 License: MIT Imports: 5 Imported by: 0

README

internal/hash

digest := hash.SHA256String("body")
fmt.Println(digest.String())

internal/hash provides stable SHA-256 digest helpers for source, artifact, and metadata identity.

Use HashIdentity for ordered transform ledgers where source, parser, chunking, model, schema, and profile changes must invalidate derived artifacts. Empty fields are omitted; part order is significant.

It intentionally stays small: callers decide which bytes are canonical and when a digest invalidates downstream artifacts.

Documentation

Overview

Package hash provides stable content hash helpers for reliquary primitives. Callers own byte canonicalization and downstream invalidation policy.

Package hash provides stable content hash helpers for reliquary primitives.

Index

Examples

Constants

View Source
const (
	// AlgorithmSHA256 is the canonical algorithm name used by reliquary metadata.
	AlgorithmSHA256 = "sha256"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Digest

type Digest struct {
	Algorithm string
	Hex       string
}

Digest identifies content by algorithm and hex-encoded value.

func HashIdentity

func HashIdentity(parts ...IdentityPart) Digest

HashIdentity returns a stable digest for ordered transform identity parts. Reordering parts changes the digest. Zero-value parts and empty fields are omitted deterministically.

Example
package main

import (
	"fmt"

	"github.com/dotcommander/reliquary/internal/hash"
)

func main() {
	digest := hash.HashIdentity(
		hash.IdentityPart{Kind: "source", InputHash: "source-sha"},
		hash.IdentityPart{Kind: "chunker", Version: "v1", ConfigHash: "chunk-cfg"},
	)
	fmt.Println(digest.Algorithm, digest.String() != "")
}
Output:
sha256 true

func SHA256Bytes

func SHA256Bytes(b []byte) Digest

SHA256Bytes returns a SHA-256 digest for b.

func SHA256Reader

func SHA256Reader(r io.Reader) (Digest, error)

SHA256Reader streams r into a SHA-256 digest.

func SHA256String

func SHA256String(s string) Digest

SHA256String returns a SHA-256 digest for s.

Example
package main

import (
	"fmt"

	"github.com/dotcommander/reliquary/internal/hash"
)

func main() {
	digest := hash.SHA256String("body")
	fmt.Println(digest.Algorithm, digest.String() != "")
}
Output:
sha256 true

func (Digest) String

func (d Digest) String() string

String returns the portable digest identity, for example sha256:abcd.

type Identity

type Identity []IdentityPart

Identity is an ordered list of transform identity parts.

func (Identity) Digest

func (id Identity) Digest() Digest

Digest returns a stable digest for id.

type IdentityPart

type IdentityPart struct {
	Kind       string
	ID         string
	Version    string
	ConfigHash string
	InputHash  string
	Value      string
	Digest     Digest
}

IdentityPart names one ordered input to a derived artifact identity. Empty fields are omitted from the hash encoding, so callers can fill only the dimensions they own.

Jump to

Keyboard shortcuts

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