bundlefooter

package
v1.0.0-beta2 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package bundlefooter implements the AFBNDL01 trailer described in ADR 0004 (and task-sdk/docs/executable-bundle-spec.rst). A bundle file is the compiled executable with three appended regions: the source bytes, the manifest bytes, and a fixed 64-byte trailer that locates them and carries a SHA-256 over the binary region for integrity.

The trailer layout (all little-endian) is:

bytes  0..3   source_len     uint32
bytes  4..7   metadata_len   uint32
bytes  8..11  footer_ver     uint32  (= 1)
bytes 12..43  binary_sha256  32 bytes (SHA-256 of the binary region)
bytes 44..55  reserved       12 bytes, zero
bytes 56..63  magic          8 bytes ASCII "AFBNDL01"

Index

Constants

View Source
const (
	// TrailerSize is the fixed length of the trailer, in bytes.
	TrailerSize = 64

	// FooterVersion is the currently defined trailer-format version.
	FooterVersion = 1

	// MaxRegionSize is the largest source or metadata region this footer
	// format can address (uint32 length field).
	MaxRegionSize = math.MaxUint32
)

Variables

View Source
var ErrHashMismatch = errors.New("bundlefooter: binary_sha256 mismatch")

ErrHashMismatch is returned by Read when the SHA-256 recomputed over the binary region does not match the binary_sha256 recorded in the trailer.

View Source
var ErrNotBundle = errors.New("bundlefooter: not a bundle (magic mismatch)")

ErrNotBundle is returned by Read when the file does not end with the AFBNDL01 magic.

View Source
var ErrUnknownVersion = errors.New("bundlefooter: unknown footer version")

ErrUnknownVersion is returned by Read when the trailer's footer_ver field is something other than FooterVersion.

View Source
var Magic = [8]byte{'A', 'F', 'B', 'N', 'D', 'L', '0', '1'}

Magic is the 8-byte ASCII tag that identifies a file as a bundle.

Functions

func Append

func Append(execPath string, source, metadata []byte) error

Append writes the source bytes, metadata bytes, and trailer to the end of the file at execPath. The file's existing contents (the executable) are left intact and its mode bits are preserved. source MAY be nil/empty.

func IsBundle

func IsBundle(path string) (bool, error)

IsBundle reports whether the file at path ends with the AFBNDL01 magic. It does not validate the trailer beyond the magic check, so a file with a matching magic but a corrupt trailer body still returns true.

func Read

func Read(path string) (source, metadata []byte, err error)

Read parses the trailer of the file at path and returns the embedded source and metadata regions. Returns ErrNotBundle if the magic does not match (so callers may silently ignore non-bundle files).

Types

type Trailer

type Trailer struct {
	SourceLen     uint32
	MetadataLen   uint32
	FooterVersion uint32
	BinarySHA256  [sha256.Size]byte
}

Trailer carries the parsed contents of a bundle's 64-byte trailer.

Jump to

Keyboard shortcuts

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