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, opts = {}) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/ruby_gpg.rb', line 40

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

#decrypt_string(string, passphrase = nil) ⇒ Object



48
49
50
51
52
53
# File 'lib/ruby_gpg.rb', line 48

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, opts = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ruby_gpg.rb', line 16

def encrypt(file, recipient, opts = {})
  options = {
    :armor => false
  }.merge(opts)
  
  output = output_filename(file, options)
  
  ascii = options[:armor] == true ? "-a " : ""
  
  command = "#{gpg_command} #{ascii}--output #{output}" +
            " --recipient \"#{recipient}\" --encrypt #{file}"
  
  run_command(command)
end

#encrypt_string(string, recipient, opts = {}) ⇒ Object

Encrypt a string from stdin



32
33
34
35
36
37
38
# File 'lib/ruby_gpg.rb', line 32

def encrypt_string(string, recipient, opts = {})
  command = gpg_command.dup
  command << " -a" if opts[:armor]
  command << " --encrypt"
  command << " --recipient \"#{recipient}\""
  run_command(command, string)
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