Class GPGME::Ctx
In: lib/gpgme/ctx.rb
lib/gpgme/compat.rb
ext/gpgme/gpgme_n.c
Parent: Object

The CTX argument can be `NULL’. In that case, `gpgme_wait’ waits

  for any context to complete its operation.

Methods

Public Class methods

Create a new instance from the given options. Must be released either executing the operations inside a block, or executing {GPGME::Ctx#release} afterwards.

@param [Hash] options

 The optional parameters are as follows:
 * +:protocol+ Either +PROTOCOL_OpenPGP+ or +PROTOCOL_CMS+.
 * +:armor+ will return ASCII armored outputs if specified true.
 * +:textmode+ if +true+, inform the recipient that the input is text.
 * +:keylist_mode+ One of: +KEYLIST_MODE_LOCAL+, +KEYLIST_MODE_EXTERN+,
   +KEYLIST_MODE_SIGS+ or +KEYLIST_MODE_VALIDATE+.
 * +:password+ password of the passphrased password being used.
 * +:passphrase_callback+ A callback function. See {#set_passphrase_callback}.
 * +:passphrase_callback_value+ An object passed to passphrase_callback.
 * +:progress_callback+  A callback function. See {#set_progress_callback}.
 * +:progress_callback_value+ An object passed to progress_callback.

@example

  ctx = GPGME::Ctx.new
  # operate on ctx
  ctx.release

@example

  GPGME::Ctx.new do |ctx|
    # operate on ctx
  end

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.

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, only secret keys are returned.

See {GPGME::Key.find} for an example of how to use, or for an easier way to use.

each_keys(pattern = nil, secret_only = false, &block)

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 that match the recipients. Returns a {GPGME::Data} object which is not rewinded (should do +seek(0)+ before reading).

Private keys cannot be exported due to GPGME restrictions.

If passed, the key will be exported to keydata, which must be a {GPGME::Data} object.

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 = nil, seckey = nil)

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.

Used by {GPGME::Ctx#each_key}

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.

Used by {GPGME::Ctx#each_key}

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

Used by {GPGME::Ctx#each_key}

Returns the keys that match the pattern, or all if pattern is nil. Returns only secret keys if secret_only is true.

Return the protocol used within this context.

Set the protocol used within this context. See {GPGME::Ctx.new} for possible values.

Releases the Ctx instance. Must be called if it was initialized without a block.

@example

  ctx = GPGME::Ctx.new
  # operate on ctx
  ctx.release

Set the data pointer to the beginning.

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

  • obj the parameter +:passphrase_callback_value+ passed when creating the {GPGME::Ctx} object.
  • uid_hint hint as to what key are we asking the password for. Ex:

    +CFB3294A50C2CFD7 Albert Llop <mrsimo@example.com>+

  • passphrase_info
  • prev_was_bad 0 if it‘s the first time the password is being asked, 1 otherwise.
  • fd file descriptor where the password must be written too.

Expects a Method object which can be obtained by the method method (really..).

 ctx.set_passphrase_callback(MyModule.method(:passfunc))

@example this method will simply return maria as password.

 def pass_function(obj, uid_hint, passphrase_info, prev_was_bad, fd)
   io = IO.for_fd(fd, 'w')
   io.puts "maria"
   io.flush
 end

@example this will interactively ask for the password

 def passfunc(obj, 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
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]