1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
module GPGME
class Signature
private_class_method :new
attr_reader :summary, :fpr, :status, :notations, :wrong_key_usage
attr_reader :validity, :validity_reason
attr_reader :pka_trust, :pka_address
alias fingerprint fpr
##
# Returns true if the signature is correct
def valid?
status_code == GPGME::GPG_ERR_NO_ERROR
end
def expired_signature?
status_code == GPGME::GPG_ERR_SIG_EXPIRED
end
def expired_key?
status_code == GPGME::GPG_ERR_KEY_EXPIRED
end
def revoked_key?
status_code == GPGME::GPG_ERR_CERT_REVOKED
end
def bad?
status_code == GPGME::GPG_ERR_BAD_SIGNATURE
end
def no_key?
status_code == GPGME::GPG_ERR_NO_PUBKEY
end
def status_code
GPGME::gpgme_err_code(status)
end
def from
@from ||= begin
Ctx.new do |ctx|
if from_key = ctx.get_key(fingerprint)
"#{from_key.subkeys[0].keyid} #{from_key.uids[0].uid}"
else
fingerprint
end
end
end
end
def key
@key ||= begin
Ctx.new do |ctx|
@key = ctx.get_key(fingerprint)
end
end
end
def timestamp
Time.at(@timestamp)
end
def exp_timestamp
Time.at(@exp_timestamp)
end
def to_s
case status_code
when GPGME::GPG_ERR_NO_ERROR
"Good signature from #{from}"
when GPGME::GPG_ERR_SIG_EXPIRED
"Expired signature from #{from}"
when GPGME::GPG_ERR_KEY_EXPIRED
"Signature made from expired key #{from}"
when GPGME::GPG_ERR_CERT_REVOKED
"Signature made from revoked key #{from}"
when GPGME::GPG_ERR_BAD_SIGNATURE
"Bad signature from #{from}"
when GPGME::GPG_ERR_NO_PUBKEY
"No public key for #{from}"
end
end
end
end
|