From 80abdea74b5741e7855756b854966f55b6c864e5 Mon Sep 17 00:00:00 2001 From: Greg Burri Date: Wed, 7 Aug 2019 23:15:24 +0200 Subject: [PATCH 1/1] Use the key file to decipher the message given as http parameter. --- src/main.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) 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()) } ); -- 2.45.2