From 1b2fd160bcc3288cab9863e6c27af31cc2ca8053 Mon Sep 17 00:00:00 2001 From: readme-bot Date: Sat, 23 Dec 2023 17:34:47 +0800 Subject: [PATCH 1/2] remove md5 in rust code --- src-tauri/Cargo.lock | 7 ------- src-tauri/Cargo.toml | 1 - src-tauri/src/main.rs | 13 +------------ src/middlelayers/data.ts | 14 +++++++++----- 4 files changed, 10 insertions(+), 25 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 11f294f..bc0895c 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -1998,12 +1998,6 @@ dependencies = [ "opaque-debug", ] -[[package]] -name = "md5" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "490cc448043f947bae3cbee9c203358d62dbee0db12107a74be5c30ccfd09771" - [[package]] name = "memchr" version = "2.5.0" @@ -4361,7 +4355,6 @@ dependencies = [ "coingecko", "lazy_static", "magic-crypt", - "md5", "okex", "rand 0.3.23", "reqwest", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index c97e71f..0202afd 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -27,7 +27,6 @@ tauri = {version = "1.2", features = ["app-all", "dialog-open", "dialog-save", " tokio = {version = "1", features = ["sync"] } uuid = "1.3.3" tauri-plugin-aptabase = "0.3" -md5 = "0.7.0" reqwest = "0.11.22" [features] diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 938c0db..b588f04 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -1,6 +1,6 @@ #[macro_use] extern crate lazy_static; -use std::{collections::HashMap, fs}; +use std::{collections::HashMap}; use tauri::Manager; use track3::{ @@ -131,16 +131,6 @@ fn decrypt(data: String) -> Result { } } -#[cfg_attr( - all(not(debug_assertions), target_os = "windows"), - windows_subsystem = "windows" -)] -#[tauri::command] -fn md5(data: String) -> Result { - let digest = md5::compute(data.as_bytes()); - Ok(format!("{:x}", digest)) -} - #[cfg_attr( all(not(debug_assertions), target_os = "windows"), windows_subsystem = "windows" @@ -225,7 +215,6 @@ fn main() { query_okex_balance, encrypt, decrypt, - md5, download_coins_logos, open_debank_window_in_background, close_debank_window, diff --git a/src/middlelayers/data.ts b/src/middlelayers/data.ts index 6d523eb..576718e 100644 --- a/src/middlelayers/data.ts +++ b/src/middlelayers/data.ts @@ -16,6 +16,7 @@ import { AssetPriceModel, ExportAssetModel, HistoricalData } from './types' import { exportConfigurationString, importRawConfiguration } from './configuration' import { ASSET_HANDLER } from './entities/assets' import { ASSET_PRICE_HANDLER } from './entities/asset-prices' +import md5 from 'md5' type ExportData = { exportAt: string @@ -102,9 +103,11 @@ export async function exportHistoricalData(exportConfiguration = false): Promise configuration: cfg } + const md5Payload = { data: JSON.stringify(exportData) } + const content = JSON.stringify({ ...exportData, - md5: await invoke("md5", { data: JSON.stringify(exportData) }), + md5: md5(JSON.stringify(md5Payload)), } as ExportData) // save to filePath @@ -126,14 +129,15 @@ export async function importHistoricalData(): Promise { } const contents = await readTextFile(selected as string) - const { exportAt, md5, configuration, historicalData } = JSON.parse(contents) as ExportData + const { exportAt, md5: md5Str, configuration, historicalData } = JSON.parse(contents) as ExportData // !compatible with older versions logic ( before 0.3.3 ) - if (md5) { + if (md5Str) { // verify md5 // todo: use md5 in typescript - const currentMd5 = await invoke("md5", { data: JSON.stringify({ exportAt, historicalData, configuration }) }) - if (currentMd5 !== md5) { + const md5Payload = { data: JSON.stringify({ exportAt, historicalData, configuration }) } + const currentMd5 = md5(JSON.stringify(md5Payload)) + if (currentMd5 !== md5Str) { throw new Error("invalid data, md5 check failed: errorCode 000") } } From d31e1b1c476cc0b04a2a6e490ac47b972ee8cb7c Mon Sep 17 00:00:00 2001 From: readme-bot Date: Sat, 23 Dec 2023 17:42:48 +0800 Subject: [PATCH 2/2] remove md5 in rust code --- src/middlelayers/data.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/middlelayers/data.ts b/src/middlelayers/data.ts index 576718e..34dad51 100644 --- a/src/middlelayers/data.ts +++ b/src/middlelayers/data.ts @@ -22,7 +22,7 @@ type ExportData = { exportAt: string configuration?: string historicalData: Pick[] - md5: string + md5V2: string } // TODO: query by token address not symbol, because there are multiple coins with same symbol @@ -107,7 +107,7 @@ export async function exportHistoricalData(exportConfiguration = false): Promise const content = JSON.stringify({ ...exportData, - md5: md5(JSON.stringify(md5Payload)), + md5V2: md5(JSON.stringify(md5Payload)), } as ExportData) // save to filePath @@ -129,7 +129,7 @@ export async function importHistoricalData(): Promise { } const contents = await readTextFile(selected as string) - const { exportAt, md5: md5Str, configuration, historicalData } = JSON.parse(contents) as ExportData + const { exportAt, md5V2: md5Str, configuration, historicalData } = JSON.parse(contents) as ExportData // !compatible with older versions logic ( before 0.3.3 ) if (md5Str) {