Class GPGME::Ctx
In: lib/gpgme.rb
lib/gpgme/compat.rb
Parent: Object

A context within which all cryptographic operations are performed.

Methods

Public Class methods

Create a new instance from the given options. options is a Hash whose keys are

  • :protocol Either PROTOCOL_OpenPGP or PROTOCOL_CMS.
  • :armor If true, the output should be ASCII armored.
  • :textmode If true, inform the recipient that the input is text.
  • :keylist_mode Either KEYLIST_MODE_LOCAL, KEYLIST_MODE_EXTERN, KEYLIST_MODE_SIGS, or KEYLIST_MODE_VALIDATE.
  • :passphrase_callback A callback function.
  • :passphrase_callback_value An object passed to passphrase_callback.
  • :progress_callback A callback function.
  • :progress_callback_value An object passed to progress_callback.

Public Instance methods

Add keys to the list of signers.

Return true if the output is ASCII armored.

Tell whether the output should be ASCII armored.

card_edit(key, editfunc, hook_value = nil, out = Data.new)

Alias for edit_card_key

Remove the list of signers from this object.

Decrypt the ciphertext and return the plaintext.

Decrypt the ciphertext and return the plaintext.

delete(key, allow_secret = false)

Alias for delete_key

Delete the key from the key ring. If allow_secret is false, only public keys are deleted, otherwise secret keys are deleted as well.

Convenient method to iterate over keys. If pattern is nil, all available keys are returned. If secret_only is true, the only secret keys are returned.

each_keys(pattern = nil, secret_only = false)

Alias for each_key

edit(key, editfunc, hook_value = nil, out = Data.new)

Alias for edit_key

edit_card(key, editfunc, hook_value = nil, out = Data.new)

Alias for edit_card_key

Edit attributes of the key in the local key ring.

Encrypt the plaintext in the data object for the recipients and return the ciphertext.

export(recipients, keydata = Data.new)

Alias for export_keys

Extract the public keys of the recipients.

Generate a new key pair. parms is a string which looks like

 <GnupgKeyParms format="internal">
 Key-Type: DSA
 Key-Length: 1024
 Subkey-Type: ELG-E
 Subkey-Length: 1024
 Name-Real: Joe Tester
 Name-Comment: with stupid passphrase
 Name-Email: joe@foo.bar
 Expire-Date: 0
 Passphrase: abc
 </GnupgKeyParms>

If pubkey and seckey are both set to nil, it stores the generated key pair into your key ring.

genkey(parms, pubkey = Data.new, seckey = Data.new)

Alias for generate_key

Get the key with the fingerprint. If secret is true, secret key is returned.

import(keydata)

Alias for import_keys

Add the keys in the data buffer to the key ring.

End a pending key list operation.

Return the current key listing mode.

Change the default behaviour of the key listing functions.

Advance to the next key in the key listing operation.

Initiate a key listing operation for given pattern. If pattern is nil, all available keys are returned. If secret_only is true, the only secret keys are returned.

Return the protocol used within this context.

Set the protocol used within this context.

Set the data pointer to the beginning.

Set the passphrase callback with given hook value. passfunc should respond to call with 5 arguments.

 def passfunc(hook, uid_hint, passphrase_info, prev_was_bad, fd)
   $stderr.write("Passphrase for #{uid_hint}: ")
   $stderr.flush
   begin
     system('stty -echo')
     io = IO.for_fd(fd, 'w')
     io.puts(gets)
     io.flush
   ensure
     (0 ... $_.length).each do |i| $_[i] = ?0 end if $_
     system('stty echo')
   end
   $stderr.puts
 end

 ctx.set_passphrase_callback(method(:passfunc))
set_passphrase_cb(passfunc, hook_value = nil)

Set the progress callback with given hook value. progfunc should respond to call with 5 arguments.

 def progfunc(hook, what, type, current, total)
   $stderr.write("#{what}: #{current}/#{total}\r")
   $stderr.flush
 end

 ctx.set_progress_callback(method(:progfunc))
set_progress_cb(progfunc, hook_value = nil)

Create a signature for the text. plain is a data object which contains the text. sig is a data object where the generated signature is stored.

Return true if canonical text mode is enabled.

Tell whether canonical text mode should be used.

Verify that the signature in the data object is a valid signature.

[Validate]