Class: Hawk::Crypto::Mac
- Inherits:
-
Base
- Object
- Base
- Hawk::Crypto::Mac
show all
- Defined in:
- lib/hawk/crypto.rb
Instance Method Summary
collapse
Methods inherited from Base
#==, #encode64, #eql?, #to_s
Constructor Details
#initialize(key, options, algorithm = 'sha256') ⇒ Mac
Returns a new instance of Mac.
68
69
70
|
# File 'lib/hawk/crypto.rb', line 68
def initialize(key, options, algorithm = 'sha256')
@key, @options, @algorithm = key, options, algorithm
end
|
Instance Method Details
#digest ⇒ Object
100
101
102
|
# File 'lib/hawk/crypto.rb', line 100
def digest
@digest ||= OpenSSL::HMAC.digest(openssl_digest(@algorithm).new, @key, normalized_string)
end
|
#normalized_string ⇒ Object
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/hawk/crypto.rb', line 72
def normalized_string
options = @options.dup
if !options[:hash] && options.has_key?(:payload) && !options[:payload].nil?
options[:hash] = Crypto.hash(options)
end
parts = []
parts << "hawk.1.#{options[:type] || 'header'}"
parts << options[:ts]
parts << options[:nonce]
parts << options[:method].to_s.upcase
parts << options[:request_uri]
parts << options[:host]
parts << options[:port]
parts << options[:hash]
parts << options[:ext]
if options[:app]
parts << options[:app]
parts << options[:dlg]
end
parts << nil
parts.join("\n")
end
|