passphrase

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package passphrase provides the passphrase-based archive encryption shared by internal/backup and the recovery bundle: a caller-chosen "magic" prefix identifies the archive format and doubles as the AEAD's associated data (so a sealed payload can't be replayed under a different format's magic), and the passphrase itself is stretched with Argon2id before sealing the payload with AES-256-GCM. Without a passphrase, the payload is written plain, behind the same magic+flag framing, so a reader can always tell which case it's looking at from the first few bytes alone.

Index

Constants

This section is empty.

Variables

View Source
var ErrBadMagic = errors.New("passphrase: not a recognised archive for this magic")

ErrBadMagic is returned when the leading bytes don't match the caller's expected magic — the file isn't this kind of archive at all.

View Source
var ErrPassphraseRequired = errors.New("passphrase: this archive is encrypted; a passphrase is required")

ErrPassphraseRequired is returned when opening an encrypted archive without one (or with the wrong one — the two are indistinguishable by design).

Functions

func OpenFrom

func OpenFrom(r io.Reader, magic []byte, passphrase string) ([]byte, error)

OpenFrom reads salt || nonce || len || sealed from r (immediately after ReadFlag has consumed the magic+flag prefix) and returns the decrypted plaintext.

func ReadFlag

func ReadFlag(r io.Reader, magic []byte) (encrypted bool, err error)

ReadFlag reads and verifies the magic prefix from r and returns whether the payload that follows is encrypted. Callers read this first, then dispatch to either a plain io.Copy of the remainder or OpenFrom.

func SealTo

func SealTo(w io.Writer, magic []byte, plain []byte, passphrase string) error

SealTo writes magic || flagEncrypted || salt || nonce || len || sealed, where sealed is AES-256-GCM(plain) under an Argon2id-derived key, with magic as the AEAD's associated data. The whole plaintext is sealed as one unit — chunking would invite a truncation attack for no benefit here — so plain must fit in memory, same as the encrypted path this replaces in internal/backup.

func WritePlainTo

func WritePlainTo(w io.Writer, magic []byte, r io.Reader) error

WritePlainTo writes magic || flagPlain, then streams r into w unmodified. Used when the caller passed no passphrase: the payload is never buffered in memory just to satisfy this framing.

Types

This section is empty.

Jump to

Keyboard shortcuts

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