technion / ruby-argon2

A Ruby gem offering bindings for Argon2 password hashing
MIT License
229 stars 30 forks source link

Ensure that input to 'create' is a string. #16

Closed stomar closed 7 years ago

stomar commented 7 years ago

This provides a much clearer error message for other input types (e.g. nil, which happens from time to time...).

Currently:

Argon2::Password.create(nil)
# /home/.../gems/argon2-1.1.1/lib/argon2/ffi_engine.rb:59:in `[]': bignum too big to convert into `long' (RangeError)

Argon2::Password.create(1)
# /home/.../gems/argon2-1.1.1/lib/argon2/ffi_engine.rb:51:in `hash_argon2i_encode': undefined method `bytesize' for 1:Integer (NoMethodError)

New:

Argon2::Password.create(nil)
# /home/.../gems/argon2-1.1.1/lib/argon2.rb:21:in `create': Invalid password (expected string) (Argon2::ArgonHashFail)
technion commented 7 years ago

Thank you for this PR.

Note, CI only failed due to an external issue involving the codeclimate gem. I've pushed a fix for that too.

stomar commented 7 years ago

thanks!