Use the key file to decipher the message given as http parameter.
authorGreg Burri <greg.burri@gmail.com>
Wed, 7 Aug 2019 21:15:24 +0000 (23:15 +0200)
committerGreg Burri <greg.burri@gmail.com>
Wed, 7 Aug 2019 21:15:24 +0000 (23:15 +0200)
src/main.rs

index 2480260..6ecbb0a 100644 (file)
@@ -29,11 +29,11 @@ pub struct Request {
    m: Option<String>
 }
 
-fn main_page(query: Query<Request>) -> Result<HttpResponse> {
+fn main_page(query: Query<Request>, key: &str) -> Result<HttpResponse> {
     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())
             }
         );