From 8d9dded968d270adc97dc3274bbed27e26e968ba Mon Sep 17 00:00:00 2001 From: Stanimal Date: Sun, 28 Nov 2021 12:20:04 +0400 Subject: [PATCH] fix: use json 5 for tor identity --- Cargo.lock | 2 +- applications/tari_app_utilities/Cargo.toml | 2 +- .../tari_app_utilities/src/identity_management.rs | 14 ++++++-------- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 730b9ef7f5..caa7719ce2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4539,7 +4539,7 @@ dependencies = [ "log", "qrcode", "rand 0.8.4", - "serde_json", + "serde 1.0.130", "structopt", "strum 0.19.5", "strum_macros 0.19.4", diff --git a/applications/tari_app_utilities/Cargo.toml b/applications/tari_app_utilities/Cargo.toml index ae6d9c9d1f..d4f64bc4c7 100644 --- a/applications/tari_app_utilities/Cargo.toml +++ b/applications/tari_app_utilities/Cargo.toml @@ -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" diff --git a/applications/tari_app_utilities/src/identity_management.rs b/applications/tari_app_utilities/src/identity_management.rs index 7dc6458b5f..086d35c672 100644 --- a/applications/tari_app_utilities/src/identity_management.rs +++ b/applications/tari_app_utilities/src/identity_management.rs @@ -22,6 +22,7 @@ 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}, @@ -29,10 +30,7 @@ use tari_common::{ }; 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"; @@ -194,7 +192,7 @@ pub fn recover_node_identity>( /// /// ## Returns /// Result containing an object on success, string will indicate reason on error -pub fn load_from_json, T: MessageFormat>(path: P) -> Result { +pub fn load_from_json, T: DeserializeOwned>(path: P) -> Result { if !path.as_ref().exists() { return Err(format!( "Identity file, {}, does not exist.", @@ -203,7 +201,7 @@ pub fn load_from_json, T: MessageFormat>(path: P) -> Result, T: MessageFormat>(path: P) -> Result, T: MessageFormat>(path: P, object: &T) -> Result<(), String> { - let json = object.to_json().unwrap(); +pub fn save_as_json, 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()))?;