New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sha1::Sha1.result_str() can yield incorrect results #4458

pkgw opened this Issue Jan 12, 2013 · 1 comment


None yet
2 participants

pkgw commented Jan 12, 2013

The problem is that each byte in the SHA1 digest is hexified individually in a way that doesn't include leading zeros: a byte of 0x0a just gets turned into 'a'. So if your digest should be "ab0e" the result is "abe". You can see in this program where the printed strings vary in length:

extern mod std;
use std::sha1;

fn main () { 
    let s = sha1::sha1 ();
    let mut i = 0u8;

    while i < 100 {
        s.input (~[i]);
        io::print (s.result_str () + "\n");
        s.reset ();
        i += 1;

Do the Rust standard libraries have a byte-array-to-hex converter somewhere? It seems like that'd be a useful thing to tuck in somewhere. Besides being incorrect for the time being, the SHA1 hex converter also looks like it's probably slower than it needs to be.

bors added a commit that referenced this issue Feb 27, 2013

auto merge of #5140 : yjh0502/rust/issue_4458, r=catamorphism
Fix is a bug fix for issue #4458.

This patch is quite straight-forward. A test for result_str() is added.

This comment has been minimized.

Show comment
Hide comment

graydon Apr 30, 2013


fixed in 5ae9b29


graydon commented Apr 30, 2013

fixed in 5ae9b29

@graydon graydon closed this Apr 30, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment