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
- Variables
- type DeviceID
- type ErrWrongKindOfServiceID
- type ProtocolAddress
- type ServiceID
- func (s ServiceID) ACI() (ServiceID, error)
- func (s ServiceID) Compare(other ServiceID) int
- func (s ServiceID) Kind() ServiceIDKind
- func (s ServiceID) LogString() string
- func (s ServiceID) PNI() (ServiceID, error)
- func (s ServiceID) RawUUID() [UUIDLen]byte
- func (s ServiceID) ServiceIDBinary() []byte
- func (s ServiceID) ServiceIDFixedWidthBinary() [ServiceIDFixedWidthBinaryLen]byte
- func (s ServiceID) ServiceIDString() string
- func (s ServiceID) String() string
- func (s ServiceID) ToProtocolAddress(deviceID DeviceID) ProtocolAddress
- type ServiceIDKind
Constants ¶
const MaxValidDeviceID = 127
MaxValidDeviceID is the largest value a DeviceID may hold. Device IDs are constrained to the range 1..=127.
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.
const UUIDLen = 16
UUIDLen is the length of the raw UUID inside a service ID.
Variables ¶
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.
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 ¶
NewDeviceID constructs a DeviceID if id is in the valid range 1..=127, returning ErrInvalidDeviceID otherwise.
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 ParseServiceIDBinary ¶
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 ¶
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 ¶
ACI returns the service ID as an ACI, or an ErrWrongKindOfServiceID error if it is not an ACI.
func (ServiceID) Compare ¶
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 ¶
LogString returns the redacted-free debug form "<KIND:uuid>", matching the upstream Debug formatting used in logs.
func (ServiceID) PNI ¶
PNI returns the service ID as a PNI, or an ErrWrongKindOfServiceID error if it is not a PNI.
func (ServiceID) RawUUID ¶
RawUUID returns the raw 16-byte UUID inside this service ID, discarding the kind.
func (ServiceID) ServiceIDBinary ¶
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 ¶
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) 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").