address

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package address provides types identifying an individual Signal client instance: service IDs (ACI/PNI), device IDs, and protocol addresses.

It is a pure-Go port of rust/core/src/address.rs; the binary and string encodings are wire-compatible with upstream libsignal.

Index

Constants

View Source
const MaxValidDeviceID = 127

MaxValidDeviceID is the largest value a DeviceID may hold. Device IDs are constrained to the range 1..=127.

View Source
const ServiceIDFixedWidthBinaryLen = 17

ServiceIDFixedWidthBinaryLen is the length of the fixed-width binary representation of a service ID: a one-byte kind tag followed by the 16-byte raw UUID.

View Source
const UUIDLen = 16

UUIDLen is the length of the raw UUID inside a service ID.

Variables

View Source
var ErrInvalidDeviceID = errors.New("device ID is out of range")

ErrInvalidDeviceID is returned when constructing a DeviceID from a value outside the valid range 1..=127.

View Source
var ErrInvalidServiceID = errors.New("invalid service ID")

ErrInvalidServiceID is returned when parsing fails for any of the standard service-ID representations.

Functions

This section is empty.

Types

type DeviceID

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

DeviceID identifies a particular Signal client instance for some user. Valid device IDs are in the range 1..=127.

func NewDeviceID

func NewDeviceID(id uint32) (DeviceID, error)

NewDeviceID constructs a DeviceID if id is in the valid range 1..=127, returning ErrInvalidDeviceID otherwise.

func (DeviceID) String

func (d DeviceID) String() string

String implements fmt.Stringer, rendering the numeric device ID.

func (DeviceID) Value

func (d DeviceID) Value() uint32

Value returns the device ID as a uint32.

type ErrWrongKindOfServiceID

type ErrWrongKindOfServiceID struct {
	Expected ServiceIDKind
	Actual   ServiceIDKind
}

ErrWrongKindOfServiceID is returned when downcasting a ServiceID to a specific kind (via ServiceID.ACI or ServiceID.PNI) and the actual kind does not match the expected kind.

func (ErrWrongKindOfServiceID) Error

func (e ErrWrongKindOfServiceID) Error() string

type ProtocolAddress

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

ProtocolAddress represents a unique Signal client instance as a (name, device ID) pair, where name is a user's globally-unique public identity (usually a service-ID string).

func NewProtocolAddress

func NewProtocolAddress(name string, deviceID DeviceID) ProtocolAddress

NewProtocolAddress creates a new address from a user identity name and a device ID.

func (ProtocolAddress) DeviceID

func (a ProtocolAddress) DeviceID() DeviceID

DeviceID returns the device identifier component of the address.

func (ProtocolAddress) Name

func (a ProtocolAddress) Name() string

Name returns the user identity name. This is usually a service-ID string.

func (ProtocolAddress) String

func (a ProtocolAddress) String() string

String implements fmt.Stringer, rendering the address as "name.deviceID".

type ServiceID

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

ServiceID is a Signal service ID, which can be one of various kinds.

Conceptually it is a UUID in a particular "namespace" representing a particular way to reach a user on the Signal service.

func NewACI

func NewACI(uuid [UUIDLen]byte) ServiceID

NewACI constructs an ACI service ID from a raw UUID.

func NewPNI

func NewPNI(uuid [UUIDLen]byte) ServiceID

NewPNI constructs a PNI service ID from a raw UUID.

func ParseServiceIDBinary

func ParseServiceIDBinary(b []byte) (ServiceID, error)

ParseServiceIDBinary parses the standard variable-width binary representation. A 16-byte input is an ACI; a 17-byte input is the fixed-width form, but it is an error for the fixed-width form to carry the ACI tag (ACIs are unmarked in the variable-width format).

func ParseServiceIDFixedWidthBinary

func ParseServiceIDFixedWidthBinary(b [ServiceIDFixedWidthBinaryLen]byte) (ServiceID, error)

ParseServiceIDFixedWidthBinary parses the standard fixed-width binary representation, rejecting unknown kind tags.

func ParseServiceIDString

func ParseServiceIDString(input string) (ServiceID, error)

ParseServiceIDString parses the standard string representation. UUID parsing is case-insensitive and accepts only the hyphenated form. A "PNI:" prefix selects a PNI; any other input is parsed as a bare ACI UUID.

func (ServiceID) ACI

func (s ServiceID) ACI() (ServiceID, error)

ACI returns the service ID as an ACI, or an ErrWrongKindOfServiceID error if it is not an ACI.

func (ServiceID) Compare

func (s ServiceID) Compare(other ServiceID) int

Compare returns -1, 0, or +1 reporting whether s sorts before, equal to, or after other. The ordering matches the fixed-width binary ordering used by upstream (kind tag first, then UUID bytes).

func (ServiceID) Kind

func (s ServiceID) Kind() ServiceIDKind

Kind reports which kind of service ID this is.

func (ServiceID) LogString

func (s ServiceID) LogString() string

LogString returns the redacted-free debug form "<KIND:uuid>", matching the upstream Debug formatting used in logs.

func (ServiceID) PNI

func (s ServiceID) PNI() (ServiceID, error)

PNI returns the service ID as a PNI, or an ErrWrongKindOfServiceID error if it is not a PNI.

func (ServiceID) RawUUID

func (s ServiceID) RawUUID() [UUIDLen]byte

RawUUID returns the raw 16-byte UUID inside this service ID, discarding the kind.

func (ServiceID) ServiceIDBinary

func (s ServiceID) ServiceIDBinary() []byte

ServiceIDBinary returns the standard variable-width binary representation.

This format is not self-delimiting; the length is needed to decode it. An ACI is encoded as its raw 16-byte UUID; any other kind is encoded as the 17-byte fixed-width form.

func (ServiceID) ServiceIDFixedWidthBinary

func (s ServiceID) ServiceIDFixedWidthBinary() [ServiceIDFixedWidthBinaryLen]byte

ServiceIDFixedWidthBinary returns the standard fixed-width binary representation: a one-byte kind tag followed by the raw UUID.

func (ServiceID) ServiceIDString

func (s ServiceID) ServiceIDString() string

ServiceIDString returns the standard string representation. An ACI is rendered as a bare hyphenated UUID; any other kind is prefixed with its kind and a colon (e.g. "PNI:...").

func (ServiceID) String

func (s ServiceID) String() string

String implements fmt.Stringer using the standard string representation.

func (ServiceID) ToProtocolAddress

func (s ServiceID) ToProtocolAddress(deviceID DeviceID) ProtocolAddress

ToProtocolAddress constructs a ProtocolAddress from this service ID and a device ID.

type ServiceIDKind

type ServiceIDKind uint8

ServiceIDKind enumerates the known kinds of ServiceID.

const (
	// ServiceIDKindACI identifies an ACI ("ACcount Identifier").
	ServiceIDKindACI ServiceIDKind = 0
	// ServiceIDKindPNI identifies a PNI ("Phone Number Identifier").
	ServiceIDKindPNI ServiceIDKind = 1
)

func (ServiceIDKind) String

func (k ServiceIDKind) String() string

String returns the canonical short name of the kind ("ACI" or "PNI").

Jump to

Keyboard shortcuts

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