Documentation
¶
Overview ¶
Package hash provides vendor hash calculation for reproducible builds.
Index ¶
- func IsValidSRIHash(hash string) bool
- type Calculator
- func (c *Calculator) CalculateCargoHash(ctx context.Context, repoPath string) (string, error)
- func (c *Calculator) CalculateCargoHashWithResult(ctx context.Context, repoPath string) (*HashResult, error)
- func (c *Calculator) CalculateGoVendorHash(ctx context.Context, repoPath string) (string, error)
- func (c *Calculator) CalculateGoVendorHashWithResult(ctx context.Context, repoPath string) (*HashResult, error)
- func (c *Calculator) CalculateNpmHash(ctx context.Context, repoPath string) (string, error)
- func (c *Calculator) CalculateNpmHashWithResult(ctx context.Context, repoPath string) (*HashResult, error)
- func (c *Calculator) IsFakeHash(hash string) bool
- type CalculatorOption
- type HashCalculator
- type HashResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsValidSRIHash ¶
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 ¶
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 ¶
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 ¶
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.