format

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 17 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 format implements the frozen v1 offline-vault binary formats. It performs no file I/O, prompting, KDF work or persistence. Callers must reserve nonce budgets and manage key lifetimes before using encryption primitives.

Index

Constants

View Source
const (
	// Version identifies the frozen v1 container layout. Incompatible layouts
	// require a new version; existing suite identifiers must not be reassigned.
	Version = 1
	// MaxIDBytes bounds each identifier without changing other stores' contracts.
	MaxIDBytes = 1024
	// MaxSecretBytes bounds the plaintext of a single item.
	MaxSecretBytes = 64 * 1024
	// MaxMetaBytes bounds an entire wrapped-key container.
	MaxMetaBytes = 4096
	// MaxItemBytes includes the largest header and authentication tag.
	MaxItemBytes = 67667
	// MaxEncryptions counts reserved encryptions, including unsuccessful writes.
	MaxEncryptions = 1 << 20
	// WarningEncryptions is ceil(90% of MaxEncryptions).
	WarningEncryptions = 943719
)
View Source
const (
	// MaxManifestBytes bounds one manifest block, including its header.
	MaxManifestBytes = 1 << 20
)
View Source
const (
	// MaxStateBytes bounds the complete JSON state envelope.
	MaxStateBytes = 16 * 1024
)

Variables

View Source
var (
	// ErrCorrupt indicates malformed or unauthentic data, without echoing input.
	ErrCorrupt = errors.New("offline credential data is corrupt")
	// ErrUnsupported indicates an unknown version or suite.
	ErrUnsupported = errors.New("offline credential format is unsupported")
	// ErrIdentity indicates a mismatch with the caller's expected identity.
	ErrIdentity = errors.New("offline credential identity mismatch")
)

Functions

func ItemFilename

func ItemFilename(itemID string) (string, error)

ItemFilename never uses caller identifiers as filesystem path components.

func KeyFileWrappingKey

func KeyFileWrappingKey(m Meta, key []byte) ([]byte, error)

KeyFileWrappingKey derives the wrapping key from an independent key file. The caller must clear the result and must never reuse a salt for new wrapping.

func ManifestRoot

func ManifestRoot(hashes [][32]byte) ([32]byte, error)

ManifestRoot hashes ordered block hashes. Callers must also validate consecutive block indices, cross-block ItemID ordering and the total entry count while streaming.

func OpenItem

func OpenItem(data, key []byte, expected ItemIdentity) (credential.Secret, error)

OpenItem authenticates identity and expiry without imposing a wall clock. Maintenance can read expired data; ordinary Get must check expiry before delivery.

func SealBudget

func SealBudget(b Budget, dek []byte) ([]byte, error)

SealBudget authenticates a count. Durable monotonic updates remain the file layer's responsibility.

func SealItem

func SealItem(i ItemIdentity, nonce [12]byte, key []byte, secret credential.Secret) ([]byte, error)

SealItem encrypts a secret, preserving expiry including historical expiries. The caller must durably reserve an encryption and supply a fresh random nonce. Ordinary Put must additionally reject an already-expired secret.

func SealMeta

func SealMeta(m Meta, wrappingKey, dek []byte) ([]byte, error)

SealMeta wraps a DEK using a prepared header and wrapping key. This low-level primitive requires a fresh salt, nonce and one-use wrapping key from its caller.

func SealTransaction

func SealTransaction(t Transaction, sourceKey, targetKey []byte) ([]byte, error)

SealTransaction authenticates all state under the supplied source and/or target keys. Missing keys produce empty MAC fields; at least one valid key is required.

Types

type Budget

type Budget struct {
	VaultID    [16]byte
	Generation uint64
	Consumed   uint64
	Sequence   uint64
	StoreID    string
}

Budget is an authenticated reservation count, not an anti-rollback anchor.

func OpenBudget

func OpenBudget(data, dek []byte, vaultID [16]byte, generation uint64, storeID string) (Budget, error)

OpenBudget authenticates the count and verifies the expected key identity.

type Current

type Current struct {
	VaultID    [16]byte
	Revision   uint64
	Generation uint64
	MetaHash   [32]byte
}

Current is an unauthenticated publication pointer until matched to valid Meta.

func ParseCurrent

func ParseCurrent(data []byte) (Current, error)

ParseCurrent validates syntax, not publication authenticity or freshness.

func (Current) MarshalBinary

func (c Current) MarshalBinary() ([]byte, error)

MarshalBinary encodes the fixed-size publication pointer.

func (Current) Matches

func (c Current) Matches(data []byte, m Meta) bool

Matches binds a pointer to exact metadata; it does not authenticate the metadata.

type Endpoint

type Endpoint struct {
	VaultID      [16]byte
	StoreID      string
	Revision     uint64
	Generation   uint64
	MetaHash     [32]byte
	ManifestRoot [32]byte
	ItemCount    uint64
}

Endpoint identifies one transaction side and its authenticated snapshot.

type ItemIdentity

