hash

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package hash provides vendor hash calculation for reproducible builds.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsValidSRIHash

func IsValidSRIHash(hash string) bool

IsValidSRIHash checks if a string is a valid SRI hash.

Types

type Calculator

type Calculator struct {
	// FakeHash is the placeholder hash used for initial builds.
	// Nix will fail with the correct hash in the error message.
	FakeHash string

	// MaxRetries is the maximum number of retry attempts for hash extraction.
	MaxRetries int

	// Timeout is the maximum time to wait for hash calculation.
	Timeout time.Duration
}

Calculator implements the HashCalculator interface.

func NewCalculator

func NewCalculator() *Calculator

NewCalculator creates a new Calculator with default settings.

func NewCalculatorWithOptions

func NewCalculatorWithOptions(opts ...CalculatorOption) *Calculator

NewCalculatorWithOptions creates a new Calculator with custom options.

func (*Calculator) CalculateCargoHash

func (c *Calculator) CalculateCargoHash(ctx context.Context, repoPath string) (string, error)

CalculateCargoHash calculates the hash for Cargo dependencies from Cargo.lock.

func (*Calculator) CalculateCargoHashWithResult

func (c *Calculator) CalculateCargoHashWithResult(ctx context.Context, repoPath string) (*HashResult, error)

CalculateCargoHashWithResult calculates the Cargo hash and returns detailed result.

func (*Calculator) CalculateGoVendorHash

func (c *Calculator) CalculateGoVendorHash(ctx context.Context, repoPath string) (string, error)

CalculateGoVendorHash calculates the vendor hash for a Go module. It uses the fake-hash retry mechanism: first attempts with a fake hash, then extracts the real hash from the Nix error output.

func (*Calculator) CalculateGoVendorHashWithResult

func (c *Calculator) CalculateGoVendorHashWithResult(ctx context.Context, repoPath string) (*HashResult, error)

CalculateGoVendorHashWithResult calculates the Go vendor hash and returns detailed result.

func (*Calculator) CalculateNpmHash

func (c *Calculator) CalculateNpmHash(ctx context.Context, repoPath string) (string, error)

CalculateNpmHash calculates the hash for npm dependencies from package-lock.json. This uses the SRI hash format compatible with Nix.

func (*Calculator) CalculateNpmHashWithResult

func (c *Calculator) CalculateNpmHashWithResult(ctx context.Context, repoPath string) (*HashResult, error)

CalculateNpmHashWithResult calculates the npm hash and returns detailed result.

func (*Calculator) IsFakeHash

func (c *Calculator) IsFakeHash(hash string) bool

IsFakeHash checks if the hash is the placeholder fake hash.

type CalculatorOption

type CalculatorOption func(*Calculator)

CalculatorOption is a functional option for configuring Calculator.

func WithFakeHash

func WithFakeHash(hash string) CalculatorOption

WithFakeHash sets a custom fake hash for initial builds.

func WithMaxRetries

func WithMaxRetries(retries int) CalculatorOption

WithMaxRetries sets the maximum number of retry attempts.

func WithTimeout

func WithTimeout(timeout time.Duration) CalculatorOption

WithTimeout sets the timeout for hash calculation.

type HashCalculator

type HashCalculator interface {
	// CalculateGoVendorHash calculates the vendor hash for a Go module.
	CalculateGoVendorHash(ctx context.Context, repoPath string) (string, error)

	// CalculateNpmHash calculates the hash for npm dependencies.
	CalculateNpmHash(ctx context.Context, repoPath string) (string, error)

	// CalculateCargoHash calculates the hash for Cargo dependencies.
	CalculateCargoHash(ctx context.Context, repoPath string) (string, error)
}

HashCalculator calculates vendor hashes for reproducible builds.

type HashResult

type HashResult struct {
	Hash       string `json:"hash"`
	Algorithm  string `json:"algorithm"`
	SourceFile string `json:"source_file,omitempty"`
	Retries    int    `json:"retries,omitempty"`
}

HashResult contains the result of a hash calculation.

Jump to

Keyboard shortcuts

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