Module: Gem::OpenPGP::KeyMaster

Defined in:
lib/rubygems/openpgp/keymaster.rb

Overview

Capture used signing keys so we can see if they changed.

Constant Summary collapse

SETTING_DIR =
".rubygems-openpgp"
KEYMASTER_FILE =
"known_gems"

Class Method Summary collapse

Class Method Details

.add_fingerprint(gem_name, fingerprint) ⇒ Object



53
54
55
56
57
# File 'lib/rubygems/openpgp/keymaster.rb', line 53

def self.add_fingerprint gem_name, fingerprint
  fingerprints = load_fingerprints
  fingerprints[gem_name] = fingerprint
  save_fingerprints fingerprints
end

.check_fingerprint(gem_name, fingerprint) ⇒ Object

Check that an existing gem fingerprint matches a given fingerprint. In the case we haven’t seen the gem before, we’ll add the fingerprint and won’t complain.



62
63
64
65
66
67
68
69
70
71
# File 'lib/rubygems/openpgp/keymaster.rb', line 62

def self.check_fingerprint gem_name, fingerprint
  fingerprints = load_fingerprints
  
  if !fingerprints.has_key?(gem_name)
    add_fingerprint gem_name, fingerprint
    return true
  end

  fingerprints[gem_name] == fingerprint
end

.full_setting_filenameObject



7
8
9
10
# File 'lib/rubygems/openpgp/keymaster.rb', line 7

def self.full_setting_filename
  home_dir = ENV["HOME"] || ENV["HOMEPATH"]
  File.join(home_dir, SETTING_DIR, KEYMASTER_FILE)
end

.get_fingerprint(gem_name) ⇒ Object



49
50
51
# File 'lib/rubygems/openpgp/keymaster.rb', line 49

def self.get_fingerprint gem_name
  load_fingerprints[gem_name]
end

.load_fingerprintsObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rubygems/openpgp/keymaster.rb', line 23

def self.load_fingerprints
  touch_keymaster_file

  home_dir = ENV["HOME"] || ENV["HOMEPATH"]

  fingerprints = {}
  File.open(full_setting_filename) do |f|
    f.readlines.each do |line|
      gem, fingerprint = line.strip.split("\t")
      fingerprints[gem] = fingerprint
    end
  end

  fingerprints
end

.save_fingerprints(fingerprints) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/rubygems/openpgp/keymaster.rb', line 39

def self.save_fingerprints fingerprints
  touch_keymaster_file

  File.open(full_setting_filename,"w") do |f|
    fingerprints.each_pair do |gem, fingerprint|
      f.puts("#{gem}\t#{fingerprint}")
    end
  end
end

.touch_keymaster_fileObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/rubygems/openpgp/keymaster.rb', line 12

def self.touch_keymaster_file
  home_dir = ENV["HOME"] || ENV["HOMEPATH"]
  
  setting_dir = File.join(home_dir, SETTING_DIR)
  Dir.mkdir(setting_dir, 0700) if !File.directory? setting_dir

  if !File.exists?(full_setting_filename)
    File.open(full_setting_filename,"w").close
  end
end