summaryrefslogtreecommitdiffstats
path: root/src/bin
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2015-03-15 04:28:11 -0400
committerJesse Luehrs <doy@tozt.net>2015-03-15 04:28:11 -0400
commitf2b02462a35e46bbfb46df359494094722f95736 (patch)
tree63036af2651e8291b1dd492582535e5aaa01af8c /src/bin
parent7bafc19e5f367cc795ad08672359e7fce0329539 (diff)
downloadmatasano-f2b02462a35e46bbfb46df359494094722f95736.tar.gz
matasano-f2b02462a35e46bbfb46df359494094722f95736.zip
tests
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/1.rs27
1 files changed, 19 insertions, 8 deletions
diff --git a/src/bin/1.rs b/src/bin/1.rs
index 3378e65..f8c1408 100644
--- a/src/bin/1.rs
+++ b/src/bin/1.rs
@@ -1,9 +1,19 @@
extern crate "rustc-serialize" as serialize;
-use std::io::prelude::*;
+#[cfg(not(test))] use std::io::prelude::*;
+
use serialize::base64::{ToBase64,STANDARD};
use serialize::hex::FromHex;
+fn hex_to_base64 (hex: &str) -> String {
+ let bytes = match hex.from_hex() {
+ Ok(b) => b,
+ Err(e) => panic!("{}", e),
+ };
+ return bytes.to_base64(STANDARD);
+}
+
+#[cfg(not(test))]
fn main () {
loop {
let mut buf = [0; 6];
@@ -14,12 +24,13 @@ fn main () {
if len == 0 {
break;
}
- let hex = std::str::from_utf8(&buf[..len]).unwrap();
- let bytes = match hex.from_hex() {
- Ok(b) => b,
- Err(e) => panic!("{}", e),
- };
- let base64 = bytes.to_base64(STANDARD);
- print!("{}", base64);
+ print!("{}", hex_to_base64(std::str::from_utf8(&buf[..len]).unwrap()));
}
}
+
+#[test]
+fn test_base64 () {
+ let hex = "49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d";
+ let base64 = "SSdtIGtpbGxpbmcgeW91ciBicmFpbiBsaWtlIGEgcG9pc29ub3VzIG11c2hyb29t";
+ assert_eq!(hex_to_base64(hex), base64);
+}