1
Fork 0

Remove vecs from std::sha1

This commit is contained in:
Brian Anderson 2011-08-11 23:54:26 -07:00
parent 235109f8d2
commit f9623f0056
2 changed files with 6 additions and 19 deletions

View file

@ -25,11 +25,9 @@ type sha1 =
// Reset the sha1 state for reuse. This is called // Reset the sha1 state for reuse. This is called
// automatically during construction // automatically during construction
obj { obj {
fn input(&vec[u8]) ; fn input(&[u8]) ;
fn input_ivec(&[u8]) ;
fn input_str(&str) ; fn input_str(&str) ;
fn result() -> vec[u8] ; fn result() -> [u8] ;
fn result_ivec() -> [u8] ;
fn result_str() -> str ; fn result_str() -> str ;
fn reset() ; fn reset() ;
}; };
@ -239,20 +237,9 @@ fn mk_sha1() -> sha1 {
st.h.(4) = 0xC3D2E1F0u32; st.h.(4) = 0xC3D2E1F0u32;
st.computed = false; st.computed = false;
} }
fn input(msg: &vec[u8]) { fn input(msg: &[u8]) { add_input(st, msg); }
let m = ~[];
for b: u8 in msg { m += ~[b]; }
add_input(st, m);
}
fn input_ivec(msg: &[u8]) { add_input(st, msg); }
fn input_str(msg: &str) { add_input(st, str::bytes(msg)); } fn input_str(msg: &str) { add_input(st, str::bytes(msg)); }
fn result() -> vec[u8] { fn result() -> [u8] { ret mk_result(st); }
let rivec = mk_result(st);
let rvec = [];
for b: u8 in rivec { rvec += [b]; }
ret rvec;
}
fn result_ivec() -> [u8] { ret mk_result(st); }
fn result_str() -> str { fn result_str() -> str {
let r = mk_result(st); let r = mk_result(st);
let s = ""; let s = "";

View file

@ -76,7 +76,7 @@ fn test() {
let sh = sha1::mk_sha1(); let sh = sha1::mk_sha1();
for t: test in tests { for t: test in tests {
sh.input_str(t.input); sh.input_str(t.input);
let out = sh.result_ivec(); let out = sh.result();
check_vec_eq(t.output, out); check_vec_eq(t.output, out);
sh.reset(); sh.reset();
} }
@ -91,7 +91,7 @@ fn test() {
sh.input_str(str::substr(t.input, len - left, take)); sh.input_str(str::substr(t.input, len - left, take));
left = left - take; left = left - take;
} }
let out = sh.result_ivec(); let out = sh.result();
check_vec_eq(t.output, out); check_vec_eq(t.output, out);
sh.reset(); sh.reset();
} }