diff options
author | Jesse Luehrs <doy@tozt.net> | 2015-03-20 10:12:49 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2015-03-20 10:12:49 -0400 |
commit | aa42eb5525047d55ed3206626101caf9e4db79ea (patch) | |
tree | 26ff73fc5f843f5960a4ba03c99f562298493613 | |
parent | e47104a3369cc76e718b0c68d4faf69fdcd7f2ee (diff) | |
download | matasano-aa42eb5525047d55ed3206626101caf9e4db79ea.tar.gz matasano-aa42eb5525047d55ed3206626101caf9e4db79ea.zip |
fix warnings
-rw-r--r-- | src/aes.rs | 24 | ||||
-rw-r--r-- | tests/lib.rs | 8 |
2 files changed, 17 insertions, 15 deletions
@@ -1,6 +1,6 @@ use std; +use std::borrow::ToOwned; use std::collections::{HashMap, HashSet}; -use std::collections::hash_map::Entry::{Occupied, Vacant}; use openssl; @@ -141,6 +141,14 @@ pub fn crack_padded_aes_128_ecb<F> (f: &F) -> Vec<u8> where F: Fn(&[u8]) -> Vec< } pub fn crack_querystring_aes_128_ecb<F> (encrypter: F) -> (String, Vec<Vec<u8>>) where F: Fn(&str) -> Vec<u8> { + fn incr_map_element (map: &mut HashMap<Vec<u8>, usize>, key: Vec<u8>) { + if let Some(val) = map.get_mut(&key) { + *val += 1; + return; + } + map.insert(key, 1); + }; + // find blocks that correspond to "uid=10&role=user" or "role=user&uid=10" let find_uid_role_blocks = || { let mut map = HashMap::new(); @@ -148,14 +156,8 @@ pub fn crack_querystring_aes_128_ecb<F> (encrypter: F) -> (String, Vec<Vec<u8>>) let email_bytes: Vec<u8> = std::iter::repeat(c).take(9).collect(); let email = std::str::from_utf8(&email_bytes[..]).unwrap(); let ciphertext = encrypter(email); - match map.entry(ciphertext[..16].to_vec()) { - Occupied(mut o) => { *o.get_mut() += 1; }, - Vacant(v) => { v.insert(1); }, - } - match map.entry(ciphertext[16..32].to_vec()) { - Occupied(mut o) => { *o.get_mut() += 1; }, - Vacant(v) => { v.insert(1); }, - } + incr_map_element(&mut map, ciphertext[..16].to_vec()); + incr_map_element(&mut map, ciphertext[16..32].to_vec()); } let mut most_common_blocks = vec![]; @@ -180,7 +182,7 @@ pub fn crack_querystring_aes_128_ecb<F> (encrypter: F) -> (String, Vec<Vec<u8>>) } } - if let [(ref block1, i1), (ref block2, i2)] = &most_common_blocks[..] { + if let [(ref block1, _), (ref block2, _)] = &most_common_blocks[..] { return (block1.clone(), block2.clone()); } else { @@ -218,7 +220,7 @@ pub fn crack_querystring_aes_128_ecb<F> (encrypter: F) -> (String, Vec<Vec<u8>>) possibles.push(modified_ciphertext); } } - return (String::from_str(email), possibles); + return (email.to_owned(), possibles); }; let (block1, block2) = find_uid_role_blocks(); diff --git a/tests/lib.rs b/tests/lib.rs index 629b7c2..1650165 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -234,7 +234,7 @@ fn problem_13 () { return Some( params .into_iter() - .map(|(k, v)| (String::from_str(k), String::from_str(v))) + .map(|(k, v)| (k.to_owned(), v.to_owned())) .collect() ); } @@ -245,9 +245,9 @@ fn problem_13 () { let (email, ciphertexts) = matasano::crack_querystring_aes_128_ecb(encrypter); let mut expected = HashMap::new(); - expected.insert(String::from_str("email"), email); - expected.insert(String::from_str("uid"), String::from_str("10")); - expected.insert(String::from_str("role"), String::from_str("admin")); + expected.insert("email".to_owned(), email); + expected.insert("uid".to_owned(), "10".to_owned()); + expected.insert("role".to_owned(), "admin".to_owned()); assert!(ciphertexts.iter().any(|ciphertext| { decrypter(ciphertext).map(|params| params == expected).unwrap_or(false) })); |