X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=src%2Fmain.rs;fp=src%2Fmain.rs;h=3056267c2df25d5dbc9642c0c50e063a979bf00e;hb=96a5780355820bb1a78cb4ec8dff41dd30ef6ceb;hp=f1e66ee9639ff6edf8e62c1dcf54c80c768d88f7;hpb=c1a5fe1d8e733d744a94acf278903133e2a72115;p=rup.git diff --git a/src/main.rs b/src/main.rs index f1e66ee..3056267 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,7 @@ extern crate percent_encoding; use listenfd::ListenFd; use actix_files as fs; -use actix_web::{web, middleware, App, HttpServer, HttpResponse, Responder, Result, web::Query}; +use actix_web::{web, middleware, App, HttpServer, HttpResponse, Result, web::Query}; use askama::Template; use std::io::prelude::*; @@ -60,14 +60,14 @@ fn get_exe_name() -> String { fn read_key() -> String { let mut key = String::new(); File::open(consts::FILE_KEY) - .expect(&format!("Failed to open key file: {}", consts::FILE_KEY)) + .unwrap_or_else(|_| panic!("Failed to open key file: {}", consts::FILE_KEY)) .read_to_string(&mut key) - .expect(&format!("Failed to read key file: {}", consts::FILE_KEY)); + .unwrap_or_else(|_| panic!("Failed to read key file: {}", consts::FILE_KEY)); String::from( percent_encoding::percent_decode(key.replace('\n', "").as_bytes()) .decode_utf8() - .expect(&format!("Failed to decode key file: {}", consts::FILE_KEY)) + .unwrap_or_else(|_| panic!("Failed to decode key file: {}", consts::FILE_KEY)) ) } @@ -79,7 +79,7 @@ fn main() -> std::io::Result<()> { println!("Starting RUP as web server..."); let config: Config = { - let f = File::open(consts::FILE_CONF).expect(&format!("Failed to open configuration file {}", consts::FILE_CONF)); + let f = File::open(consts::FILE_CONF).unwrap_or_else(|_| panic!("Failed to open configuration file {}", consts::FILE_CONF)); match from_reader(f) { Ok(c) => c, Err(e) => panic!("Failed to load config: {}", e) @@ -112,7 +112,7 @@ fn main() -> std::io::Result<()> { server.run() } -fn process_args(key: &String) -> bool { +fn process_args(key: &str) -> bool { fn print_usage() { println!("Usage:"); println!(" {} [--help] [--encrypt |--decrypt ]", get_exe_name()); @@ -124,7 +124,7 @@ fn process_args(key: &String) -> bool { print_usage(); return true } else if let Some((position_arg_encrypt, _)) = args.iter().find_position(|arg| arg == &"--encrypt") { - match args.iter().nth(position_arg_encrypt + 1) { + match args.get(position_arg_encrypt + 1) { Some(mess_to_encrypt) => { match crypto::encrypt(&key, mess_to_encrypt) { Ok(encrypted_mess) => { @@ -139,7 +139,7 @@ fn process_args(key: &String) -> bool { return true } else if let Some((position_arg_decrypt, _)) = args.iter().find_position(|arg| arg == &"--decrypt") { - match args.iter().nth(position_arg_decrypt + 1) { + match args.get(position_arg_decrypt + 1) { Some(cipher_text) => { let cipher_text_decoded = percent_encoding::percent_decode(cipher_text.as_bytes()).decode_utf8().expect("Unable to decode encoded cipher text"); match crypto::decrypt(&key, &cipher_text_decoded) { @@ -155,5 +155,5 @@ fn process_args(key: &String) -> bool { return true } - return false + false }