Documentation
¶
Overview ¶
Package identity owns typed identifiers that span subsystems — server-id today; potential future device-id, paired-device-id — and the bootstrap of those identifiers from disk. The pure types and validation live next to the I/O wrapper that mints and persists them on first run.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidServerID = errors.New("identity: invalid server id")
ErrInvalidServerID indicates a string failed canonical UUIDv4 validation. Errors returned from ParseServerID match this with errors.Is.
Functions ¶
This section is empty.
Types ¶
type ServerID ¶
type ServerID string
ServerID is the public routing identifier for one pyrycode-binary instance. Canonical form is a UUIDv4 lowercase hex string (8-4-4-4-12, 36 chars). Surfaced on the wire in pairing payloads and in the relay handshake's x-pyrycode-server header.
The empty ServerID ("") is the unset sentinel and is never a valid generated id. Construct ServerID values only via NewServerID or ParseServerID; do not convert raw strings to ServerID outside this package.
func LoadOrCreate ¶
LoadOrCreate returns the ServerID stored at path, generating and persisting a fresh one if path does not exist.
The caller is responsible for resolving the absolute path (typically ~/.pyry/server-id from config); LoadOrCreate operates on absolute paths so tests can use t.TempDir().
On first run (path does not exist), the parent directory is created with mode 0700 if missing, a fresh UUIDv4 is minted via NewServerID, written atomically (sibling temp file + rename) with mode 0600 and a single trailing newline, and returned.
On subsequent runs (path exists), the file is read and validated via ParseServerID. A single trailing newline is tolerated; any other deviation from canonical UUIDv4 form returns an error matching ErrInvalidServerID via errors.Is. The file is NEVER overwritten on the existing-file path, even on validation failure — paired devices bind their tokens to a specific server-id, and silently regenerating would invalidate every pairing without operator awareness. Errors include the path for operator diagnostics; file contents are not included to avoid future log-leak risk.
LoadOrCreate is not safe for concurrent use against the same path; bootstrap runs once on daemon startup before any goroutines fan out. Two pyry processes sharing a HOME directory is a misconfiguration outside this loader's contract.
func NewServerID ¶
func NewServerID() ServerID
NewServerID returns a fresh UUIDv4-shaped ServerID drawn from crypto/rand.
crypto/rand.Read is documented as infallible on supported platforms. If the system rng is unavailable we panic — silently degrading to a zero-entropy id would break the unguessability that the relay-routing security model depends on.
func ParseServerID ¶
ParseServerID validates that s is a canonical UUIDv4 string and returns it as a ServerID. Returns ErrInvalidServerID for empty or malformed input. Use this at every wire/disk boundary that accepts an externally-supplied server-id.