What seems to be the problem?
The hex string produced by the string.sha1 function prints the result in a non-standard way.
To be exact, for each byte it swaps the higher and lower 4 bits compared to what other implementations do.
So for example if one byte of the hash was 0xAF, the string would contain FA instead.
What did you expect to happen?
I expected the resulting string to match the output of other tools, e.g. sha1sum.
How can we reproduce this?
premake5.lua
require("premake", ">=5.0.0-beta7")
print(string.sha1(io.readfile("./test.txt")))
test.txt
What have you tried so far?
The problem seems to be here i guess:
|
output[i * 2 + 0] = g_int2hex[result[i] & 0x0f]; |
|
output[i * 2 + 1] = g_int2hex[result[i] >> 4]; |
The code first adds the lower 4 bits to the string, then the upper 4 bits.
Standard way to print a hex string would however first print the upper 4 bits, then the lower 4 bits.
I would have made a PR, however this has been implemented this way for 10 years now, so I wasn't sure if this is even something that should be fixed or if it was left like this intentionally?
If it is something to fix, I can make one though.
not related to any specific action
What version of Premake are you using?
premake5 (Premake Build Script Generator) 5.0.0-beta7
Anything else we should know?
What seems to be the problem?
The hex string produced by the
string.sha1function prints the result in a non-standard way.To be exact, for each byte it swaps the higher and lower 4 bits compared to what other implementations do.
So for example if one byte of the hash was
0xAF, the string would containFAinstead.What did you expect to happen?
I expected the resulting string to match the output of other tools, e.g.
sha1sum.How can we reproduce this?
premake5.luatest.txtWhat have you tried so far?
The problem seems to be here i guess:
premake-core/src/host/string_sha1.c
Lines 175 to 176 in ef05390
The code first adds the lower 4 bits to the string, then the upper 4 bits.
Standard way to print a hex string would however first print the upper 4 bits, then the lower 4 bits.
I would have made a PR, however this has been implemented this way for 10 years now, so I wasn't sure if this is even something that should be fixed or if it was left like this intentionally?
If it is something to fix, I can make one though.
not related to any specific action
What version of Premake are you using?
premake5 (Premake Build Script Generator) 5.0.0-beta7Anything else we should know?