Re: Hash

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: Hash

Post 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 )
User avatar
zorg
Party member
Posts: 3436
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Re: Hash

Post 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
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: Re: Hash

Post 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'
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: Hash[resolved]

Post by Ref »

As I expected - my bad.
I overwrote the function in a library.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 53 guests