password: ensure encrypt only once

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages
2022-07-27 21:30:02 +08:00
parent 9f22f55a1f
commit 551bf5030b
2 changed files with 55 additions and 28 deletions

View File

@@ -218,7 +218,8 @@ impl Config2 {
fn load() -> Config2 {
let mut config = Config::load_::<Config2>("2");
if let Some(mut socks) = config.socks {
let (password, store) = decrypt_str_or_original(&socks.password, PASSWORD_ENC_VERSION);
let (password, _, store) =
decrypt_str_or_original(&socks.password, PASSWORD_ENC_VERSION);
socks.password = password;
config.socks = Some(socks);
if store {
@@ -298,7 +299,7 @@ impl Config {
fn load() -> Config {
let mut config = Config::load_::<Config>("");
let (password, store) = decrypt_str_or_original(&config.password, PASSWORD_ENC_VERSION);
let (password, _, store) = decrypt_str_or_original(&config.password, PASSWORD_ENC_VERSION);
config.password = password;
if store {
config.store();
@@ -754,17 +755,17 @@ impl PeerConfig {
Ok(config) => {
let mut config: PeerConfig = config;
let mut store = false;
let (password, store2) =
let (password, _, store2) =
decrypt_vec_or_original(&config.password, PASSWORD_ENC_VERSION);
config.password = password;
store = store || store2;
config.options.get_mut("rdp_password").map(|v| {
let (password, store2) = decrypt_str_or_original(v, PASSWORD_ENC_VERSION);
let (password, _, store2) = decrypt_str_or_original(v, PASSWORD_ENC_VERSION);
*v = password;
store = store || store2;
});
config.options.get_mut("os-password").map(|v| {
let (password, store2) = decrypt_str_or_original(v, PASSWORD_ENC_VERSION);
let (password, _, store2) = decrypt_str_or_original(v, PASSWORD_ENC_VERSION);
*v = password;
store = store || store2;
});