"openssl 0.10.23 (registry+https://github.com/rust-lang/crates.io-index)",
"ron 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.94 (registry+https://github.com/rust-lang/crates.io-index)",
+ "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
use actix_web::{web, middleware, App, HttpServer, HttpResponse, Responder, Result, web::Query};
use askama::Template;
+use std::io::prelude::*;
use ron::de::from_reader;
use serde::Deserialize;
use std::{fs::File, env::args};
println!(" {} [--help] [--encrypt <message>]", get_exe_name());
}
+fn read_key() -> String {
+ use url::percent_encoding::percent_decode;
+ let mut key = String::new();
+ File::open(consts::FILE_KEY)
+ .expect(&format!("Failed to open key file: {}", consts::FILE_KEY))
+ .read_to_string(&mut key)
+ .expect(&format!("Failed to read key file: {}", consts::FILE_KEY));
+
+ String::from(
+ percent_decode(key.as_bytes())
+ .decode_utf8()
+ .expect(&format!("Failed to decode key file: {}", consts::FILE_KEY))
+ )
+}
+
fn main() -> std::io::Result<()> {
let args: Vec<String> = args().collect();
+ let key = read_key();
+
if args.iter().any(|arg| arg == "--help") {
print_usage();
return Ok(());
} else if let Some((position_arg_encrypt, _)) = args.iter().find_position(|arg| arg == &"--encrypt") {
match args.iter().nth(position_arg_encrypt + 1) {
Some(mess_to_encrypt) => {
- let encrypted_mess = mess_to_encrypt;
- //let encrypted_mess = crypto::encrypt(key: &str, plain_text: &str);
+ let encrypted_mess = crypto::encrypt(&key, mess_to_encrypt);
println!("Encrypted message: {}", encrypted_mess);
}
None => print_usage()
}
};
- let key = File::open(consts::FILE_KEY).expect(&format!("Failed to open key file: {}", consts::FILE_KEY));
-
println!("Configuration: {:?}", config);
let mut listenfd = ListenFd::from_env();