Module: Enigma
Defined Under Namespace
Classes: Client
Constant Summary collapse
- SIGNATURE_HEADER =
"X_ENIGMA_SIGNATURE"
Class Method Summary collapse
Instance Method Summary collapse
- #matches?(actual_signature, method, path, payload) ⇒ Boolean
- #signature(method, path, payload) ⇒ Object
Class Method Details
.server_key ⇒ Object
15 16 17 |
# File 'lib/enigma.rb', line 15 def self.server_key @server_key end |
.server_key=(server_key) ⇒ Object
11 12 13 |
# File 'lib/enigma.rb', line 11 def self.server_key=(server_key) @server_key = server_key end |
Instance Method Details
#matches?(actual_signature, method, path, payload) ⇒ Boolean
26 27 28 29 30 31 32 33 34 |
# File 'lib/enigma.rb', line 26 def matches?(actual_signature, method, path, payload) matched = true expected_signature = self.signature(method, path, payload) expected_signature.each_char.zip(actual_signature.to_s.each_char).each do |expected, actual| matched = false if expected != actual end matched end |
#signature(method, path, payload) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/enigma.rb', line 19 def signature(method, path, payload) = [method, path, payload].map(&:to_s).inject(&:+) digest = OpenSSL::Digest::Digest.new("sha512") OpenSSL::HMAC.hexdigest(digest, self.server_key, ).to_s end |