Class: RIMS::Password::HashSource::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/rims/passwd.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(digest_factory, stretch_count, salt, hash) ⇒ Entry

Returns a new instance of Entry.



139
140
141
142
143
144
# File 'lib/rims/passwd.rb', line 139

def initialize(digest_factory, stretch_count, salt, hash)
  @digest_factory = digest_factory
  @stretch_count = stretch_count
  @salt = salt
  @hash = hash
end

Instance Attribute Details

#hashObject (readonly)

Returns the value of attribute hash.



152
153
154
# File 'lib/rims/passwd.rb', line 152

def hash
  @hash
end

#saltObject (readonly)

Returns the value of attribute salt.



151
152
153
# File 'lib/rims/passwd.rb', line 151

def salt
  @salt
end

#stretch_countObject (readonly)

Returns the value of attribute stretch_count.



150
151
152
# File 'lib/rims/passwd.rb', line 150

def stretch_count
  @stretch_count
end

Class Method Details

.encode(digest, stretch_count, salt, password) ⇒ Object



130
131
132
133
134
135
136
137
# File 'lib/rims/passwd.rb', line 130

def self.encode(digest, stretch_count, salt, password)
  salt_password = salt.b + password.b
  digest.update(salt_password)
  stretch_count.times do
    digest.update(digest.digest + salt_password)
  end
  digest.hexdigest
end

Instance Method Details

#compare(password) ⇒ Object



162
163
164
# File 'lib/rims/passwd.rb', line 162

def compare(password)
  self.class.encode(@digest_factory.new, @stretch_count, @salt, password) == @hash
end

#hash_typeObject



146
147
148
# File 'lib/rims/passwd.rb', line 146

def hash_type
  @digest_factory.to_s.sub(/^Digest::/, '')
end

#salt_base64Object



154
155
156
# File 'lib/rims/passwd.rb', line 154

def salt_base64
  Protocol.encode_base64(@salt)
end

#to_sObject



158
159
160
# File 'lib/rims/passwd.rb', line 158

def to_s
  [ hash_type, @stretch_count, salt_base64, @hash ].join(':')
end