make sure no gen_keypair more than once

This commit is contained in:
csf
2022-07-29 16:30:55 +08:00
parent da2906c95f
commit 2fbcbc6543
3 changed files with 16 additions and 7 deletions

View File

@@ -584,15 +584,16 @@ impl Config {
config.store();
}
pub fn get_sk_uuid() -> Vec<u8> {
// for uuid, avoid deadlock
// * Manually make sure no gen_keypair more than once
// for uuid, avoid deadlock
pub fn get_key_pair_without_lock() -> (Vec<u8>, Vec<u8>) {
let mut config = Config::load_::<Config>("");
if config.key_pair.0.is_empty() {
let (pk, sk) = sign::gen_keypair();
config.key_pair = (sk.0.to_vec(), pk.0.into());
Config::store_(&config, "");
}
config.key_pair.1
config.key_pair.clone()
}
pub fn get_key_pair() -> (Vec<u8>, Vec<u8>) {

View File

@@ -209,9 +209,16 @@ pub fn get_modified_time(path: &std::path::Path) -> SystemTime {
fn gen_uuid() -> Vec<u8> {
#[cfg(not(any(target_os = "android", target_os = "ios")))]
if let Ok(id) = machine_uid::get() {
return id.into();
id.into()
} else {
Config::get_key_pair().1
}
Config::get_sk_uuid()
#[cfg(any(target_os = "android", target_os = "ios"))]
Config::get_key_pair_without_lock().1
}
pub fn init_uuid() {
let _ = *UUID;
}
pub fn get_uuid() -> Vec<u8> {