Skip to content

Commit 5ae087d

Browse files
author
Austin Ziegler
committed
Cleaning up Net::LDAP::Password, including file rename.
1 parent 6eaf87d commit 5ae087d

File tree

3 files changed

+53
-58
lines changed

3 files changed

+53
-58
lines changed

lib/net/ldap.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class LDAP
1616
require 'net/ldap/pdu'
1717
require 'net/ldap/filter'
1818
require 'net/ldap/dataset'
19-
require 'net/ldap/psw'
19+
require 'net/ldap/password'
2020
require 'net/ldap/entry'
2121

2222
# == Net::LDAP

lib/net/ldap/password.rb

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#----------------------------------------------------------------------------
2+
#
3+
# Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
4+
#
5+
# Gmail: garbagecat10
6+
#
7+
# This program is free software; you can redistribute it and/or modify
8+
# it under the terms of the GNU General Public License as published by
9+
# the Free Software Foundation; either version 2 of the License, or
10+
# (at your option) any later version.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU General Public License
18+
# along with this program; if not, write to the Free Software
19+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20+
#
21+
#---------------------------------------------------------------------------
22+
23+
require 'digest/sha1'
24+
require 'digest/md5'
25+
26+
class Net::LDAP::Password
27+
class << self
28+
# Generate a password-hash suitable for inclusion in an LDAP attribute.
29+
# Pass a hash type (currently supported: :md5 and :sha) and a plaintext
30+
# password. This function will return a hashed representation.
31+
#
32+
#--
33+
# STUB: This is here to fulfill the requirements of an RFC, which
34+
# one?
35+
#
36+
# TODO, gotta do salted-sha and (maybe)salted-md5. Should we provide
37+
# sha1 as a synonym for sha1? I vote no because then should you also
38+
# provide ssha1 for symmetry?
39+
def generate(type, str)
40+
digest, digest_name = case type
41+
when :md5
42+
[Digest::MD5.new, 'MD5']
43+
when :sha
44+
[Digest::SHA1.new, 'SHA']
45+
else
46+
raise Net::LDAP::LdapError, "Unsupported password-hash type (#{type})"
47+
end
48+
digest << str.to_s
49+
return "{#{digest_name}}#{[digest.digest].pack('m').chomp }"
50+
end
51+
end
52+
end

lib/net/ldap/psw.rb

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)