hash

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package hash defines the content hash used for every object in vx.

vx identifies blobs, trees and changesets by the BLAKE3-256 hash of their canonical encoding. The text form is "b3:" followed by 64 lowercase hex characters. Objects of different kinds are hashed with a distinct domain prefix so that a blob can never collide with a tree that has the same bytes.

Index

Constants

View Source
const Prefix = "b3:"

Prefix is the text prefix that marks a vx hash.

View Source
const Size = 32

Size is the length of a hash in bytes.

Variables

View Source
var ErrInvalid = errors.New("invalid hash")

ErrInvalid is returned when parsing malformed hash text.

Functions

This section is empty.

Types

type Hash

type Hash [Size]byte

Hash is a BLAKE3-256 digest. The zero value means "no object".

var Zero Hash

Zero is the empty hash.

func FromBytes

func FromBytes(b []byte) (Hash, error)

FromBytes converts a 32 byte slice. A nil or empty slice gives Zero.

func MustParse

func MustParse(s string) Hash

MustParse is Parse for tests and constants.

func Of

func Of(kind Kind, data []byte) Hash

Of hashes data in the domain of kind.

func Parse

func Parse(s string) (Hash, error)

Parse reads the text form. The "b3:" prefix is optional.

func (Hash) Bytes

func (h Hash) Bytes() []byte

Bytes returns the hash as a slice, or nil for Zero.

func (Hash) Hex

func (h Hash) Hex() string

Hex returns the 64 character hex form without prefix.

func (Hash) IsZero

func (h Hash) IsZero() bool

IsZero reports whether h is the empty hash.

func (Hash) MarshalText

func (h Hash) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (*Hash) Scan

func (h *Hash) Scan(src any) error

Scan implements sql.Scanner.

func (Hash) Short

func (h Hash) Short() string

Short returns a 12 character hex prefix for display.

func (Hash) String

func (h Hash) String() string

String returns the full text form, for example "b3:9f1c...".

func (*Hash) UnmarshalText

func (h *Hash) UnmarshalText(b []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

func (Hash) Value

func (h Hash) Value() (driver.Value, error)

Value implements driver.Valuer, storing the hash as bytea (NULL for Zero).

type Kind

type Kind string

Kind separates the hash domains of different object types.

const (
	KindBlob      Kind = "blob"
	KindTree      Kind = "tree"
	KindChangeset Kind = "changeset"
)

Jump to

Keyboard shortcuts

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