projects
/
rup.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Update dependencies
[rup.git]
/
src
/
main.rs
diff --git
a/src/main.rs
b/src/main.rs
index
6ecbb0a
..
1d25a69
100644
(file)
--- 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 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, web::Query};
use askama::Template;
use std::io::prelude::*;
use askama::Template;
use std::io::prelude::*;
@@
-29,7
+29,7
@@
pub struct Request {
m: Option<String>
}
m: Option<String>
}
-fn main_page(query: Query<Request>, key: &str) ->
Result<HttpResponse>
{
+fn main_page(query: Query<Request>, key: &str) ->
HttpResponse
{
let m =
match &query.m {
Some(b) =>
let m =
match &query.m {
Some(b) =>
@@
-43,7
+43,7
@@
fn main_page(query: Query<Request>, key: &str) -> Result<HttpResponse> {
let hello = MainTemplate { sentence: &m };
let s = hello.render().unwrap();
let hello = MainTemplate { sentence: &m };
let s = hello.render().unwrap();
-
Ok(HttpResponse::Ok().content_type("text/html").body(s)
)
+
HttpResponse::Ok().content_type("text/html").body(s
)
}
#[derive(Debug, Deserialize)]
}
#[derive(Debug, Deserialize)]
@@
-52,26
+52,27
@@
struct Config {
}
fn get_exe_name() -> String {
}
fn get_exe_name() -> String {
- let first_arg = std::env::args().nth(0).unwrap();
- //dbg!(&first_arg);
+ let first_arg = std::env::args().next().unwrap();
let sep: &[_] = &['\\', '/'];
first_arg[first_arg.rfind(sep).unwrap()+1..].to_string()
}
let sep: &[_] = &['\\', '/'];
first_arg[first_arg.rfind(sep).unwrap()+1..].to_string()
}
+
fn read_key() -> String {
let mut key = String::new();
File::open(consts::FILE_KEY)
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)
.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(
String::from(
- percent_encoding::percent_decode(key.as_bytes())
+ percent_encoding::percent_decode(key.
replace('\n', "").
as_bytes())
.decode_utf8()
.decode_utf8()
- .
expect(&format
!("Failed to decode key file: {}", consts::FILE_KEY))
+ .
unwrap_or_else(|_| panic
!("Failed to decode key file: {}", consts::FILE_KEY))
)
}
)
}
-fn main() -> std::io::Result<()> {
+#[actix_rt::main]
+async fn main() -> std::io::Result<()> {
let key = read_key();
if process_args(&key) { return Ok(()) }
let key = read_key();
if process_args(&key) { return Ok(()) }
@@
-79,7
+80,7
@@
fn main() -> std::io::Result<()> {
println!("Starting RUP as web server...");
let config: Config = {
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)
match from_reader(f) {
Ok(c) => c,
Err(e) => panic!("Failed to load config: {}", e)
@@
-109,10
+110,10
@@
fn main() -> std::io::Result<()> {
server.bind(&format!("0.0.0.0:{}", config.port)).unwrap()
};
server.bind(&format!("0.0.0.0:{}", config.port)).unwrap()
};
- server.run()
+ server.run()
.await
}
}
-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());
fn print_usage() {
println!("Usage:");
println!(" {} [--help] [--encrypt <plain-text>|--decrypt <cipher-text>]", get_exe_name());
@@
-124,7
+125,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") {
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) => {
Some(mess_to_encrypt) => {
match crypto::encrypt(&key, mess_to_encrypt) {
Ok(encrypted_mess) => {
@@
-139,7
+140,7
@@
fn process_args(key: &String) -> bool {
return true
} else if let Some((position_arg_decrypt, _)) = args.iter().find_position(|arg| arg == &"--decrypt") {
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) {
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
+156,5
@@
fn process_args(key: &String) -> bool {
return true
}
return true
}
-
return
false
+ false
}
}