Documentation
¶
Index ¶
- func GenerateDeviceID(opts Options) (string, error)
- func GenerateDeviceIDFromInfo(info *SystemInfo, opts Options) (string, error)
- func GenerateReversibleID(opts Options) (string, error)
- func GetPrefix(opts PrefixOptions) (string, error)
- func GetPrefixedDeviceID(prefixOpts PrefixOptions, deviceOpts Options) (string, error)
- func GetShortDeviceID(opts Options) (string, error)
- type Collector
- type IDComparison
- type Options
- type PrefixOptions
- type ReversibleDeviceInfo
- type StructuredDeviceID
- type SystemInfo
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateDeviceID ¶
GenerateDeviceID generates a unique device ID based on system information
Example ¶
// Generate a device ID with default options
opts := DefaultOptions()
deviceID, err := GenerateDeviceID(opts)
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
fmt.Printf("Device ID: %s\n", deviceID[:16]+"...")
// Generate with custom options
customOpts := Options{
IncludeMAC: true,
IncludeMachineID: true,
Salt: "my-app-v1.0",
}
customID, err := GenerateDeviceID(customOpts)
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
fmt.Printf("Custom Device ID: %s\n", customID[:16]+"...")
Example (Irreversible) ¶
// Generate an irreversible device ID
deviceID, _ := GenerateDeviceID(DefaultOptions())
fmt.Printf("SHA256 Device ID: %s\n", deviceID[:16]+"...")
// This ID cannot be reversed to get system info
// You can only verify by regenerating with same system
// For visible info, use structured ID
structured, _ := GenerateStructuredID(PrefixOptions{Hostname: true}, DefaultOptions())
fmt.Printf("Structured ID: %s\n", structured.ToString())
// Output might be: mir-laptop-f282b622a980dca4
func GenerateDeviceIDFromInfo ¶
func GenerateDeviceIDFromInfo(info *SystemInfo, opts Options) (string, error)
GenerateDeviceIDFromInfo generates a device ID from provided system info
func GenerateReversibleID ¶
GenerateReversibleID creates an encoded device ID that can be decoded WARNING: This reveals system information and should only be used when necessary
func GetPrefix ¶
func GetPrefix(opts PrefixOptions) (string, error)
func GetPrefixedDeviceID ¶
func GetPrefixedDeviceID(prefixOpts PrefixOptions, deviceOpts Options) (string, error)
GetPrefixedDeviceID generates a device ID with an optional prefix This is a convenience function that combines GetPrefix and device ID generation
func GetShortDeviceID ¶
GetShortDeviceID returns a shorter version of the device ID (first 16 characters)
Types ¶
type Collector ¶
type Collector interface {
GetMACAddresses() ([]string, error)
GetCPUInfo() (string, error)
GetOSInfo() (osType, osVersion, osArch string, err error)
GetHostname() (string, error)
GetMachineID() (string, error)
GetSerialNumber() (string, error)
GetProductUUID() (string, error)
GetBoardSerial() (string, error)
GetDiskSerials() ([]string, error)
GetUsername() (string, error)
GetHomeDir() (string, error)
}
Collector interface for platform-specific implementations
type IDComparison ¶
type IDComparison struct {
// What we can determine from hashed IDs
Identical bool `json:"identical"`
// What we can determine from structured IDs
SameHostname *bool `json:"same_hostname,omitempty"`
}
CompareDeviceIDs compares two device IDs and returns what can be determined
func CompareIDs ¶
func CompareIDs(id1, id2 string) IDComparison
CompareIDs compares two device IDs and returns what can be determined
type Options ¶
type Options struct {
// Include network interfaces (IncludeMAC addresses)
IncludeMAC bool
// Include CPU information
IncludeCPU bool
// Include OS information
IncludeOS bool
// Include disk serials
IncludeDisk bool
// Include user information
IncludeUser bool
// Include machine-specific IDs
IncludeMachineID bool
// Include hostname
IncludeHostname bool
// Custom salt for ID generation
Salt string
// Leave the ID in plain text
Plain bool
}
Options for device ID generation
func DefaultOptions ¶
func DefaultOptions() Options
DefaultOptions returns options with all identifiers enabled
func DefaultUniqueOptions ¶
func DefaultUniqueOptions() Options
DefaultUniqueOptions returns options with MAC, MachineID, and Hostname enabled
type PrefixOptions ¶
type ReversibleDeviceInfo ¶
type ReversibleDeviceInfo struct {
Version int `json:"v"`
MACAddresses []string `json:"mac,omitempty"`
CPUInfo string `json:"cpu,omitempty"`
OSInfo struct {
Type string `json:"type"`
Version string `json:"ver"`
Arch string `json:"arch"`
} `json:"os"`
Hostname string `json:"host,omitempty"`
}
ReversibleDeviceInfo contains system information that can be encoded/decoded
func DecodeReversibleID ¶
func DecodeReversibleID(encodedID string) (*ReversibleDeviceInfo, error)
DecodeReversibleID decodes a reversible device ID back to system information
type StructuredDeviceID ¶
type StructuredDeviceID struct {
// Visible components
Prefix string `json:"prefix"`
// Hashed unique identifier (irreversible)
UniqueHash string `json:"hash"`
}
StructuredDeviceID represents a device ID that contains visible, parseable information
func GenerateStructuredID ¶
func GenerateStructuredID(prefixOpts PrefixOptions, opts Options) (*StructuredDeviceID, error)
GenerateStructuredID creates a device ID with both visible and hashed components
func ParseStructuredID ¶
func ParseStructuredID(id string) (*StructuredDeviceID, error)
ParseStructuredID parses a structured ID string
func (*StructuredDeviceID) ToString ¶
func (s *StructuredDeviceID) ToString() string
ToString converts the structured ID to a string format
type SystemInfo ¶
type SystemInfo struct {
// Hardware identifiers
MACAddresses []string `json:"mac_addresses"`
CPUInfo string `json:"cpu_info"`
// OS identifiers
OSType string `json:"os_type"`
OSVersion string `json:"os_version"`
OSArchitecture string `json:"os_architecture"`
Hostname string `json:"hostname"`
// System identifiers
MachineID string `json:"machine_id"`
SerialNumber string `json:"serial_number"`
ProductUUID string `json:"product_uuid"`
BoardSerial string `json:"board_serial"`
// Disk identifiers
DiskSerials []string `json:"disk_serials"`
// Additional identifiers
Username string `json:"username"`
HomeDir string `json:"home_dir"`
}
SystemInfo contains various system identifiers
func GetSystemInfo ¶
func GetSystemInfo() (*SystemInfo, error)
GetSystemInfo collects all available system information
Example ¶
info, err := GetSystemInfo()
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
fmt.Printf("OS: %s %s (%s)\n", info.OSType, info.OSVersion, info.OSArchitecture)
fmt.Printf("Hostname: %s\n", info.Hostname)
fmt.Printf("MAC Addresses: %d found\n", len(info.MACAddresses))