Class: RIMS::Password::HashSource::Entry
- Inherits:
-
Object
- Object
- RIMS::Password::HashSource::Entry
- Defined in:
- lib/rims/passwd.rb
Instance Attribute Summary collapse
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
-
#salt ⇒ Object
readonly
Returns the value of attribute salt.
-
#stretch_count ⇒ Object
readonly
Returns the value of attribute stretch_count.
Class Method Summary collapse
Instance Method Summary collapse
- #compare(password) ⇒ Object
- #hash_type ⇒ Object
-
#initialize(digest_factory, stretch_count, salt, hash) ⇒ Entry
constructor
A new instance of Entry.
- #salt_base64 ⇒ Object
- #to_s ⇒ Object
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
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
152 153 154 |
# File 'lib/rims/passwd.rb', line 152 def hash @hash end |
#salt ⇒ Object (readonly)
Returns the value of attribute salt.
151 152 153 |
# File 'lib/rims/passwd.rb', line 151 def salt @salt end |
#stretch_count ⇒ Object (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_type ⇒ Object
146 147 148 |
# File 'lib/rims/passwd.rb', line 146 def hash_type @digest_factory.to_s.sub(/^Digest::/, '') end |
#salt_base64 ⇒ Object
154 155 156 |
# File 'lib/rims/passwd.rb', line 154 def salt_base64 Protocol.encode_base64(@salt) end |
#to_s ⇒ Object
158 159 160 |
# File 'lib/rims/passwd.rb', line 158 def to_s [ hash_type, @stretch_count, salt_base64, @hash ].join(':') end |