Class: Hawk::Crypto::Hash

Inherits:
Base
  • Object
show all
Defined in:
lib/hawk/crypto.rb

Instance Method Summary collapse

Methods inherited from Base

#==, #encode64, #eql?, #to_s

Constructor Details

#initialize(content_type, payload, algorithm) ⇒ Hash

Returns a new instance of Hash.



106
107
108
109
110
# File 'lib/hawk/crypto.rb', line 106

def initialize(content_type, payload, algorithm)
  @content_type, @payload, @algorithm = content_type, payload, algorithm

  @content_type = @content_type.to_s.split(';').first.to_s.sub(/\A\s*/, '').sub(/\s*\Z/, '')
end

Instance Method Details

#digestObject



125
126
127
# File 'lib/hawk/crypto.rb', line 125

def digest
  @digest ||= openssl_digest(@algorithm).digest(normalized_string)
end

#normalized_stringObject



112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/hawk/crypto.rb', line 112

def normalized_string
  @normalized_string ||= begin
    parts = []

    parts << "hawk.1.payload"
    parts << @content_type
    parts << @payload.to_s
    parts << nil # trailing newline

    parts.join("\n")
  end
end