From a5ef9c1c0e0293d98b430887eaa56241d7f990f2 Mon Sep 17 00:00:00 2001 From: vicanso Date: Sun, 29 Dec 2024 11:11:48 +0800 Subject: [PATCH] refactor: use crc32 hash for secret description --- src/config/common.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/config/common.rs b/src/config/common.rs index bbcb866..bd69b8a 100644 --- a/src/config/common.rs +++ b/src/config/common.rs @@ -899,17 +899,28 @@ impl PingapConf { }); } for (name, data) in value.certificates.iter() { + let mut clone_data = data.clone(); + if let Some(cert) = &clone_data.tls_cert { + clone_data.tls_cert = Some(format!("crc32:{:X}", crc32fast::hash(cert.as_bytes()))); + } + if let Some(key) = &clone_data.tls_key { + clone_data.tls_key = Some(format!("crc32:{:X}", crc32fast::hash(key.as_bytes()))); + } descriptions.push(Description { category: CATEGORY_CERTIFICATE.to_string(), name: format!("certificate:{name}"), - data: toml::to_string_pretty(data).unwrap_or_default(), + data: toml::to_string_pretty(&clone_data).unwrap_or_default(), }); } for (name, data) in value.storages.iter() { + let mut clone_data = data.clone(); + if let Some(secret) = &clone_data.secret { + clone_data.secret = Some(format!("crc32:{:X}", crc32fast::hash(secret.as_bytes()))); + } descriptions.push(Description { category: CATEGORY_STORAGE.to_string(), name: format!("storage:{name}"), - data: toml::to_string_pretty(data).unwrap_or_default(), + data: toml::to_string_pretty(&clone_data).unwrap_or_default(), }); } value.servers = HashMap::new();