class GPGME::Key
like email
or name
{.uids}, with a {.primary_uid}, where other attributes are derived from,
Also, every key has at least a {GPGME::UserID}, accessible through
derived from, like the fingerprint
.
{.subkeys}, and with a {.primary_subkey} where most attributes are
Every key has two instances of {GPGME::SubKey}, accessible through
A ruby representation of a public or a secret key.
#
def ==(another_key)
def ==(another_key) self.class === another_key and fingerprint == another_key.fingerprint end
def comment
#
def comment primary_uid.comment end
def delete!(allow_secret = false)
Delete this key. If it's public, and has a secret one it will fail unless
#
def delete!(allow_secret = false) GPGME::Ctx.new do |ctx| ctx.delete_key self, allow_secret end end
def email
#
def email primary_uid.email end
def expired
#
def expired subkeys.any?(&:expired) end
def expires
#
def expires primary_subkey.expires end
def expires?
#
def expires? primary_subkey.expires? end
def export(pattern, options = {})
- Example: writing to a file -
Returns:
-
(GPGME::Data)
- the exported key.
Parameters:
-
options
(Hash
) -- -
pattern
() --
def export(pattern, options = {}) output = Data.new(options[:output]) if options.delete(:minimal) == true export_mode = 4 else export_mode = 0 end GPGME::Ctx.new(options) do |ctx| ctx.export_keys(pattern, output, export_mode) end output.seek(0) output end
def export(options = {})
# => the key will be written to the file.
key.export(:output => file)
file = File.open("key.asc", "w+")
@example
# => GPGME::Data you can read with ASCII armored format
key.export(:armor => true)
@example
{GPGME::Data}, where the output will go.
+options[:output]+, where you can specify something that can become a
Exports this key. Accepts the same options as {GPGME::Ctx.new}, and
#
def export(options = {}) Key.export self.sha, options end
def find(secret, keys_or_names = nil, purposes = [])
# => return the public keys that match mrsimo@example.com and are
GPGME::Key.find(:public, "mrsimo@example.com", :sign)
@example
# => return only public keys that match mrsimo@example.com
GPGME::Key.find(:public, "mrsimo@example.com")
@example
GPGME::Key.find :secret # => first secret key found
@example
See {GPGME::Key} for a list of possible key capabilities.
* +purposes+ get only keys that are usable for any of these purposes.
blank to get all.
elements, or string identifiers like the email or the sha. Leave
* +keys_or_names+ an array or an item that can be either {GPGME::Key}
get only public keys.
* +secret+ set to +:secret+ to get only secret keys, or to +:public+ to
Returns an array of {GPGME::Key} objects that match the parameters.
#
def find(secret, keys_or_names = nil, purposes = []) secret = (secret == :secret) keys_or_names = [""] if keys_or_names.nil? || (keys_or_names.is_a?(Array) && keys_or_names.empty?) keys_or_names = [keys_or_names].flatten purposes = [purposes].flatten.compact.uniq keys = [] keys_or_names.each do |key_or_name| case key_or_name when Key then keys << key_or_name when String GPGME::Ctx.new do |ctx| keys += ctx.keys(key_or_name, secret).select do |k| k.usable_for?(purposes) end end end end keys end
def fingerprint
#
def fingerprint primary_subkey.fingerprint end
def get(fingerprint)
def get(fingerprint) Ctx.new do |ctx| ctx.get_key(fingerprint) end end
def import(keydata, options = {})
-
options
() --
-
keydata
() --
def import(keydata, options = {}) GPGME::Ctx.new(options) do |ctx| ctx.import_keys(Data.new(keydata)) ctx.import_result end end
def inspect
def inspect sprintf("#<#{self.class} %s %4d%s/%s %s trust=%s, owner_trust=%s, \ bility=%s, subkeys=%s, uids=%s>", primary_subkey.secret? ? 'sec' : 'pub', primary_subkey.length, primary_subkey.pubkey_algo_letter, primary_subkey.fingerprint[-8 .. -1], primary_subkey.timestamp.strftime('%Y-%m-%d'), trust.inspect, VALIDITY_NAMES[@owner_trust].inspect, capability.inspect, subkeys.inspect, uids.inspect) end
def name
#
def name primary_uid.name end
def primary_subkey
def primary_subkey @primary_subkey ||= subkeys.first end
def primary_uid
#
def primary_uid uids.first end
def sha
#
def sha primary_subkey.sha end
def to_s
def to_s primary_subkey = subkeys[0] s = sprintf("%s %4d%s/%s %s\n", primary_subkey.secret? ? 'sec' : 'pub', primary_subkey.length, primary_subkey.pubkey_algo_letter, primary_subkey.fingerprint[-8 .. -1], primary_subkey.timestamp.strftime('%Y-%m-%d')) uids.each do |user_id| s << "uid\t\t#{user_id.name} <#{user_id.email}>\n" end subkeys.each do |subkey| s << subkey.to_s end s end
def valid?(key)
def valid?(key) GPGME::Key.import(key).considered == 1 end