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::*;
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))
)
}
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)
server.run()
}
-fn process_args(key: &String) -> bool {
+fn process_args(key: &str) -> bool {
fn print_usage() {
println!("Usage:");
println!(" {} [--help] [--encrypt <plain-text>|--decrypt <cipher-text>]", get_exe_name());
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) => {
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) {
return true
}
- return false
+ false
}