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
# File 'lib/hawk/crypto.rb', line 106

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

Instance Method Details

#digestObject



123
124
125
# File 'lib/hawk/crypto.rb', line 123

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

#normalized_stringObject



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

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