class Gpgr::Encrypt::GpgFileForEncryption

Contians the details used to encrypt specified file, is what actually does any encryption.

Attributes

email_addresses[RW]
file[RW]
file_output[RW]

Public Class Methods

new(path, output_path) click to toggle source

The path to the file which GPG Will be encrypting and the path where you want the encrypted file to be output.

# File lib/gpgr.rb, line 79
def initialize(path, output_path)
  @file = File.expand_path(path)
  if output_path == path + '.pgp'
    @file_output = @file + '.pgp'
  else
    @file_output = File.expand_path(output_path)
  end
  @email_addresses = []
end

Public Instance Methods

encrypt() click to toggle source

Encrypts the current file for the list of recipients specific (if they are valid)

# File lib/gpgr.rb, line 105
def encrypt
  bad_key = @email_addresses.empty?
  
  if File.exists?(@file)
    unless File.readable?(@file)
      raise InvalidFileException.new("File at #{@file} is not readable.") and return
    end
  else
    raise InvalidFileException.new("File at #{@file} does not exist.") and return
  end
  
  @email_addresses.each do |add|
    unless Gpgr::Keys.public_key_installed?(add)
      bad_key = true
    end
  end
  if bad_key
    raise InvalidEmailException.new("One or more of the e-mail addresses you supplied don't have valid keys assigned!")
  else
    command = Gpgr.command + " -q --no-verbose --yes -a -o #{@file_output} -r " + @email_addresses.join(' -r ') + " -e #{@file}"
    system(command)
  end
end
encrypt_using(email_addresses) click to toggle source

Takes a list of e-mail addresses and then encrypts the file straight away.

# File lib/gpgr.rb, line 91
def encrypt_using(email_addresses)
  using(email_addresses)
  encrypt
end
using(email_addresses) click to toggle source

Expects an array of e-mail addresses for people who this file file should be

decryptable by.

# File lib/gpgr.rb, line 99
def using(email_addresses)
  @email_addresses = email_addresses
end