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

remove md5 in rust code #217

Merged
merged 2 commits into from
Dec 23, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions src-tauri/Cargo.lock

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

1 change: 0 additions & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
13 changes: 1 addition & 12 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[macro_use]
extern crate lazy_static;
use std::{collections::HashMap, fs};
use std::{collections::HashMap};

use tauri::Manager;
use track3::{
Expand Down Expand Up @@ -131,16 +131,6 @@ fn decrypt(data: String) -> Result<String, String> {
}
}

#[cfg_attr(
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
)]
#[tauri::command]
fn md5(data: String) -> Result<String, String> {
let digest = md5::compute(data.as_bytes());
Ok(format!("{:x}", digest))
}

#[cfg_attr(
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
Expand Down Expand Up @@ -225,7 +215,6 @@ fn main() {
query_okex_balance,
encrypt,
decrypt,
md5,
download_coins_logos,
open_debank_window_in_background,
close_debank_window,
Expand Down
16 changes: 10 additions & 6 deletions src/middlelayers/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ 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
configuration?: string
historicalData: Pick<HistoricalData, "createdAt" | "assets" | "total">[]
md5: string
md5V2: string
}

// TODO: query by token address not symbol, because there are multiple coins with same symbol
Expand Down Expand Up @@ -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<string>("md5", { data: JSON.stringify(exportData) }),
md5V2: md5(JSON.stringify(md5Payload)),
} as ExportData)

// save to filePath
Expand All @@ -126,14 +129,15 @@ export async function importHistoricalData(): Promise<boolean> {
}
const contents = await readTextFile(selected as string)

const { exportAt, md5, 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 (md5) {
if (md5Str) {
// verify md5
// todo: use md5 in typescript
const currentMd5 = await invoke<string>("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")
}
}
Expand Down
Loading