Module: Hawk::TimestampMacHeader

Extended by:
TimestampMacHeader
Included in:
TimestampMacHeader
Defined in:
lib/hawk/timestamp_mac_header.rb

Constant Summary collapse

REQUIRED_CREDENTIAL_MEMBERS =
AuthorizationHeader::REQUIRED_CREDENTIAL_MEMBERS
SUPPORTED_ALGORITHMS =
AuthorizationHeader::SUPPORTED_ALGORITHMS
InvalidCredentialsError =
Class.new(StandardError)
InvalidAlgorithmError =
Class.new(StandardError)

Instance Method Summary collapse

Instance Method Details

#build(options) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/hawk/timestamp_mac_header.rb', line 11

def build(options)
  options[:ts] ||= Time.now.to_i

  credentials = options[:credentials]
  REQUIRED_CREDENTIAL_MEMBERS.each do |key|
    unless credentials.has_key?(key)
      raise InvalidCredentialsError.new("#{key.inspect} is missing!")
    end
  end

  unless SUPPORTED_ALGORITHMS.include?(credentials[:algorithm])
    raise InvalidAlgorithmError.new("#{credentials[:algorithm].inspect} is not a supported algorithm! Use one of the following: #{SUPPORTED_ALGORITHMS.join(', ')}")
  end

  tsm = Crypto.ts_mac(options)

  %(Hawk ts="#{options[:ts]}", tsm="#{tsm}")
end