Class: GPGME::Key

Inherits:
Object
  • Object
show all
Defined in:
lib/gpgme.rb

Overview

A public or secret key.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#chain_idObject (readonly)

Returns the value of attribute chain_id.



1249
1250
1251
# File 'lib/gpgme.rb', line 1249

def chain_id
  @chain_id
end

#issuer_nameObject (readonly)

Returns the value of attribute issuer_name.



1249
1250
1251
# File 'lib/gpgme.rb', line 1249

def issuer_name
  @issuer_name
end

#issuer_serialObject (readonly)

Returns the value of attribute issuer_serial.



1249
1250
1251
# File 'lib/gpgme.rb', line 1249

def issuer_serial
  @issuer_serial
end

#keylist_modeObject (readonly)

Returns the value of attribute keylist_mode.



1248
1249
1250
# File 'lib/gpgme.rb', line 1248

def keylist_mode
  @keylist_mode
end

#owner_trustObject (readonly)

Returns the value of attribute owner_trust.



1248
1249
1250
# File 'lib/gpgme.rb', line 1248

def owner_trust
  @owner_trust
end

#protocolObject (readonly)

Returns the value of attribute protocol.



1248
1249
1250
# File 'lib/gpgme.rb', line 1248

def protocol
  @protocol
end

#subkeysObject (readonly)

Returns the value of attribute subkeys.



1250
1251
1252
# File 'lib/gpgme.rb', line 1250

def subkeys
  @subkeys
end

#uidsObject (readonly)

Returns the value of attribute uids.



1250
1251
1252
# File 'lib/gpgme.rb', line 1250

def uids
  @uids
end

Instance Method Details

#capabilityObject



1259
1260
1261
1262
1263
1264
1265
1266
# File 'lib/gpgme.rb', line 1259

def capability
  caps = Array.new
  caps << :encrypt if @can_encrypt
  caps << :sign if @can_sign
  caps << :certify if @can_certify
  caps << :authenticate if @can_authenticate
  caps
end

#inspectObject



1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
# File 'lib/gpgme.rb', line 1280

def inspect
  primary_subkey = subkeys[0]
  sprintf("#<#{self.class} %s %4d%c/%s %s trust=%s, owner_trust=%s, \
capability=%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

#secret?Boolean

Returns:

  • (Boolean)


1276
1277
1278
# File 'lib/gpgme.rb', line 1276

def secret?
  @secret == 1
end

#to_sObject



1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
# File 'lib/gpgme.rb', line 1296

def to_s
  primary_subkey = subkeys[0]
  s = sprintf("%s   %4d%c/%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

#trustObject



1252
1253
1254
1255
1256
1257
# File 'lib/gpgme.rb', line 1252

def trust
  return :revoked if @revoked == 1
  return :expired if @expired == 1
  return :disabled if @disabled == 1
  return :invalid if @invalid == 1
end

#usable_for?(purposes) ⇒ Boolean

Returns:

  • (Boolean)


1268
1269
1270
1271
1272
1273
1274
# File 'lib/gpgme.rb', line 1268

def usable_for?(purposes)
  unless purposes.kind_of? Array
    purposes = [purposes]
  end
  return false if [:revoked, :expired, :disabled, :invalid].include? trust
  return (purposes - capability).empty?
end