Changes according the latest Rust nightly.
[crypto_lab1.git] / lab1_rust / src / main.rs
index ea511be..2e15908 100644 (file)
@@ -8,6 +8,7 @@ use std::os;
 
 use end_point::{ Client, Server };
 
+mod utils;
 mod crypto;
 mod packet;
 mod end_point;
@@ -29,14 +30,14 @@ fn do_oracle_attack(address: &str, variant: packet::Variant) {
 
    match oracle_machine::decipher(address, PORT, &xor_operand, &cipher_block, variant) {
       Some(ref deciphered) if deciphered.as_slice() == expected_plain_block => {
-         println!("The oracle machine has found the clear block!:");
+         println!("The oracle machine has found the plain block!:");
          println!("   Expected block: {}", expected_plain_block.to_vec());
          println!("   Decrypted block: {}", deciphered)
       }
       Some(ref other) =>
-         println!("The oracle machine hasn't found the clear block: {}", other),
+         println!("The oracle machine hasn't found the plain block: {}", other),
       _ =>
-         println!("The oracle machine hasn't found the clear block"),
+         println!("The oracle machine hasn't found the plain block"),
    }
 }
 
@@ -64,18 +65,18 @@ fn mode() -> Mode {
    let args = os::args();
 
    if args.iter().any(|a| a.as_slice() == "--help" || a.as_slice() == "-h") {
-      return Help
+      return Mode::Help
    }
 
    if args.len() <= 1 {
-      ServerAlone
+      Mode::ServerAlone
    } else {
       match args[1].as_slice() {
-         "genkey" => GenKey,
-         "tests" => Tests,
-         "oracle-weak" => OracleWeak,
-         "oracle-fixed" => OracleFixed,
-         _ => ServerAlone,
+         "genkey" => Mode::GenKey,
+         "tests" => Mode::Tests,
+         "oracle-weak" => Mode::OracleWeak,
+         "oracle-fixed" => Mode::OracleFixed,
+         _ => Mode::ServerAlone,
       }
    }
 }
@@ -84,8 +85,8 @@ fn main() {
    let mode = mode();
 
    match mode {
-      Help => print_usage(),
-      GenKey =>
+      Mode::Help => print_usage(),
+      Mode::GenKey =>
          match crypto::generate_key(256 / 8) {
             Ok(key) => println!("key: {}", key),
             Err(e) => println!("Unable to generate a key. Error: {}", e)
@@ -94,14 +95,14 @@ fn main() {
          let address = "::1";
          println!("Starting server on [{}]:{}...", address, PORT);
 
-         match Server::new(address, PORT, match mode { OracleFixed => packet::Fixed, _ => packet::Weak }) {
+         match Server::new(address, PORT, match mode { Mode::OracleFixed => packet::Variant::Fixed, _ => packet::Variant::Weak }) {
             Ok(mut server) => {
                println!("Server started");
 
                match mode {
-                  Tests => Client::start_tests(address, PORT, packet::Weak),
-                  OracleWeak => do_oracle_attack(address, packet::Weak),
-                  OracleFixed => do_oracle_attack(address, packet::Fixed),
+                  Mode::Tests => Client::start_tests(address, PORT, packet::Variant::Weak),
+                  Mode::OracleWeak => do_oracle_attack(address, packet::Variant::Weak),
+                  Mode::OracleFixed => do_oracle_attack(address, packet::Variant::Fixed),
                   _ => {
                      println!("Press any key to quit");
                      io::stdin().read_line().ok().expect("Failed to read line");