diff options
author | Jesse Luehrs <doy@tozt.net> | 2015-03-15 04:58:29 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2015-03-15 04:58:29 -0400 |
commit | ef018a85888a2d77b0dc4904404776ae1b6cb401 (patch) | |
tree | eff36cb5c25802c322eb6510850106cc5d655539 /src/lib.rs | |
parent | 7312ac25a4a89c603cc8311f442a000433b5301b (diff) | |
download | matasano-ef018a85888a2d77b0dc4904404776ae1b6cb401.tar.gz matasano-ef018a85888a2d77b0dc4904404776ae1b6cb401.zip |
make these functions more useful
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 11 |
1 files changed, 3 insertions, 8 deletions
@@ -1,19 +1,14 @@ extern crate "rustc-serialize" as serialize; use serialize::base64::{ToBase64,STANDARD}; -use serialize::hex::{FromHex,ToHex}; -pub fn hex_to_base64 (hex: &str) -> String { - let bytes = hex.from_hex().unwrap(); +pub fn to_base64 (bytes: &[u8]) -> String { return bytes.to_base64(STANDARD); } -pub fn fixed_xor (str1: &str, str2: &str) -> String { - let bytes1 = str1.from_hex().unwrap(); - let bytes2 = str2.from_hex().unwrap(); +pub fn fixed_xor (bytes1: &[u8], bytes2: &[u8]) -> Vec<u8> { return bytes1.iter() .zip(bytes2.iter()) .map(|(&a, &b)| { a ^ b }) - .collect::<Vec<u8>>() - .to_hex(); + .collect(); } |