From: Greg Burri Date: Wed, 7 Aug 2019 21:15:24 +0000 (+0200) Subject: Use the key file to decipher the message given as http parameter. X-Git-Url: https://git.euphorik.ch/?a=commitdiff_plain;h=80abdea74b5741e7855756b854966f55b6c864e5;p=rup.git Use the key file to decipher the message given as http parameter. --- diff --git a/src/main.rs b/src/main.rs index 2480260..6ecbb0a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,11 +29,11 @@ pub struct Request { m: Option } -fn main_page(query: Query) -> Result { +fn main_page(query: Query, key: &str) -> Result { let m = match &query.m { Some(b) => - match crypto::decrypt(KEY, b) { + match crypto::decrypt(key, b) { Ok(m) => m, Err(_e) => String::from(consts::DEFAULT_MESSAGE) // TODO: log error. }, @@ -72,7 +72,6 @@ fn read_key() -> String { } fn main() -> std::io::Result<()> { - let key = read_key(); if process_args(&key) { return Ok(()) } @@ -92,11 +91,13 @@ fn main() -> std::io::Result<()> { let mut listenfd = ListenFd::from_env(); let mut server = HttpServer::new( - || { + move || { + let key = key.clone(); // Is this neccessary?? + App::new() .wrap(middleware::Compress::default()) .wrap(middleware::Logger::default()) - .service(web::resource("/").to(main_page)) + .service(web::resource("/").to(move |query| main_page(query, &key))) .service(fs::Files::new("/static", "static").show_files_listing()) } );