Class: Hbc::Verify::Gpg

Inherits:
Object
  • Object
show all
Defined in:
Library/Homebrew/cask/lib/hbc/verify/gpg.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cask, downloaded_path, command = Hbc::SystemCommand) ⇒ Gpg

Returns a new instance of Gpg



10
11
12
13
14
# File 'Library/Homebrew/cask/lib/hbc/verify/gpg.rb', line 10

def initialize(cask, downloaded_path, command = Hbc::SystemCommand)
  @command = command
  @cask = cask
  @downloaded_path = downloaded_path
end

Instance Attribute Details

#caskObject (readonly)

Returns the value of attribute cask



8
9
10
# File 'Library/Homebrew/cask/lib/hbc/verify/gpg.rb', line 8

def cask
  @cask
end

#downloaded_pathObject (readonly)

Returns the value of attribute downloaded_path



8
9
10
# File 'Library/Homebrew/cask/lib/hbc/verify/gpg.rb', line 8

def downloaded_path
  @downloaded_path
end

Class Method Details

.me?(cask) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
# File 'Library/Homebrew/cask/lib/hbc/verify/gpg.rb', line 4

def self.me?(cask)
  cask.gpg
end

Instance Method Details

#available?Boolean

Returns:

  • (Boolean)


16
17
18
19
# File 'Library/Homebrew/cask/lib/hbc/verify/gpg.rb', line 16

def available?
  return @available unless @available.nil?
  @available = self.class.me?(cask) && installed?
end

#fetch_sig(force = false) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'Library/Homebrew/cask/lib/hbc/verify/gpg.rb', line 29

def fetch_sig(force = false)
  unversioned_cask = cask.version.is_a?(Symbol)
  cached = cask.("gpg") unless unversioned_cask

  meta_dir = cached || cask.("gpg", :now, true)
  sig_path = meta_dir.join("signature.asc")

  curl_download cask.gpg.signature, to: sig_path unless cached || force

  sig_path
end

#import_keyObject



41
42
43
44
45
46
47
48
49
# File 'Library/Homebrew/cask/lib/hbc/verify/gpg.rb', line 41

def import_key
  args = if cask.gpg.key_id
    ["--recv-keys", cask.gpg.key_id]
  elsif cask.gpg.key_url
    ["--fetch-key", cask.gpg.key_url.to_s]
  end

  @command.run!("gpg", args: args)
end

#installed?Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
27
# File 'Library/Homebrew/cask/lib/hbc/verify/gpg.rb', line 21

def installed?
  cmd = @command.run("/usr/bin/type",
                     args: ["-p", "gpg"])

  # if `gpg` is found, return its absolute path
  cmd.success? ? cmd.stdout : false
end

#verifyObject



51
52
53
54
55
56
57
58
59
60
61
# File 'Library/Homebrew/cask/lib/hbc/verify/gpg.rb', line 51

def verify
  return unless available?
  import_key
  sig = fetch_sig

  ohai "Verifying GPG signature for #{cask}"

  @command.run!("gpg",
                args:         ["--verify", sig, downloaded_path],
                print_stdout: true)
end