Skip to content
Snippets Groups Projects
Verified Commit 07012f5a authored by Korben Tompkin's avatar Korben Tompkin :mortar_board:
Browse files

feat(server): Hashing

parent 83763a5e
No related branches found
No related tags found
1 merge request!3feat(server): Server implementation
......@@ -1293,9 +1293,11 @@ name = "server"
version = "0.1.0"
dependencies = [
"axum",
"hex",
"serde",
"serde_json",
"sqlx",
"tiger",
"tokio",
]
......@@ -1656,6 +1658,15 @@ dependencies = [
"syn",
]
[[package]]
name = "tiger"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "579abbce4ad73b04386dbeb34369c9873a8f9b749c7b99cbf479a2949ff715ed"
dependencies = [
"digest",
]
[[package]]
name = "tinystr"
version = "0.7.6"
......
......@@ -5,7 +5,9 @@ edition = "2021"
[dependencies]
axum = "0.8.1"
hex = "0.4.3"
serde = "1.0.217"
serde_json = "1.0.138"
sqlx = { version = "0.8.3", features = ["runtime-tokio"] }
tiger = "0.2.1"
tokio = { version = "1.43.0", features = ["macros", "rt-multi-thread"] }
......@@ -4,9 +4,11 @@ use axum::{
routing::{get, post},
Router,
};
use hex;
use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
use std::{collections::HashMap, fs};
use tiger::{Digest, Tiger};
use tokio;
#[derive(Serialize, Deserialize)]
......@@ -42,8 +44,20 @@ async fn search(Path(query): Path<String>) -> Result<Json<Value>, StatusCode> {
Err(_) => String::from(""),
};
let ed: ED = ED {
db: serde_json::from_str(&data_string).unwrap(),
db: {
if let Ok(db) = serde_json::from_str(&data_string) {
db
} else {
return Err(StatusCode::INTERNAL_SERVER_ERROR);
}
},
};
println!("{:#?}", ed.db);
Ok(Json(json!({query: ""})))
let ids: HashMap<&String, &String> = ed.db.iter().filter(|(k, _)| k.contains(&query)).collect();
Ok(Json(json!(ids)))
}
async fn hash(plaintext: String) -> String {
let mut hf = Tiger::new();
hf.update(plaintext.as_bytes());
hex::encode(hf.finalize().as_slice())
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment