Open hoffi opened 1 year ago
@hoffi Yes, there is a maximum length after which it has no effect on the generated hash. But still salt is used and if you change the letter in your snippet you will see an effect.
https://github.com/peterhellberg/hashids.rb/blob/master/lib/hashids.rb#L157
Hashids uses idx = (idx + 1) % salt_length
to provide looping/cycling through indices in the alphabet shuffling process. At the same time it depends on the initial alphabet length - separators length - guards - lottery. So if salt length is quite larger then alphabet then it would use only first part of salt for alphabet shuffling. And it would be enough to shuffle the whole alphabet. Anyway, shuffling will happen. And yes, the last part of the salt would not be used. I agree that this is not obvious, but this is not an exception. Using a random string would generate uniq values.
The salt appears to have a maximum length after which it has no longer impacts the generated hash.
Here some examples:
If i change the alphabet it also affects this maximum length:
Looks like something around
(alphabet.length * 0.7).floor
is the maximum length?Should this be validated and raise a
SaltError
when the salt is too long?