File: sub_key.rb

package info (click to toggle)
ruby-gpgme 2.0.5-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,348 kB
  • ctags: 342
  • sloc: ruby: 2,921; ansic: 2,259; makefile: 3
file content (58 lines) | stat: -rw-r--r-- 1,240 bytes parent folder | download | duplicates (2)
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
module GPGME
  class SubKey
    private_class_method :new

    attr_reader :pubkey_algo, :length, :keyid, :fpr
    alias fingerprint fpr

    include KeyCommon

    def timestamp
      Time.at(@timestamp)
    end

    def expires
      Time.at(@expires)
    end

    def expired
      return false if @expires == 0
      @expires < Time.now.to_i
    end

    def sha
      (@fingerprint || @keyid)[-8 .. -1]
    end

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

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

    def inspect
      sprintf("#<#{self.class} %s %4d%s/%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

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