mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-12-05 05:50:04 +08:00
feat: implement encryption guard for secure data handling in YAML operations
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use crate::{enhance::seq::SeqMap, logging, utils::logging::Type};
|
||||
use crate::{config::EncryptionGuard, enhance::seq::SeqMap, logging, utils::logging::Type};
|
||||
use anyhow::{Context, Result, anyhow, bail};
|
||||
use nanoid::nanoid;
|
||||
use serde::{Serialize, de::DeserializeOwned};
|
||||
@@ -11,6 +11,7 @@ pub async fn read_yaml<T: DeserializeOwned>(path: &PathBuf) -> Result<T> {
|
||||
bail!("file not found \"{}\"", path.display());
|
||||
}
|
||||
|
||||
let _guard = EncryptionGuard::new();
|
||||
let yaml_str = tokio::fs::read_to_string(path).await?;
|
||||
|
||||
Ok(serde_yaml_ng::from_str::<T>(&yaml_str)?)
|
||||
@@ -65,6 +66,7 @@ pub async fn save_yaml<T: Serialize + Sync>(
|
||||
data: &T,
|
||||
prefix: Option<&str>,
|
||||
) -> Result<()> {
|
||||
let _guard = EncryptionGuard::new();
|
||||
let data_str = serde_yaml_ng::to_string(data)?;
|
||||
|
||||
let yaml_str = match prefix {
|
||||
|
||||
Reference in New Issue
Block a user