X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=lab1_rust%2Fsrc%2Foracle_machine.rs;h=018e2a5948cd024526ede01fba3eed4a25472f02;hb=4d892f864a1f47eb1aab23f1c70ccb143081849c;hp=dd0430db9dc2632c9b6f75bf504847092b0d212b;hpb=fe03a7f9df6b8f4cf03e2399aeb68a7dc2605a67;p=crypto_lab1.git diff --git a/lab1_rust/src/oracle_machine.rs b/lab1_rust/src/oracle_machine.rs index dd0430d..018e2a5 100644 --- a/lab1_rust/src/oracle_machine.rs +++ b/lab1_rust/src/oracle_machine.rs @@ -3,14 +3,15 @@ use std::io::TcpStream; use std::iter::range_inclusive; use std::slice::bytes::copy_memory; use packet; -use packet::{ Packet, Error }; +use packet::Packet; +use packet::PacketType::Error; use end_point::EndPoint; /// Tries to decipher a ciphered data block by using the previous XOR operand and an oracle on the provided address and port. /// May print some messages on stdout. pub fn decipher(address: &str, port: u16, original_xor_operand: &[u8, ..16], cipher_block: &[u8, ..16], variant: packet::Variant) -> Option> { let mut end_point = EndPoint::new( - match TcpStream::connect(address, port) { + match TcpStream::connect((address, port)) { Ok(s) => s, _ => { println!("Unable to connect to the oracle on [{}]:{}", address, port); @@ -49,8 +50,8 @@ pub fn decipher(address: &str, port: u16, original_xor_operand: &[u8, ..16], cip forged_xor_operand(&mut final_packet)[byte] = v; - match end_point.send_raw_with_result(final_packet) { - Ok(Ok(p @ Packet { t: Error(packet::AuthError), .. })) => { + match end_point.send_raw_with_result(&final_packet) { + Ok(Ok(p @ Packet { t: Error(packet::ErrorType::Auth), .. })) => { println!("We received a MAC Error: {}", p); // If we already got a MAC mismatch for the first byte then @@ -79,7 +80,7 @@ pub fn decipher(address: &str, port: u16, original_xor_operand: &[u8, ..16], cip break; } }, - Ok(Ok(Packet { t: Error(packet::CryptError), .. })) => (), // Ignored case: the padding is wrong. + Ok(Ok(Packet { t: Error(packet::ErrorType::Crypt), .. })) => (), // Ignored case: the padding is wrong. other => { println!("Unexcepted response, aborting. {}", other); return None