Add device HWID support to sing-box subscriptions

This commit is contained in:
2026-07-08 20:31:21 +03:00
parent 7316e932f0
commit 42b85cc8fa
12 changed files with 450 additions and 19 deletions

View File

@@ -138,6 +138,8 @@ pub struct LocalSingBoxConfig {
#[serde(default)]
pub subscription_url: Option<String>,
#[serde(default)]
pub device_hwid: Option<String>,
#[serde(default)]
pub selected_server_tag: Option<String>,
#[serde(default = "default_local_singbox_listen_host")]
pub listen_host: String,
@@ -157,12 +159,17 @@ impl LocalSingBoxConfig {
.as_deref()
.map(redact_subscription_url)
}
pub fn device_hwid_display(&self) -> Option<String> {
self.device_hwid.as_deref().map(redact_device_hwid)
}
}
impl Default for LocalSingBoxConfig {
fn default() -> Self {
Self {
subscription_url: None,
device_hwid: None,
selected_server_tag: None,
listen_host: default_local_singbox_listen_host(),
listen_port: default_local_singbox_listen_port(),
@@ -271,3 +278,27 @@ pub fn redact_subscription_url(raw_url: &str) -> String {
}
}
}
pub fn redact_device_hwid(raw_hwid: &str) -> String {
let trimmed = raw_hwid.trim();
if trimmed.is_empty() {
return String::new();
}
let length = trimmed.chars().count();
if length <= 8 {
return "***".to_string();
}
let prefix = trimmed.chars().take(4).collect::<String>();
let suffix = trimmed
.chars()
.rev()
.take(4)
.collect::<String>()
.chars()
.rev()
.collect::<String>();
format!("{prefix}...{suffix}")
}