Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use json 5 for tor identity (regression) #3624

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion applications/tari_app_utilities/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ config = { version = "0.9.3" }
futures = { version = "^0.3.16", default-features = false, features = ["alloc"] }
qrcode = { version = "0.12" }
dirs-next = "1.0.2"
serde_json = "1.0"
serde = "1.0.126"
json5 = "0.2.2"
log = { version = "0.4.8", features = ["std"] }
rand = "0.8"
Expand Down
14 changes: 6 additions & 8 deletions applications/tari_app_utilities/src/identity_management.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,15 @@

use log::*;
use rand::rngs::OsRng;
use serde::{de::DeserializeOwned, Serialize};
use std::{clone::Clone, fs, path::Path, str::FromStr, string::ToString, sync::Arc};
use tari_common::{
configuration::{bootstrap::prompt, utils::get_local_ip},
exit_codes::ExitCodes,
};
use tari_common_types::types::PrivateKey;
use tari_comms::{multiaddr::Multiaddr, peer_manager::PeerFeatures, NodeIdentity};
use tari_crypto::{
keys::SecretKey,
tari_utilities::{hex::Hex, message_format::MessageFormat},
};
use tari_crypto::{keys::SecretKey, tari_utilities::hex::Hex};

pub const LOG_TARGET: &str = "tari_application";

Expand Down Expand Up @@ -194,7 +192,7 @@ pub fn recover_node_identity<P: AsRef<Path>>(
///
/// ## Returns
/// Result containing an object on success, string will indicate reason on error
pub fn load_from_json<P: AsRef<Path>, T: MessageFormat>(path: P) -> Result<T, String> {
pub fn load_from_json<P: AsRef<Path>, T: DeserializeOwned>(path: P) -> Result<T, String> {
if !path.as_ref().exists() {
return Err(format!(
"Identity file, {}, does not exist.",
Expand All @@ -203,7 +201,7 @@ pub fn load_from_json<P: AsRef<Path>, T: MessageFormat>(path: P) -> Result<T, St
}

let contents = fs::read_to_string(path).map_err(|err| err.to_string())?;
let object = T::from_json(&contents).map_err(|err| err.to_string())?;
let object = json5::from_str(&contents).map_err(|err| err.to_string())?;
Ok(object)
}

Expand All @@ -214,8 +212,8 @@ pub fn load_from_json<P: AsRef<Path>, T: MessageFormat>(path: P) -> Result<T, St
///
/// ## Returns
/// Result to check if successful or not, string will indicate reason on error
pub fn save_as_json<P: AsRef<Path>, T: MessageFormat>(path: P, object: &T) -> Result<(), String> {
let json = object.to_json().unwrap();
pub fn save_as_json<P: AsRef<Path>, T: Serialize>(path: P, object: &T) -> Result<(), String> {
let json = json5::to_string(object).unwrap();
if let Some(p) = path.as_ref().parent() {
if !p.exists() {
fs::create_dir_all(p).map_err(|e| format!("Could not save json to data folder. {}", e.to_string()))?;
Expand Down