deviceid

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package deviceid implements Astarte's 128-bit device identifier and its canonical encodings: the 22-character unpadded base64url wire form used in MQTT topics, REST paths and certificate CNs, and the canonical UUID form used by operators and tooling.

Astarte device IDs are opaque 128-bit values. In practice they are either random (UUIDv4-shaped, `astartectl utils device-id generate-random` parity) or derived deterministically from a namespace UUID plus an arbitrary payload string via UUIDv5 (RFC 4122 §4.3, `astartectl utils device-id compute-from-string` parity).

Index

Constants

View Source
const EncodedLen = 22

EncodedLen is the length of the base64url wire form of a device ID: 16 bytes encoded as unpadded base64url.

Variables

View Source
var ErrInvalid = errors.New("invalid device ID")

ErrInvalid is wrapped by every parse failure returned from this package, so callers can classify rejection with errors.Is regardless of the specific cause (length, alphabet, canonicality, UUID syntax).

Functions

This section is empty.

Types

type ID

type ID [16]byte

ID is a 128-bit Astarte device identifier.

func FromNamespace

func FromNamespace(ns ID, payload string) ID

FromNamespace derives a deterministic device ID from a namespace UUID and an arbitrary payload string using UUIDv5 (RFC 4122 §4.3: SHA-1 over namespace bytes followed by the payload, version and variant bits forced). It produces exactly the IDs `astartectl utils device-id compute-from-string <namespace-uuid> <payload>` prints.

func FromUUID

func FromUUID(s string) (ID, error)

FromUUID parses a canonical UUID string (8-4-4-4-12 hexadecimal groups, case-insensitive) into a device ID. Non-canonical forms (braces, URN prefix, missing hyphens) are rejected.

func Parse

func Parse(s string) (ID, error)

Parse decodes the Astarte wire form of a device ID: exactly 22 characters of unpadded base64url decoding to 16 bytes. Anything else — wrong length, padding, standard-alphabet characters ('+', '/'), non-canonical trailing bits — is rejected with an error wrapping ErrInvalid.

func Random

func Random() (ID, error)

Random returns a new random device ID. The ID is UUIDv4-shaped (version and RFC 4122 variant bits set), matching what `astartectl utils device-id generate-random` and the official SDKs produce.

func (ID) String

func (id ID) String() string

String returns the 22-character unpadded base64url wire form.

func (ID) UUID

func (id ID) UUID() string

UUID returns the canonical lowercase UUID form of the device ID.

Jump to

Keyboard shortcuts

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