Class: GPGME::Signature

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#fprObject (readonly) Also known as: fingerprint

Returns the value of attribute fpr.



5
6
7
# File 'lib/gpgme/signature.rb', line 5

def fpr
  @fpr
end

#notationsObject (readonly)

Returns the value of attribute notations.



5
6
7
# File 'lib/gpgme/signature.rb', line 5

def notations
  @notations
end

#pka_addressObject (readonly)

Returns the value of attribute pka_address.



7
8
9
# File 'lib/gpgme/signature.rb', line 7

def pka_address
  @pka_address
end

#pka_trustObject (readonly)

Returns the value of attribute pka_trust.



7
8
9
# File 'lib/gpgme/signature.rb', line 7

def pka_trust
  @pka_trust
end

#statusObject (readonly)

Returns the value of attribute status.



5
6
7
# File 'lib/gpgme/signature.rb', line 5

def status
  @status
end

#summaryObject (readonly)

Returns the value of attribute summary.



5
6
7
# File 'lib/gpgme/signature.rb', line 5

def summary
  @summary
end

#validityObject (readonly)

Returns the value of attribute validity.



6
7
8
# File 'lib/gpgme/signature.rb', line 6

def validity
  @validity
end

#validity_reasonObject (readonly)

Returns the value of attribute validity_reason.



6
7
8
# File 'lib/gpgme/signature.rb', line 6

def validity_reason
  @validity_reason
end

#wrong_key_usageObject (readonly)

Returns the value of attribute wrong_key_usage.



5
6
7
# File 'lib/gpgme/signature.rb', line 5

def wrong_key_usage
  @wrong_key_usage
end

Class Method Details

.new_from_struct(struct) ⇒ Object



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
# File 'lib/gpgme/ffi/signature.rb', line 3

def self.new_from_struct(struct)
  instance = allocate

  instance.instance_exec do
    @summary   = struct[:summary]
    @fpr       = struct[:fpr]
    @status    = struct[:status]

    @notations = []

    pointer = struct[:notations]
    until pointer.null?
      notation = Library::SigNotation.new pointer

      @notations << SigNotation.new_from_struct(notation)

      pointer = notation[:next]
    end

    @timestamp       = struct[:timestamp]
    @exp_timestamp   = struct[:exp_timestamp]
    @wrong_key_usage = (struct[:flags] >> 0) & 1
    @pka_trust       = (struct[:flags] >> 1) & 3
    @chain_model     = (struct[:flags] >> 3) & 1
    @validity        = struct[:validity]
    @validity_reason = struct[:validity_reason]
    @pka_address     = struct[:pka_address]
  end

  instance
end

Instance Method Details

#bad?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/gpgme/signature.rb', line 28

def bad?
  status_code == GPGME::GPG_ERR_BAD_SIGNATURE
end

#exp_timestampObject



64
65
66
# File 'lib/gpgme/signature.rb', line 64

def exp_timestamp
  Time.at(@exp_timestamp)
end

#expired_key?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/gpgme/signature.rb', line 20

def expired_key?
  status_code == GPGME::GPG_ERR_KEY_EXPIRED
end

#expired_signature?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/gpgme/signature.rb', line 16

def expired_signature?
  status_code == GPGME::GPG_ERR_SIG_EXPIRED
end

#fromObject



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/gpgme/signature.rb', line 40

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

#keyObject



52
53
54
55
56
57
58
# File 'lib/gpgme/signature.rb', line 52

def key
  @key ||= begin
    Ctx.new do |ctx|
      @key = ctx.get_key(fingerprint)
    end
  end
end

#no_key?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/gpgme/signature.rb', line 32

def no_key?
  status_code == GPGME::GPG_ERR_NO_PUBKEY
end

#revoked_key?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/gpgme/signature.rb', line 24

def revoked_key?
  status_code == GPGME::GPG_ERR_CERT_REVOKED
end

#status_codeObject



36
37
38
# File 'lib/gpgme/signature.rb', line 36

def status_code
  GPGME::gpgme_err_code(status)
end

#timestampObject



60
61
62
# File 'lib/gpgme/signature.rb', line 60

def timestamp
  Time.at(@timestamp)
end

#to_sObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/gpgme/signature.rb', line 68

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

#valid?Boolean

Returns true if the signature is correct

Returns:

  • (Boolean)


12
13
14
# File 'lib/gpgme/signature.rb', line 12

def valid?
  status_code == GPGME::GPG_ERR_NO_ERROR
end