Module: Linzer::Common

Included in:
Signer, Verifier
Defined in:
lib/linzer/common.rb

Instance Method Summary collapse

Instance Method Details

#signature_base(message, components, parameters) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/linzer/common.rb', line 5

def signature_base(message, components, parameters)
  signature_base = components.each_with_object(+"") do |component, base|
    base << "\"#{component}\": #{message[component]}\n"
  end

  signature_params =
    Starry.serialize([Starry::InnerList.new(components, parameters)])

  signature_base << "\"@signature-params\": #{signature_params}"
  signature_base
end

#validate_components(message, components) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/linzer/common.rb', line 17

def validate_components(message, components)
  if components.include?("@signature-params")
    raise Error.new "Invalid component in signature input"
  end
  msg = "Cannot verify signature. Missing component in message: %s"
  components.each { |c| raise Error.new msg % "\"#{c}\"" unless message.field?(c)  }
  msg = "Invalid signature. Duplicated component in signature input."
  raise Error.new msg if components.size != components.uniq.size
end