Class: FTPMVC::Filter::Gpg

Inherits:
Base
  • Object
show all
Defined in:
lib/ftpmvc/filter/gpg.rb

Instance Method Summary collapse

Constructor Details

#initialize(fs, chain, options = {}) ⇒ Gpg

Returns a new instance of Gpg.



8
9
10
11
12
13
# File 'lib/ftpmvc/filter/gpg.rb', line 8

def initialize(fs, chain, options={})
  super fs, chain
  @crypto = GPGME::Crypto.new(
    password: options[:passphrase], recipients: options[:recipients], always_trust: true)
  import_keys(options[:keys]) if options.include?(:keys)
end

Instance Method Details

#directory?(path) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/ftpmvc/filter/gpg.rb', line 31

def directory?(path)
  @chain.directory?(remove_extension(path))
end

#exists?(path) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/ftpmvc/filter/gpg.rb', line 27

def exists?(path)
  @chain.exists?(remove_extension(path))
end

#get(path) ⇒ Object



23
24
25
# File 'lib/ftpmvc/filter/gpg.rb', line 23

def get(path)
  StringIO.new(@crypto.encrypt(original_data(path)).read)
end

#index(path) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/ftpmvc/filter/gpg.rb', line 15

def index(path)
  @chain.index(path).each do |node|
    if node.kind_of?(File) and not ::File.extname(node.name) == '.gpg'
      node.name = "#{node.name}.gpg"
    end
  end
end

#put(path, input) ⇒ Object



35
36
37
# File 'lib/ftpmvc/filter/gpg.rb', line 35

def put(path, input)
  @chain.put(remove_extension(path), FTPMVC::GPG::Input.new(@crypto.decrypt(input.read_all)))
end