Documentation
¶
Overview ¶
Package key implements the 32-byte Amber-Store lookup key: a content address that encodes a CAS object type, a logical payload length, and a truncated BLAKE3 hash of the payload's serialized bytes. See architecture/keys.md.
Index ¶
Constants ¶
const Size = 32
Size is the fixed byte length of every key.
Variables ¶
var ( // ErrBadKeyLength means the input to Parse was not exactly Size bytes. ErrBadKeyLength = errors.New("key: data is not 32 bytes") // ErrReservedBitSet means the header's reserved bit (bit 3) is set. ErrReservedBitSet = errors.New("key: reserved header bit is set") // ErrReservedType means the object type is reserved (5..15) or out of range. ErrReservedType = errors.New("key: reserved object type") // ErrNonCanonicalLength means the length field has leading-zero padding. ErrNonCanonicalLength = errors.New("key: non-canonical length encoding") )
Sentinel errors returned by Parse, Validate, and the constructors. Wrap them with %w and match with errors.Is.
Functions ¶
This section is empty.
Types ¶
type Key ¶
Key is a 32-byte lookup key. It is a value type and is directly comparable, so it can be used as a Go map key. Accessors assume the key is canonical (produced by New, NewFromHash, or Parse).
func New ¶
New computes the BLAKE3-256 digest of serialized, then assembles a canonical key via NewFromHash. length is the logical payload length and is taken as given (it need not equal len(serialized) — see NewFromHash).
func NewFromHash ¶
NewFromHash assembles a canonical key from a CAS object type, a logical payload length, and a precomputed full 256-bit BLAKE3 digest. The digest is truncated to its leading bytes to fill the key. length is used verbatim: for Blob/XattrSet it is the serialized byte length; for FileNode/DirLeaf/DirNode it is the logical size (see architecture/types.md). Returns ErrReservedType if t is not a defined type.
func Parse ¶
Parse copies b into a Key and validates its canonical form. b must be exactly Size bytes.
func (Key) LengthSize ¶
LengthSize returns the number of bytes the payload-length field occupies (1..8).
type Type ¶
type Type uint8
Type is the 4-bit CAS object type carried in the high nibble of a key's header byte (architecture/types.md).