Class: GPGME::SubKey

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

Constant Summary collapse

PUBKEY_ALGO_LETTERS =
{
  PK_RSA => ?R,
  PK_ELG_E => ?g,
  PK_ELG => ?G,
  PK_DSA => ?D
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#fprObject (readonly) Also known as: fingerprint

Returns the value of attribute fpr.



1317
1318
1319
# File 'lib/gpgme.rb', line 1317

def fpr
  @fpr
end

#keyidObject (readonly)

Returns the value of attribute keyid.



1317
1318
1319
# File 'lib/gpgme.rb', line 1317

def keyid
  @keyid
end

#lengthObject (readonly)

Returns the value of attribute length.



1317
1318
1319
# File 'lib/gpgme.rb', line 1317

def length
  @length
end

#pubkey_algoObject (readonly)

Returns the value of attribute pubkey_algo.



1317
1318
1319
# File 'lib/gpgme.rb', line 1317

def pubkey_algo
  @pubkey_algo
end

Instance Method Details

#capabilityObject



1327
1328
1329
1330
1331
1332
1333
1334
# File 'lib/gpgme.rb', line 1327

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

#expiresObject



1352
1353
1354
# File 'lib/gpgme.rb', line 1352

def expires
  Time.at(@expires)
end

#inspectObject



1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
# File 'lib/gpgme.rb', line 1367

def inspect
  sprintf("#<#{self.class} %s %4d%c/%s %s trust=%s, capability=%s>",
          secret? ? 'ssc' : 'sub',
          length,
          pubkey_algo_letter,
          (@fingerprint || @keyid)[-8 .. -1],
          timestamp.strftime('%Y-%m-%d'),
          trust.inspect,
          capability.inspect)
end

#pubkey_algo_letterObject



1363
1364
1365
# File 'lib/gpgme.rb', line 1363

def pubkey_algo_letter
  PUBKEY_ALGO_LETTERS[@pubkey_algo] || ??
end

#secret?Boolean

Returns:

  • (Boolean)


1344
1345
1346
# File 'lib/gpgme.rb', line 1344

def secret?
  @secret == 1
end

#timestampObject



1348
1349
1350
# File 'lib/gpgme.rb', line 1348

def timestamp
  Time.at(@timestamp)
end

#to_sObject



1378
1379
1380
1381
1382
1383
1384
1385
# File 'lib/gpgme.rb', line 1378

def to_s
  sprintf("%s   %4d%c/%s %s\n",
          secret? ? 'ssc' : 'sub',
          length,
          pubkey_algo_letter,
          (@fingerprint || @keyid)[-8 .. -1],
          timestamp.strftime('%Y-%m-%d'))
end

#trustObject



1320
1321
1322
1323
1324
1325
# File 'lib/gpgme.rb', line 1320

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)


1336
1337
1338
1339
1340
1341
1342
# File 'lib/gpgme.rb', line 1336

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