type ItemIdentity struct {
	VaultID    [16]byte
	Generation uint64
	Ref        credential.Ref
}

ItemIdentity binds an item to the requested store, vault and DEK generation.

func InspectItem

func InspectItem(data []byte) (ItemIdentity, error)

InspectItem reads bounded, unauthenticated identity metadata for enumeration. Callers must compare it with the vault and filename, then authenticate OpenItem.

type KeyIdentity

type KeyIdentity struct {
	VaultID    [16]byte
	Generation uint64
	StoreID    string
}

KeyIdentity identifies a vault key independently of a publication or item.

type ManifestBlock

type ManifestBlock struct {
	Index   uint32
	Entries []ManifestEntry
}

ManifestBlock is a bounded, strictly ordered chunk of a source or target snapshot.

func ParseManifestBlock

func ParseManifestBlock(data []byte) (ManifestBlock, error)

ParseManifestBlock does not authenticate the block; verify its root via state MAC.

func (ManifestBlock) MarshalBinary

func (m ManifestBlock) MarshalBinary() ([]byte, error)

MarshalBinary validates strict byte ordering and bounds before allocating output.

type ManifestEntry

type ManifestEntry struct {
	ItemID   string
	FileSize uint32
	Hash     [32]byte
}

ManifestEntry describes a ciphertext, never a plaintext secret.

type ManifestVerifier

type ManifestVerifier struct {
	// contains filtered or unexported fields
}

ManifestVerifier checks an entire snapshot without retaining all block hashes. It is single-owner, contains public metadata only, and performs no I/O.

func NewManifestVerifier

func NewManifestVerifier(blocks uint32, items uint64) (*ManifestVerifier, error)

NewManifestVerifier fixes the authenticated expected counts before reading blocks.

func (*ManifestVerifier) Add

func (v *ManifestVerifier) Add(data []byte) error

Add validates a consecutive, strictly ordered block and adds its exact-byte hash. Rejected blocks do not advance the verifier.

func (*ManifestVerifier) Finish

func (v *ManifestVerifier) Finish(expected [32]byte) error

Finish verifies counts and the state-authenticated root. It cannot prove that the listed files actually exist; the file layer must authenticate those files.

type Meta

type Meta struct {
	Suite      WrapSuite
	VaultID    [16]byte
	Generation uint64
	Revision   uint64
	Salt       []byte
	Nonce      [12]byte
	StoreID    string
}

Meta contains public wrapping metadata. Parsed metadata is not authenticated.

func OpenMeta

func OpenMeta(data, wrappingKey []byte, storeID string) (Meta, []byte, error)

OpenMeta authenticates the wrapping container and expected store identity. Authentication failure deliberately does not distinguish bad keys from tampering.

func ParseMeta

func ParseMeta(data []byte) (Meta, error)

ParseMeta validates the bounded format before any expensive derivation. It returns independent public metadata; callers must authenticate with OpenMeta.

type Operation

type Operation byte

Operation identifies a maintenance operation, not a normal item write.

const (
	// OpInit creates a new vault.
	OpInit Operation = iota + 1
	// OpRewrap changes wrapping material while retaining the DEK.
	OpRewrap
	// OpReencrypt creates a new DEK.
	OpReencrypt
	// OpRestore restores a trusted backup under a new DEK.
	OpRestore
	// OpClone creates an independent vault.
	OpClone
	// OpPrune cleans explicitly selected obsolete revisions.
	OpPrune
)

type Stage

type Stage byte

Stage is a recovery hint, never proof of the current durable publication.

const (
	// Prepared records intent before target construction.
	Prepared Stage = iota + 1
	// Building records incomplete target construction.
	Building
	// Verified records a fully validated and synced target.
	Verified
	// Published records a pointer switch which must still be checked.
	Published
	// Committed records confirmed durable publication.
	Committed
	// CleanupPending records explicitly requested unfinished cleanup.
	CleanupPending
)

type Transaction

type Transaction struct {
	OperationID      [16]byte
	Operation        Operation
	Stage            Stage
	Source           Endpoint
	Target           Endpoint
	CleanupRevisions []uint64
}

Transaction contains public state only. Validate current files before recovery actions.

func InspectTransaction

func InspectTransaction(data []byte) (Transaction, error)

InspectTransaction validates public syntax only, to locate wrapping metadata. Its result MUST NOT authorize reads, publication or deletion without a valid MAC.

func OpenTransaction

func OpenTransaction(data, key []byte, expected KeyIdentity, target bool) (Transaction, error)

OpenTransaction verifies the selected side against a trusted expected key identity. It does not assert that the other side or any file is recoverable.

type WrapSuite

type WrapSuite uint16

WrapSuite selects a fixed approved wrapping algorithm and parameter set.

const (
	// WrapPassword selects Argon2id v0x13 with 64 MiB, t=3, p=1.
	WrapPassword WrapSuite = 1
	// WrapKeyFile selects HKDF-SHA-256 of a 32-byte key file.
	WrapKeyFile WrapSuite = 2
)

Jump to

Keyboard shortcuts

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