Skip to content

string.sha1 prints hex digits in a non-standard way #2519

@Laupetin

Description

@Laupetin

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
Image

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.

  • 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
  • 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions