class Slosilo::Adapters::FileAdapter

Attributes

dir[R]

Public Class Methods

new(dir) click to toggle source
# File lib/slosilo/adapters/file_adapter.rb, line 8
def initialize(dir)
  @dir = dir
  @keys = {}
  @fingerprints = {}
  Dir[File.join(@dir, "*.key")].each do |f|
    key = Slosilo::EncryptedAttributes.decrypt File.read(f)
    id = File.basename(f, '.key')
    key = @keys[id] = Slosilo::Key.new(key)
    @fingerprints[key.fingerprint] = id
  end
end

Public Instance Methods

each(&block) click to toggle source
# File lib/slosilo/adapters/file_adapter.rb, line 37
def each(&block)
  @keys.each(&block)
end
get_by_fingerprint(fp) click to toggle source
# File lib/slosilo/adapters/file_adapter.rb, line 32
def get_by_fingerprint fp
  id = @fingerprints[fp]
  [@keys[id], id]
end
get_key(id) click to toggle source
# File lib/slosilo/adapters/file_adapter.rb, line 28
def get_key id
  @keys[id]
end
put_key(id, value) click to toggle source
# File lib/slosilo/adapters/file_adapter.rb, line 20
def put_key id, value
  raise "id should not contain a period" if id.index('.')
  fname = File.join(dir, "#{id}.key")
  File.write(fname, Slosilo::EncryptedAttributes.encrypt(value.to_der))
  File.chmod(0400, fname)
  @keys[id] = value
end