Class: Hbc::DSL::Gpg

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

Constant Summary collapse

KEY_PARAMETERS =
Set.new [
  :key_id,
  :key_url,
]
VALID_PARAMETERS =
Set.new []

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(signature, parameters = {}) ⇒ Gpg

Returns a new instance of Gpg



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'Library/Homebrew/cask/lib/hbc/dsl/gpg.rb', line 15

def initialize(signature, parameters = {})
  @parameters = parameters
  @signature = URI(signature)
  parameters.each do |hkey, hvalue|
    raise "invalid 'gpg' parameter: '#{hkey.inspect}'" unless VALID_PARAMETERS.include?(hkey)
    writer_method = "#{hkey}=".to_sym
    hvalue = URI(hvalue) if hkey == :key_url
    valid_id?(hvalue) if hkey == :key_id
    send(writer_method, hvalue)
  end
  return if KEY_PARAMETERS.intersection(parameters.keys).length == 1
  raise "'gpg' stanza must include exactly one of: '#{KEY_PARAMETERS.to_a}'"
end

Instance Attribute Details

#signatureObject

Returns the value of attribute signature



13
14
15
# File 'Library/Homebrew/cask/lib/hbc/dsl/gpg.rb', line 13

def signature
  @signature
end

Instance Method Details

#to_sObject



42
43
44
# File 'Library/Homebrew/cask/lib/hbc/dsl/gpg.rb', line 42

def to_s
  @signature.to_s
end

#to_yamlObject



37
38
39
40
# File 'Library/Homebrew/cask/lib/hbc/dsl/gpg.rb', line 37

def to_yaml
  # bug, :key_url value is not represented as an instance of URI
  [@signature, @parameters].to_yaml
end

#valid_id?(id) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
35
# File 'Library/Homebrew/cask/lib/hbc/dsl/gpg.rb', line 29

def valid_id?(id)
  legal_lengths = Set.new [8, 16, 40]
  is_valid = id.is_a?(String) && legal_lengths.include?(id.length) && id[/^[0-9a-f]+$/i]
  raise "invalid ':key_id' value: '#{id.inspect}'" unless is_valid

  is_valid
end