Class HTAuth::Algorithm
In: lib/htauth/algorithm.rb
lib/htauth/algorithm.rb
Parent: Object

base class all the Passwd algorithms derive from

Methods

Constants

SALT_CHARS = (%w[ . / ] + ("0".."9").to_a + ('A'..'Z').to_a + ('a'..'z').to_a).freeze
DEFAULT = ( RUBY_PLATFORM !~ /mswin32/ ) ? "crypt" : "md5"
EXISTING = "existing"
SALT_CHARS = (%w[ . / ] + ("0".."9").to_a + ('A'..'Z').to_a + ('a'..'z').to_a).freeze
DEFAULT = ( RUBY_PLATFORM !~ /mswin32/ ) ? "crypt" : "md5"
EXISTING = "existing"

Public Class methods

[Source]

    # File lib/htauth/algorithm.rb, line 13
13:       def algorithm_from_name(a_name, params = {})
14:         raise InvalidAlgorithmError, "`#{a_name}' is an invalid encryption algorithm, use one of #{sub_klasses.keys.join(', ')}" unless sub_klasses[a_name.downcase]
15:         sub_klasses[a_name.downcase].new(params)
16:       end

[Source]

    # File lib/htauth/algorithm.rb, line 13
13:       def algorithm_from_name(a_name, params = {})
14:         raise InvalidAlgorithmError, "`#{a_name}' is an invalid encryption algorithm, use one of #{sub_klasses.keys.join(', ')}" unless sub_klasses[a_name.downcase]
15:         sub_klasses[a_name.downcase].new(params)
16:       end

[Source]

    # File lib/htauth/algorithm.rb, line 18
18:       def algorithms_from_field(password_field)
19:         matches = []
20: 
21:         if password_field.index(sub_klasses['sha1'].new.prefix) then
22:           matches << sub_klasses['sha1'].new
23:         elsif password_field.index(sub_klasses['md5'].new.prefix) then
24:           p = password_field.split("$")
25:           matches << sub_klasses['md5'].new( :salt => p[2] )
26:         else
27:           matches << sub_klasses['plaintext'].new
28:           matches << sub_klasses['crypt'].new( :salt => password_field[0,2] )
29:         end
30: 
31:         return matches
32:       end

[Source]

    # File lib/htauth/algorithm.rb, line 18
18:       def algorithms_from_field(password_field)
19:         matches = []
20: 
21:         if password_field.index(sub_klasses['sha1'].new.prefix) then
22:           matches << sub_klasses['sha1'].new
23:         elsif password_field.index(sub_klasses['md5'].new.prefix) then
24:           p = password_field.split("$")
25:           matches << sub_klasses['md5'].new( :salt => p[2] )
26:         else
27:           matches << sub_klasses['plaintext'].new
28:           matches << sub_klasses['crypt'].new( :salt => password_field[0,2] )
29:         end
30: 
31:         return matches
32:       end

[Source]

    # File lib/htauth/algorithm.rb, line 34
34:       def inherited(sub_klass)
35:         k = sub_klass.name.split("::").last.downcase
36:         sub_klasses[k] = sub_klass
37:       end

[Source]

    # File lib/htauth/algorithm.rb, line 34
34:       def inherited(sub_klass)
35:         k = sub_klass.name.split("::").last.downcase
36:         sub_klasses[k] = sub_klass
37:       end

[Source]

    # File lib/htauth/algorithm.rb, line 39
39:       def sub_klasses
40:         @sub_klasses ||= {}
41:       end

[Source]

    # File lib/htauth/algorithm.rb, line 39
39:       def sub_klasses
40:         @sub_klasses ||= {}
41:       end

Public Instance methods

[Source]

    # File lib/htauth/algorithm.rb, line 45
45:     def encode(password) ; end

[Source]

    # File lib/htauth/algorithm.rb, line 45
45:     def encode(password) ; end

8 bytes of random items from SALT_CHARS

[Source]

    # File lib/htauth/algorithm.rb, line 48
48:     def gen_salt
49:       chars = []
50:       8.times { chars << SALT_CHARS[rand(SALT_CHARS.size)] }
51:       chars.join('')     
52:     end

8 bytes of random items from SALT_CHARS

[Source]

    # File lib/htauth/algorithm.rb, line 48
48:     def gen_salt
49:       chars = []
50:       8.times { chars << SALT_CHARS[rand(SALT_CHARS.size)] }
51:       chars.join('')     
52:     end

[Source]

    # File lib/htauth/algorithm.rb, line 44
44:     def prefix ; end

[Source]

    # File lib/htauth/algorithm.rb, line 44
44:     def prefix ; end

this is not the Base64 encoding, this is the to64() method from apr

[Source]

    # File lib/htauth/algorithm.rb, line 55
55:     def to_64(number, rounds)
56:       r = StringIO.new
57:       rounds.times do |x|
58:         r.print(SALT_CHARS[number % 64])
59:         number >>= 6
60:       end
61:       return r.string
62:     end

this is not the Base64 encoding, this is the to64() method from apr

[Source]

    # File lib/htauth/algorithm.rb, line 55
55:     def to_64(number, rounds)
56:       r = StringIO.new
57:       rounds.times do |x|
58:         r.print(SALT_CHARS[number % 64])
59:         number >>= 6
60:       end
61:       return r.string
62:     end

[Validate]