Object
A context within which all cryptographic operations are performed.
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.
# File lib/gpgme.rb, line 917 def self.new(options = Hash.new) rctx = Array.new err = GPGME::gpgme_new(rctx) exc = GPGME::error_to_exception(err) raise exc if exc ctx = rctx[0] options.each_pair do |key, value| case key when :protocol ctx.protocol = value when :armor ctx.armor = value when :textmode ctx.textmode = value when :keylist_mode ctx.keylist_mode = value when :passphrase_callback ctx.set_passphrase_callback(value, options[:passphrase_callback_value]) when :progress_callback ctx.set_progress_callback(value, options[:progress_callback_value]) end end if block_given? begin yield ctx ensure GPGME::gpgme_release(ctx) end else ctx end end
Add keys to the list of signers.
# File lib/gpgme.rb, line 1224 def add_signer(*keys) keys.each do |key| err = GPGME::gpgme_signers_add(self, key) exc = GPGME::error_to_exception(err) raise exc if exc end end
Return true if the output is ASCII armored.
# File lib/gpgme.rb, line 972 def armor GPGME::gpgme_get_armor(self) == 1 ? true : false end
Tell whether the output should be ASCII armored.
# File lib/gpgme.rb, line 966 def armor=(yes) GPGME::gpgme_set_armor(self, yes ? 1 : 0) yes end
Remove the list of signers from this object.
# File lib/gpgme.rb, line 1219 def clear_signers GPGME::gpgme_signers_clear(self) end
Decrypt the ciphertext and return the plaintext.
# File lib/gpgme.rb, line 1180 def decrypt(cipher, plain = Data.new) err = GPGME::gpgme_op_decrypt(self, cipher, plain) exc = GPGME::error_to_exception(err) raise exc if exc plain end
# File lib/gpgme.rb, line 1194 def decrypt_result GPGME::gpgme_op_decrypt_result(self) end
# File lib/gpgme.rb, line 1187 def decrypt_verify(cipher, plain = Data.new) err = GPGME::gpgme_op_decrypt_verify(self, cipher, plain) exc = GPGME::error_to_exception(err) raise exc if exc plain end
Delete the key from the key ring. If allow_secret is false, only public keys are deleted, otherwise secret keys are deleted as well.
# File lib/gpgme.rb, line 1155 def delete_key(key, allow_secret = false) err = GPGME::gpgme_op_delete(self, key, allow_secret ? 1 : 0) exc = GPGME::error_to_exception(err) raise exc if exc end
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.
# File lib/gpgme.rb, line 1074 def each_key(pattern = nil, secret_only = false, &block) # :yields: key keylist_start(pattern, secret_only) begin loop do yield keylist_next end keys rescue EOFError # The last key in the list has already been returned. ensure keylist_end end end
Edit attributes of the key on the card.
# File lib/gpgme.rb, line 1171 def edit_card_key(key, editfunc, hook_value = nil, out = Data.new) err = GPGME::gpgme_op_card_edit(self, key, editfunc, hook_value, out) exc = GPGME::error_to_exception(err) raise exc if exc end
Edit attributes of the key in the local key ring.
# File lib/gpgme.rb, line 1163 def edit_key(key, editfunc, hook_value = nil, out = Data.new) err = GPGME::gpgme_op_edit(self, key, editfunc, hook_value, out) exc = GPGME::error_to_exception(err) raise exc if exc end
Encrypt the plaintext in the data object for the recipients and return the ciphertext.
# File lib/gpgme.rb, line 1248 def encrypt(recp, plain, cipher = Data.new, flags = 0) err = GPGME::gpgme_op_encrypt(self, recp, flags, plain, cipher) exc = GPGME::error_to_exception(err) raise exc if exc cipher end
# File lib/gpgme.rb, line 1255 def encrypt_result GPGME::gpgme_op_encrypt_result(self) end
# File lib/gpgme.rb, line 1259 def encrypt_sign(recp, plain, cipher = Data.new, flags = 0) err = GPGME::gpgme_op_encrypt_sign(self, recp, flags, plain, cipher) exc = GPGME::error_to_exception(err) raise exc if exc cipher end
Extract the public keys of the recipients.
# File lib/gpgme.rb, line 1132 def export_keys(recipients, keydata = Data.new) err = GPGME::gpgme_op_export(self, recipients, 0, keydata) exc = GPGME::error_to_exception(err) raise exc if exc keydata end
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.
# File lib/gpgme.rb, line 1124 def generate_key(parms, pubkey = Data.new, seckey = Data.new) err = GPGME::gpgme_op_genkey(self, parms, pubkey, seckey) exc = GPGME::error_to_exception(err) raise exc if exc end
Get the key with the fingerprint. If secret is true, secret key is returned.
# File lib/gpgme.rb, line 1099 def get_key(fingerprint, secret = false) rkey = Array.new err = GPGME::gpgme_get_key(self, fingerprint, rkey, secret ? 1 : 0) exc = GPGME::error_to_exception(err) raise exc if exc rkey[0] end
Add the keys in the data buffer to the key ring.
# File lib/gpgme.rb, line 1141 def import_keys(keydata) err = GPGME::gpgme_op_import(self, keydata) exc = GPGME::error_to_exception(err) raise exc if exc end
# File lib/gpgme.rb, line 1148 def import_result GPGME::gpgme_op_import_result(self) end
# File lib/gpgme.rb, line 998 def inspect "#<#{self.class} protocol=#{PROTOCOL_NAMES[protocol] || protocol}, \ armor=#{armor}, textmode=#{textmode}, \ keylist_mode=#{KEYLIST_MODE_NAMES[keylist_mode]}>" end
End a pending key list operation.
# File lib/gpgme.rb, line 1064 def keylist_end err = GPGME::gpgme_op_keylist_end(self) exc = GPGME::error_to_exception(err) raise exc if exc end
Return the current key listing mode.
# File lib/gpgme.rb, line 994 def keylist_mode GPGME::gpgme_get_keylist_mode(self) end
Change the default behaviour of the key listing functions.
# File lib/gpgme.rb, line 988 def keylist_mode=(mode) GPGME::gpgme_set_keylist_mode(self, mode) mode end
Advance to the next key in the key listing operation.
# File lib/gpgme.rb, line 1055 def keylist_next rkey = Array.new err = GPGME::gpgme_op_keylist_next(self, rkey) exc = GPGME::error_to_exception(err) raise exc if exc rkey[0] end
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.
# File lib/gpgme.rb, line 1048 def keylist_start(pattern = nil, secret_only = false) err = GPGME::gpgme_op_keylist_start(self, pattern, secret_only ? 1 : 0) exc = GPGME::error_to_exception(err) raise exc if exc end
# File lib/gpgme.rb, line 1089 def keys(pattern = nil, secret_only = nil) keys = Array.new each_key(pattern, secret_only) do |key| keys << key end keys end
Return the protocol used within this context.
# File lib/gpgme.rb, line 961 def protocol GPGME::gpgme_get_protocol(self) end
Set the protocol used within this context.
# File lib/gpgme.rb, line 953 def protocol=(proto) err = GPGME::gpgme_set_protocol(self, proto) exc = GPGME::error_to_exception(err) raise exc if exc proto end
Set the data pointer to the beginning.
# File lib/gpgme/compat.rb, line 24 def rewind seek(0) end
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))
# File lib/gpgme.rb, line 1024 def set_passphrase_callback(passfunc, hook_value = nil) GPGME::gpgme_set_passphrase_cb(self, passfunc, hook_value) 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))
# File lib/gpgme.rb, line 1039 def set_progress_callback(progfunc, hook_value = nil) GPGME::gpgme_set_progress_cb(self, progfunc, hook_value) end
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.
# File lib/gpgme.rb, line 1235 def sign(plain, sig = Data.new, mode = GPGME::SIG_MODE_NORMAL) err = GPGME::gpgme_op_sign(self, plain, sig, mode) exc = GPGME::error_to_exception(err) raise exc if exc sig end
# File lib/gpgme.rb, line 1242 def sign_result GPGME::gpgme_op_sign_result(self) end
Return true if canonical text mode is enabled.
# File lib/gpgme.rb, line 983 def textmode GPGME::gpgme_get_textmode(self) == 1 ? true : false end
Tell whether canonical text mode should be used.
# File lib/gpgme.rb, line 977 def textmode=(yes) GPGME::gpgme_set_textmode(self, yes ? 1 : 0) yes end
Verify that the signature in the data object is a valid signature.
# File lib/gpgme.rb, line 1199 def verify(sig, signed_text = nil, plain = Data.new) err = GPGME::gpgme_op_verify(self, sig, signed_text, plain) exc = GPGME::error_to_exception(err) raise exc if exc plain end
Generated with the Darkfish Rdoc Generator 2.