Page 1 of 1

Re: Hash

Posted: Fri Jan 17, 2020 10:22 pm
by Ref
Is it just me or is the WIKI backward?

Code: Select all

rawdigest = love.data.hash( hashFunction, data )
It only seems to work for me if the arguments are reversed???

Code: Select all

rawdigest = love.data.hash( data, hashFunction )

Re: Re: Hash

Posted: Sat Jan 18, 2020 1:47 pm
by zorg
As far as i can tell from the source, the wiki's order should be the one that works...
https://github.com/love2d/love/blob/mas ... #L303-L325

Re: Re: Hash

Posted: Sun Jan 19, 2020 11:37 am
by pgimeno

Code: Select all

rawdigest = love.data.hash('sha1', '')
for i = 1, #rawdigest do
  io.write(string.format("%02x", rawdigest:byte(i)))
end
print()
works for me, printing da39a3ee5e6b4b0d3255bfef95601890afd80709 which is the SHA-1 hash of the empty string as explained in https://en.wikipedia.org/wiki/SHA-1. So the wiki order is correct.

If I invert them I get this:

Code: Select all

Error: main.lua:1: Invalid hash function '', expected one of: 'md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512'

Re: Hash[resolved]

Posted: Sun Jan 19, 2020 6:27 pm
by Ref
As I expected - my bad.
I overwrote the function in a library.