Class: Gem::Commands::VerifyCommand

Inherits:
Gem::Command
  • Object
show all
Includes:
UserInteraction, VersionOption
Defined in:
lib/rubygems/commands/verify_command.rb

Overview

Verifies a gem signed by the ‘sign’ command. Iterates through the gem contents and verifies all embedded files, if possible. Errors out if the signature is bad or the key is unknown.

Optionally takes “–get-key” which automatically retreives the key from keyservers to make things easier for people unfamiliar with gpg.

Instance Method Summary collapse

Constructor Details

#initializeVerifyCommand

:nodoc:



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rubygems/commands/verify_command.rb', line 18

def initialize # :nodoc:
  super 'verify', 'Verifies a local gem that has been signed via OpenPGP.  This helps to ensure the gem has not been tampered with in transit.'

  add_version_option

  add_option('--get-key', "If the key is not available, download it from a keyserver") do |key, options|
    options[:get_key] = true
  end

  add_option("--trust",
               'Enforce gnupg trust settings.  Only install if trusted.') do |value, options|
    Gem::OpenPGP.options[:trust] = true
  end

  add_option("--no-trust",
               "Ignoure gnupg trust settings,  even if --trust has previously been specified") do |value, options|
    Gem::OpenPGP.options[:no_trust] = true
  end

end

Instance Method Details

#argumentsObject

:nodoc:



39
40
41
# File 'lib/rubygems/commands/verify_command.rb', line 39

def arguments # :nodoc:
  "GEMNAME        name of gem to verify"
end

#defaults_strObject

:nodoc:



43
44
45
# File 'lib/rubygems/commands/verify_command.rb', line 43

def defaults_str # :nodoc:
  ""
end

#executeObject

:nodoc:



51
52
53
54
55
56
57
58
# File 'lib/rubygems/commands/verify_command.rb', line 51

def execute # :nodoc:
  version = options[:version] || Gem::Requirement.default
  gem, specs = get_one_gem_name, []
  Gem::OpenPGP.verify_gem gem, get_key=options[:get_key]
rescue Gem::OpenPGPException => ex
  alert_error(ex.message)
  terminate_interaction(1)
end

#usageObject

:nodoc:



47
48
49
# File 'lib/rubygems/commands/verify_command.rb', line 47

def usage # :nodoc:
  "gem verify GEMNAME"
end