Skip to content

Commit

Permalink
Fix: now sha1 result_str() return correct value
Browse files Browse the repository at this point in the history
  • Loading branch information
yjh0502 committed Feb 27, 2013
1 parent f4e8ac2 commit 5ae9b29
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/libstd/sha1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,11 @@ pub fn sha1() -> Sha1 {
let rr = mk_result(self);
let mut s = ~"";
for vec::each(rr) |b| {
s += uint::to_str_radix(*b as uint, 16u);
let hex = uint::to_str_radix(*b as uint, 16u);
if hex.len() == 1 {
s += "0";
}
s += hex;
}
return s;
}
Expand Down Expand Up @@ -283,6 +287,7 @@ mod tests {
struct Test {
input: ~str,
output: ~[u8],
output_str: ~str,
}

fn a_million_letter_a() -> ~str {
Expand All @@ -306,6 +311,7 @@ mod tests {
0x78u8, 0x50u8, 0xC2u8, 0x6Cu8,
0x9Cu8, 0xD0u8, 0xD8u8, 0x9Du8,
],
output_str: ~"a9993e364706816aba3e25717850c26c9cd0d89d"
},
Test {
input:
Expand All @@ -318,6 +324,7 @@ mod tests {
0xF9u8, 0x51u8, 0x29u8, 0xE5u8,
0xE5u8, 0x46u8, 0x70u8, 0xF1u8,
],
output_str: ~"84983e441c3bd26ebaae4aa1f95129e5e54670f1"
},
Test {
input: a_million_letter_a(),
Expand All @@ -328,6 +335,7 @@ mod tests {
0xDBu8, 0xADu8, 0x27u8, 0x31u8,
0x65u8, 0x34u8, 0x01u8, 0x6Fu8,
],
output_str: ~"34aa973cd4c4daa4f61eeb2bdbad27316534016f"
},
];
// Examples from wikipedia
Expand All @@ -342,6 +350,7 @@ mod tests {
0xbbu8, 0x76u8, 0xe7u8, 0x39u8,
0x1bu8, 0x93u8, 0xebu8, 0x12u8,
],
output_str: ~"2fd4e1c67a2d28fced849ee1bb76e7391b93eb12",
},
Test {
input: ~"The quick brown fox jumps over the lazy cog",
Expand All @@ -352,6 +361,7 @@ mod tests {
0x0bu8, 0xd1u8, 0x7du8, 0x9bu8,
0x10u8, 0x0du8, 0xb4u8, 0xb3u8,
],
output_str: ~"de9f2c7fd25e1b3afad3e85a0bd17d9b100db4b3",
},
];
let tests = fips_180_1_tests + wikipedia_tests;
Expand All @@ -373,6 +383,11 @@ mod tests {
sh.input_str(t.input);
let out = sh.result();
check_vec_eq(t.output, out);

let out_str = sh.result_str();
assert(out_str.len() == 40);
assert(out_str == t.output_str);

sh.reset();
}

Expand All @@ -389,6 +404,11 @@ mod tests {
}
let out = sh.result();
check_vec_eq(t.output, out);

let out_str = sh.result_str();
assert(out_str.len() == 40);
assert(out_str == t.output_str);

sh.reset();
}
}
Expand Down

6 comments on commit 5ae9b29

@graydon
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r+ thanks

@bors
Copy link
Contributor

@bors bors commented on 5ae9b29 Feb 27, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from catamorphism
at yjh0502@5ae9b29

@bors
Copy link
Contributor

@bors bors commented on 5ae9b29 Feb 27, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging yjh0502/rust/issue_4458 = 5ae9b29 into auto

@bors
Copy link
Contributor

@bors bors commented on 5ae9b29 Feb 27, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yjh0502/rust/issue_4458 = 5ae9b29 merged ok, testing candidate = 6ebc761

@bors
Copy link
Contributor

@bors bors commented on 5ae9b29 Feb 28, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 5ae9b29 Feb 28, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding incoming to auto = 6ebc761

Please sign in to comment.