use crate::errors::{LicenseError, LicenseResult};
use ring::digest;
#[cfg(target_os = "linux")]
mod linux;
#[cfg(target_os = "macos")]
mod macos;
#[cfg(target_os = "windows")]
mod windows;
pub fn get_hardware_id() -> String {
let cpu_raw = get_cpu_id().unwrap_or_else(|_| "cpu_unknown".to_string());
let board_raw = get_motherboard_id().unwrap_or_else(|_| "board_unknown".to_string());
let combined = format!("{}|{}", cpu_raw, board_raw);
let digest = digest::digest(&digest::SHA256, combined.as_bytes());
hex::encode(digest)
}
fn get_cpu_id() -> LicenseResult<String> {
#[cfg(target_os = "windows")]
{
windows::get_cpu_id()
.map_err(|e| LicenseError::ServerError(format!("Win CPU ID error: {e}")))
}
#[cfg(target_os = "macos")]
{
macos::get_cpu_id()
.map_err(|e| LicenseError::ServerError(format!("macOS CPU ID error: {e}")))
}
#[cfg(target_os = "linux")]
{
linux::get_cpu_id()
.map_err(|e| LicenseError::ServerError(format!("Linux CPU ID error: {e}")))
}
}
fn get_motherboard_id() -> LicenseResult<String> {
#[cfg(target_os = "windows")]
{
windows::get_motherboard_id()
.map_err(|e| LicenseError::ServerError(format!("Win Board ID error: {e}")))
}
#[cfg(target_os = "macos")]
{
macos::get_motherboard_id()
.map_err(|e| LicenseError::ServerError(format!("macOS Board ID error: {e}")))
}
#[cfg(target_os = "linux")]
{
linux::get_motherboard_id()
.map_err(|e| LicenseError::ServerError(format!("Linux Board ID error: {e}")))
}
}