Skip to main content

Module device

Module device 

Source
Available on crate feature device-id only.
Expand description

Device identity: an id for “this device” that an application can store and recognise later.

A device id is not authentication. It is a claim, not proof: root or Administrator can set the machine id to anything, and hypervisors set firmware UUIDs freely. Never use it as the only check for anything that matters; for proof of a device, use a key held in a TPM or Secure Enclave. It is personal data in client software: an application storing one needs a lawful basis, a retention period, and a way to delete it. See docs/DEVICE-ID.md.

The id is a keyed BLAKE3 hash of one identifier the OS keeps, keyed by a key derived from your application id. Two applications on one machine get unrelated ids, and nobody can turn an id back into the machine id or the serial numbers behind it. The raw identifier is read into a fixed buffer, hashed, and wiped; it never appears in a return value, an error, Debug, Display, or a log.

use sys_lib as sys;

let id = sys::device::id("com.example.server")?;
println!("device {id}");
let again: sys::device::DeviceId = id.to_string().parse()?;
assert!(id.ct_eq(&again));

Structs§

Builder
See builder.
Comparison
What Fingerprint::compare found.
DeviceId
An application-specific device id: 122 bits of a keyed hash, shown as an RFC 9562 version 8 UUID. Already a keyed hash, so it is safe to show.
Fingerprint
An app-keyed 16-byte hash per anchor, or absent.
SourceStatus
One source and its state.
StabilityReport
The state of every source, with no values in it.

Enums§

Anchor
An identifier a device id or a fingerprint can rest on.
Basis
What an id is anchored to.
ChangeEvent
What would change an id.
CloneRisk
What suggests an id may be shared with other machines.
SourceState
What became of reading a source.
Verdict
Whether two fingerprints are of one machine.

Constants§

FINGERPRINT_LEN
The length of a stored fingerprint.

Functions§

builder
Options for an id or a fingerprint.
fingerprint
A Fingerprint of this device: every available anchor, hashed separately.
id
An application’s device id, from the OS installation. app is a stable, application-unique string such as a reverse domain name, 1 to 255 bytes.
report
Probes every source once. Sources only: no application id is needed, and no value appears in the result.