crypto

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package crypto wraps age. Cipher is satisfied by PassphraseCipher (MVP) and, post-MVP, a recipients-based cipher.

Index

Constants

This section is empty.

Variables

View Source
var ErrWrongPassphrase = errors.New("wrong passphrase")

ErrWrongPassphrase is returned when a passphrase does not match the ciphertext (or, for Header.Unlock, any key slot).

Functions

func NewHeader

func NewHeader(passphrase, slotName string) (*Header, *MasterKey, error)

NewHeader generates a master key and a header with one passphrase slot: the primary slot, owned by whoever initialized the storage.

Types

type Cipher

type Cipher interface {
	Encrypt(plaintext []byte) ([]byte, error)
	Decrypt(ciphertext []byte) ([]byte, error)
}
type Header struct {
	Version   int    `json:"version"`
	Recipient string `json:"recipient"` // master public key
	Slots     []Slot `json:"slots"`
}

Header is the parsed header object.

func ParseHeader

func ParseHeader(data []byte) (*Header, error)

func (*Header) AddSlot

func (h *Header) AddSlot(passphrase, name string, mk *MasterKey) error

AddSlot wraps the master key under an additional passphrase.

func (*Header) Marshal

func (h *Header) Marshal() ([]byte, error)

func (*Header) Unlock

func (h *Header) Unlock(passphrase string) (*MasterKey, error)

Unlock tries the passphrase against every slot. Returns ErrWrongPassphrase when none opens.

type MasterKey

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

MasterKey is the unwrapped master identity. It satisfies Cipher: Encrypt seals to the master recipient, Decrypt opens with the identity.

func ParseMasterKey

func ParseMasterKey(s string) (*MasterKey, error)

ParseMasterKey parses the identity string form (used by the session cache, which stores the unwrapped master key, not the passphrase).

func (*MasterKey) Decrypt

func (m *MasterKey) Decrypt(ciphertext []byte) ([]byte, error)

func (*MasterKey) Encrypt

func (m *MasterKey) Encrypt(plaintext []byte) ([]byte, error)

func (*MasterKey) String

func (m *MasterKey) String() string

type PassphraseCipher

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

PassphraseCipher encrypts to an age scrypt recipient (symmetric, passphrase-derived). In the header model it wraps key-slot contents, not data blobs.

func NewPassphraseCipher

func NewPassphraseCipher(passphrase string) *PassphraseCipher

func (*PassphraseCipher) Decrypt

func (c *PassphraseCipher) Decrypt(ciphertext []byte) ([]byte, error)

func (*PassphraseCipher) Encrypt

func (c *PassphraseCipher) Encrypt(plaintext []byte) ([]byte, error)

type Slot

type Slot struct {
	Name    string `json:"name,omitempty"`
	Primary bool   `json:"primary,omitempty"`
	Wrapped []byte `json:"wrapped"` // age scrypt ciphertext of the master identity
}

Slot is one wrapped copy of the master key. Name identifies whose slot it is (user@host), the future hook for per-user factors (TOTP, etc). Primary marks the slot whose owner may rotate/remove other slots; advisory until header signing exists (no server = no cryptographic enforcement), but tooling refuses to remove or demote it.

Jump to

Keyboard shortcuts

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