Module: RubyGpg

Extended by:
RubyGpg
Included in:
RubyGpg
Defined in:
lib/ruby_gpg.rb

Defined Under Namespace

Classes: Config

Instance Method Summary collapse

Instance Method Details

#configObject



7
8
9
# File 'lib/ruby_gpg.rb', line 7

def config
  @config ||=  Config.new("gpg", "~/.gnupg")
end

#decrypt(file, passphrase = nil) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/ruby_gpg.rb', line 22

def decrypt(file, passphrase = nil)
  outfile = file.gsub(/\.gpg$/, '')
  command = "#{gpg_command} --output #{outfile}"
  command << " --passphrase #{passphrase}" if passphrase
  command << " --decrypt #{file}"
  run_command(command)
end

#decrypt_string(string, passphrase = nil) ⇒ Object



30
31
32
33
34
35
# File 'lib/ruby_gpg.rb', line 30

def decrypt_string(string, passphrase = nil)
  command = gpg_command.dup
  command << " --passphrase #{passphrase}" if passphrase
  command << " --decrypt"
  run_command(command, string)
end

#encrypt(file, recipient) ⇒ Object



16
17
18
19
20
# File 'lib/ruby_gpg.rb', line 16

def encrypt(file, recipient)
  command = "#{gpg_command} --output #{file}.gpg" +
            " --recipient \"#{recipient}\" --encrypt #{file}"
  run_command(command)
end

#gpg_commandObject



11
12
13
14
# File 'lib/ruby_gpg.rb', line 11

def gpg_command
  "#{config.executable} --homedir #{config.homedir} --quiet" +
  " --no-secmem-warning --no-permission-warning --no-tty --yes"
end