File: key_common.rb

package info (click to toggle)
ruby-gpgme 2.0.23-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,920 kB
  • sloc: ruby: 3,129; ansic: 2,559; sh: 7; makefile: 5
file content (43 lines) | stat: -rw-r--r-- 1,185 bytes parent folder | download | duplicates (4)
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
module GPGME
  module KeyCommon

    ##
    # Returns nil if the trust is valid.
    # Returns one of +:revoked+, +:expired+, +:disabled+, +:invalid+
    def trust
      return :revoked if @revoked == 1
      return :expired if @expired == 1
      return :disabled if @disabled == 1
      return :invalid if @invalid == 1
    end

    ##
    # Array of capabilities for this key. It can contain any combination of
    # +:encrypt+, +:sign+, +:certify+ or +:authenticate+
    def capability
      caps = []
      caps << :encrypt if @can_encrypt == 1
      caps << :sign if @can_sign == 1
      caps << :certify if @can_certify == 1
      caps << :authenticate if @can_authenticate == 1
      caps
    end

    ##
    # Checks if the key is capable of all of these actions. If empty array
    # is passed then will return true.
    #
    # Returns false if the keys trust has been invalidated.
    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

    def secret?
      @secret == 1
    end
  end
end