mogest/unix-crypt — Issue #2: 1.9 compatibility
Author: mkfs
Created: 2011-12-16 22:37:20+00:00
State: open

UnixCrypt.build causes a TypeError when used under Ruby 1.9.x:

TypeError at unix_crypt.rb line: 97
String can't be coerced into Fixnum

The line in question is:
ds = digest.digest(salt * (16 + a[0]))
...where 'salt' and 'a' are both strings.

The problem here is that in Ruby 1.8.x, String#[] returns a byte value, while in Ruby 1.9.x it returns a character or substring.

The way to fix this is to use String.bytes, e.g.

ds = digest.digest(salt * (16 + a.bytes.first))