lib/passrock/password_db.rb in passrock-0.0.4 vs lib/passrock/password_db.rb in passrock-0.0.5

- old
+ new

@@ -10,15 +10,17 @@ def self.bcrypt_hash(secret, salt) BCrypt::Engine.hash_secret(secret, "$2a$07$#{salt}") end - attr_reader :filename, :private_key + attr_reader :password_db, :private_key - def initialize(filename, private_key) - @filename = filename - @private_key = private_key + def initialize(opts = {}) + @password_db = opts[:password_db] + @private_key = opts[:private_key] + + raise PasswordDbNotFoundError, "Passrock Password DB not found at: #{@password_db}" unless File.file?(@password_db) end def password_in_searchable_form(password) hashed_password = self.class.bcrypt_hash(password, private_key) @@ -38,14 +40,14 @@ private def total_records # Minus 1 for length in file and 1 for 0-up counting - @total_records ||= (File.size(filename) / RECORD_LENGTH) - 2 + @total_records ||= (File.size(password_db) / RECORD_LENGTH) - 2 end def find_by_binary_search(password) - file = File.new(filename, 'rb') + file = File.new(password_db, 'rb') target = password_in_searchable_form(password) lo = 1 # start at 1 because the testKey is at 0 hi = total_records while lo <= hi \ No newline at end of file