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 ¶
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 ¶
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 ¶
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.