lib/net/ldap/password.rb in net-ldap-0.8.0 vs lib/net/ldap/password.rb in net-ldap-0.9.0

- old
+ new

@@ -19,20 +19,20 @@ # * Should we provide sha1 as a synonym for sha1? I vote no because then # should you also provide ssha1 for symmetry? # attribute_value = "" def generate(type, str) - case type - when :md5 - attribute_value = '{MD5}' + Base64.encode64(Digest::MD5.digest(str)).chomp! - when :sha - attribute_value = '{SHA}' + Base64.encode64(Digest::SHA1.digest(str)).chomp! - when :ssha - salt = SecureRandom.random_bytes(16) - attribute_value = '{SSHA}' + Base64.encode64(Digest::SHA1.digest(str + salt) + salt).chomp! - else - raise Net::LDAP::LdapError, "Unsupported password-hash type (#{type})" - end + case type + when :md5 + attribute_value = '{MD5}' + Base64.encode64(Digest::MD5.digest(str)).chomp! + when :sha + attribute_value = '{SHA}' + Base64.encode64(Digest::SHA1.digest(str)).chomp! + when :ssha + salt = SecureRandom.random_bytes(16) + attribute_value = '{SSHA}' + Base64.encode64(Digest::SHA1.digest(str + salt) + salt).chomp! + else + raise Net::LDAP::LdapError, "Unsupported password-hash type (#{type})" + end return attribute_value end end end