| Class | GPGME::Ctx |
| In: |
lib/gpgme/compat.rb
lib/gpgme/ctx.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.
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
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.
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.
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}
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 passphrase callback with given hook value. passfunc should respond to call with 5 arguments.
+CFB3294A50C2CFD7 Albert Llop <mrsimo@example.com>+
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 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))
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.