string.sha1 prints hex digits in a non-standard way
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
foobar
What have you tried so far?
The problem seems to be here i guess: https://github.com/premake/premake-core/blob/ef053905fdc68c763ebea79025a7e0fa8172c368/src/host/string_sha1.c#L175-L176
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.
- [ ] Visual Studio 2022 (vs2022)
- [ ] Visual Studio 2019 (vs2019)
- [ ] Visual Studio 2017 (vs2017)
- [ ] Visual Studio 2015 (vs2015)
- [ ] Visual Studio 2012 (vs2012)
- [ ] Visual Studio 2010 (vs2010)
- [ ] Visual Studio 2008 (vs2008)
- [ ] Visual Studio 2005 (vs2005)
- [ ] GNU Makefile (gmake)
- [ ] GNU Makefile Legacy (gmakelegacy)
- [ ] XCode (xcode)
- [ ] Codelite
- [x] Other (Please list below)
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?
Fixing it might break people using our method and comparing with previous computed one :-/