it had wrong padding on certain input lengths. ugly hack to fix, now matches sha256sum

This commit is contained in:
Adam D. Ruppe 2012-02-23 19:12:23 -05:00
parent 1e9054c4e4
commit 3c0f78ed78
1 changed files with 17 additions and 2 deletions

19
sha.d
View File

@ -126,6 +126,9 @@ struct FileByByte {
throw new Exception("couldn't open " ~ filename);
popFront();
}
// FIXME: this should prolly be recounted or something. blargh.
~this() {
if(fp !is null)
fclose(fp);
@ -175,18 +178,28 @@ template SHARange(T) if(isInputRange!(T)) {
current = 0x80;
}
} else {
bool hackforward = false;
if(state == 1) {
current = 0x0;
state = 2;
position++;
if((((position + length + 8) * 8) % 512) == 8) {
position--;
hackforward = true;
}
goto proceed;
// position++;
} else if( state == 2) {
proceed:
if(!(((position + length + 8) * 8) % 512)) {
state = 3;
position = 7;
length *= 8;
if(hackforward)
goto proceedmoar;
} else
position++;
position++;
} else if (state == 3) {
proceedmoar:
current = (length >> (position*8)) & 0xff;
if(position == 0)
state = 4;
@ -203,6 +216,8 @@ template SHARange(T) if(isInputRange!(T)) {
if(state == 0) {
return cast(ubyte) r.front();
}
assert(state != 5);
//writefln("%x", current);
return current;
}