Sha256: c002add3bc1682bcfc41075d3dc54c573014195be17e83baa5a087ea9a91b665

Contents?: true

Size: 1.02 KB

Versions: 18

Compression:

Stored size: 1.02 KB

Contents

require 'slosilo/adapters/abstract_adapter'

module Slosilo
  module Adapters
    class FileAdapter < AbstractAdapter
      attr_reader :dir
      
      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
      
      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
      
      def get_key id
        @keys[id]
      end

      def get_by_fingerprint fp
        id = @fingerprints[fp]
        [@keys[id], id]
      end
      
      def each(&block)
        @keys.each(&block)
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
slosilo-3.0.2.pre.224 lib/slosilo/adapters/file_adapter.rb
slosilo-3.0.2.pre.5 lib/slosilo/adapters/file_adapter.rb
slosilo-3.0.2.pre.44 lib/slosilo/adapters/file_adapter.rb
slosilo-3.0.2.pre.42 lib/slosilo/adapters/file_adapter.rb
slosilo-3.0.2.pre.2 lib/slosilo/adapters/file_adapter.rb
slosilo-3.0.2.pre.35 lib/slosilo/adapters/file_adapter.rb
slosilo-0.0.0 lib/slosilo/adapters/file_adapter.rb
slosilo-3.0.1 lib/slosilo/adapters/file_adapter.rb
slosilo-3.0.0 lib/slosilo/adapters/file_adapter.rb
slosilo-2.2.2 lib/slosilo/adapters/file_adapter.rb
slosilo-2.2.1 lib/slosilo/adapters/file_adapter.rb
slosilo-2.1.1 lib/slosilo/adapters/file_adapter.rb
slosilo-2.0.1 lib/slosilo/adapters/file_adapter.rb
slosilo-2.0.0 lib/slosilo/adapters/file_adapter.rb
slosilo-1.1.0 lib/slosilo/adapters/file_adapter.rb
slosilo-1.0.0 lib/slosilo/adapters/file_adapter.rb
slosilo-0.4.1 lib/slosilo/adapters/file_adapter.rb
slosilo-0.4.0 lib/slosilo/adapters/file_adapter.rb