Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the generate() method more idiomatic... #326

Merged
merged 2 commits into from
Jul 5, 2020
Merged

Make the generate() method more idiomatic... #326

merged 2 commits into from
Jul 5, 2020

Conversation

pvdb
Copy link

@pvdb pvdb commented Aug 6, 2019

... and fix the following Ruby warning in the process:

lib/net/ldap/password.rb:22: warning: assigned but unused variable - attribute_value

Doesn't change anything functionally, and the tests still pass! 😃

Copy link
Member

@HarlemSquirrel HarlemSquirrel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! A small adjustment and I think this is ready.

when :ssha
salt = SecureRandom.random_bytes(16)
attribute_value = '{SSHA}' + Base64.encode64(Digest::SHA1.digest(str + salt) + salt).chomp!
'{SSHA}' + Base64.encode64(Digest::SHA1.digest(str + salt) + salt).chomp!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think https://ruby-doc.org/stdlib/libdoc/base64/rdoc/Base64.html#method-i-strict_encode64 would make this even more simple and not require calling #chomp

Copy link
Author

@pvdb pvdb Jul 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback!

The changes in this PR (as well as the similar ones in #327 and #328) focussed on suppressing the Ruby warnings, whilst shying away from making any functional changes.

I'll gladly do the functional refactoring you suggested as well, but how do you feel about merging this PR as is, and I'll follow up immediately afterwards with the further more functional refactoring?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, that works for me.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in #362!

when :ssha
salt = SecureRandom.random_bytes(16)
attribute_value = '{SSHA}' + Base64.encode64(Digest::SHA1.digest(str + salt) + salt).chomp!
'{SSHA}' + Base64.encode64(Digest::SHA1.digest(str + salt) + salt).chomp!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, that works for me.

@HarlemSquirrel HarlemSquirrel merged commit a1e9c98 into ruby-ldap:master Jul 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants