attach

package
v0.5.6 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: GPL-3.0 Imports: 12 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 attach is the content of a doc or file message (design §3.5, §5.2): the file is sealed under a fresh one-time key, the ciphertext goes to the channel's blob route, and the message — inside the Double Ratchet envelope — carries a Descriptor naming the blob and holding that key. The relay sees the ciphertext's size and nothing else.

The cipher is AES-256-GCM from the Go standard library. Each key seals exactly one file, once, so the nonce is fixed at zero: GCM's one rule is a (key, nonce) pair never sealing twice, and a key that is never reused keeps it. The file is sealed whole, not chunked; the relay's 64 MiB cap bounds what a host holds in memory.

Index

Constants

View Source
const (
	// KeySize is the one-time key's length (AES-256).
	KeySize = 32
	// Overhead is what sealing adds: the GCM tag.
	Overhead = 16
	// MaxSize is the largest file: the relay's blob cap less the tag.
	MaxSize = relay.MaxBlob - Overhead
)

Variables

View Source
var (
	ErrDescriptor = errors.New("attach: descriptor")
	ErrOpen       = errors.New("attach: the blob does not open under the message's key")
	ErrMismatch   = errors.New("attach: the unwrapped file does not match the message's size and sha256")
)

Errors a receiver reports on its quarantine record.

Functions

func Open

func Open(d Descriptor, ct []byte) ([]byte, error)

Open unwraps ct under d's key and checks it against d's size and sha256. Nothing of a file that fails either check is returned.

func ValidName

func ValidName(name string) bool

ValidName reports whether name can be a file's name in one directory: no path, not . or .., no control character, valid UTF-8, at most 255 bytes.

Types

type Descriptor

type Descriptor struct {
	Blob   string `json:"blob"`
	Key    []byte `json:"key"`
	Name   string `json:"name"`
	Size   int64  `json:"size"`
	SHA256 string `json:"sha256"`
	Mime   string `json:"mime,omitempty"`
}

Descriptor is a doc or file message's body. Key is the one-time key (standard base64 in JSON); Size and SHA256 are the plaintext's, checked after unwrapping.

func Parse

func Parse(body []byte) (Descriptor, error)

Parse reads a descriptor from the start of body; anything after the JSON value — the status line a quarantine record adds — is ignored.

func Seal

func Seal(name string, plain []byte) ([]byte, Descriptor, error)

Seal encrypts plain under a fresh key and returns the ciphertext and the descriptor to send, its Blob left for the caller to fill from the put.

func (Descriptor) Check

func (d Descriptor) Check() error

Check is the descriptor's shape: a blob id, a key, a file name, a size in range and a sha256.

func (Descriptor) Marshal

func (d Descriptor) Marshal() ([]byte, error)

Marshal is the message body for d.

Jump to

Keyboard shortcuts

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