fn store_local_key()

in proxy_agent/src/key_keeper.rs [608:642]


    fn store_local_key(key_dir: &Path, key: &Key, encrypted: bool) -> Result<()> {
        let guid = key.guid.to_string();
        let mut key_file = key_dir.to_path_buf().join(guid);
        if encrypted {
            key_file.set_extension("encrypted");
            #[cfg(windows)]
            {
                crate::common::store_key_data(
                    &key_file,
                    serde_json::to_string(&key).map_err(|e| {
                        Error::Key(KeyErrorType::StoreLocalKey(format!(
                            "serialize key error: {:?} ",
                            e
                        )))
                    })?,
                )
            }
            #[cfg(not(windows))]
            {
                // return NotSupported error for non-windows platform
                Err(Error::Key(KeyErrorType::StoreLocalKey(
                    "Not supported to store encrypted key on non-windows platform.".to_string(),
                )))
            }
        } else {
            key_file.set_extension("key");
            misc_helpers::json_write_to_file(&key, &key_file).map_err(|e| {
                Error::Key(KeyErrorType::StoreLocalKey(format!(
                    "json_write_to_file '{}' failed {}",
                    key_file.display(),
                    e
                )))
            })
        }
    }