envelope

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: GPL-3.0 Imports: 7 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 envelope is the relay record: a type byte and opaque bytes (plan decision 7). A record is either the inviter's plaintext card (detached Ed25519 signature + card bytes) or a Signal ciphertext — a PreKeySignalMessage or a normal SignalMessage, which the library's own wire bytes do not tell apart.

The relay is untrusted and go.mau.fi/libsignal panics on some malformed input (ecc.DecodePoint indexes an empty slice) and accepts short or low-order keys. Check validates a record before any library call; Safe turns a panic that still escapes into an error.

Index

Constants

View Source
const MaxBody = 1 << 20

MaxBody is the cap on a record's decoded bytes (1 MiB).

SigSize is the length of the card's detached signature.

Variables

View Source
var (
	ErrType      = errors.New("envelope: unknown type")
	ErrEmpty     = errors.New("envelope: empty body")
	ErrTooLarge  = errors.New("envelope: body over 1 MiB")
	ErrBase64    = errors.New("envelope: body is not standard base64")
	ErrMalformed = errors.New("envelope: malformed")
	ErrPanic     = errors.New("envelope: library panic")
)

Functions

func CheckKey

func CheckKey(k []byte) error

CheckKey requires the serialized public-key form libsignal reads with ecc.DecodePoint: exactly 33 bytes, type 0x05, not a low-order point.

func CheckPreKeyMessage

func CheckPreKeyMessage(b []byte) error

CheckPreKeyMessage validates a PreKeySignalMessage and its inner message.

func CheckSignalMessage

func CheckSignalMessage(b []byte) error

CheckSignalMessage validates a normal Signal message.

func Safe

func Safe(fn func() error) (err error)

Safe runs fn and returns a panic inside it as an error wrapping ErrPanic. Wrap every libsignal deserialize and decrypt call that sees relay bytes.

func UnpackCard

func UnpackCard(body []byte) (card, sig []byte, err error)

UnpackCard splits a Card body into card bytes and signature. It does not verify the signature; the card package does, before parsing the bytes.

Types

type Envelope

type Envelope struct {
	Type Type
	Body []byte
}

Envelope is one relay record.

func FromWire

func FromWire(typ, body string) (Envelope, error)

FromWire decodes the contract's JSON fields and checks the result.

func PackCard

func PackCard(card, sig []byte) (Envelope, error)

PackCard builds a Card body: the detached signature, then the card bytes.

func (Envelope) Check

func (e Envelope) Check() error

Check validates the envelope against its type; a nil result means the bytes are safe to hand to the card verifier or to libsignal's deserializers.

func (Envelope) MarshalBinary

func (e Envelope) MarshalBinary() ([]byte, error)

MarshalBinary packs the envelope as its type byte followed by the body, the form for local storage (an outbox entry).

func (*Envelope) UnmarshalBinary

func (e *Envelope) UnmarshalBinary(b []byte) error

UnmarshalBinary reverses MarshalBinary and checks the result.

func (Envelope) Wire

func (e Envelope) Wire() (typ, body string)

Wire returns the contract's JSON fields: the type name and the body in standard padded base64.

type Type

type Type byte

Type is the record's type byte.

const (
	// Card is the plaintext, root-signed card (envelope #0).
	Card Type = 1
	// Prekey is a Signal PreKeySignalMessage (Signal type 3).
	Prekey Type = 2
	// Msg is a Signal SignalMessage (Signal type 2).
	Msg Type = 3
)

func ParseType

func ParseType(s string) (Type, error)

ParseType reads a wire name.

func (Type) String

func (t Type) String() string

String is the type's wire name: "card", "prekey" or "msg".

Jump to

Keyboard shortcuts

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