+ 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 = crypto::encrypt(&key, mess_to_encrypt);
+ let encrypted_mess_encoded = url::percent_encoding::utf8_percent_encode(&encrypted_mess, url::percent_encoding::DEFAULT_ENCODE_SET).to_string();
+ println!("Encrypted message percent-encoded: {}", encrypted_mess_encoded);
+ }
+ None => print_usage()
+ }
+
+ return Ok(());
+ } else if let Some((position_arg_decrypt, _)) = args.iter().find_position(|arg| arg == &"--decrypt") {
+ match args.iter().nth(position_arg_decrypt + 1) {
+ Some(cipher_text) => {
+ let cipher_text_decoded = url::percent_encoding::percent_decode(cipher_text.as_bytes()).decode_utf8().expect("Unable to decode encoded cipher text");
+ let plain_text = crypto::decrypt(&key, &cipher_text_decoded).unwrap();
+ println!("Decrypted message: {}", plain_text);
+ }
+ None => print_usage()
+ }
+
+ return Ok(());
+ }
+
+ 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));
+ match from_reader(f) {
+ Ok(c) => c,
+ Err(e) => panic!("Failed to load config: {}", e)
+ }
+ };
+
+ println!("Configuration: {:?}", config);
+