Module: MAuth::Signable
Overview
module which composes a string to sign.
includer must provide
-
SIGNATURE_COMPONENTS constant - array of keys to get from #attributes_for_signing
-
#attributes_for_signing
-
#merge_headers (takes a Hash of headers; returns an instance of includer’s own class whose headers have been updated with the argument headers)
Instance Method Summary collapse
- #attributes_for_signing ⇒ Object
- #initialize(attributes_for_signing) ⇒ Object
-
#string_to_sign(more_attributes) ⇒ Object
composes a string suitable for private-key signing from the SIGNATURE_COMPONENTS keys of attributes for signing, which are themselves taken from #attributes_for_signing and the given argument more_attributes.
Instance Method Details
#attributes_for_signing ⇒ Object
30 31 32 |
# File 'lib/mauth/request_and_response.rb', line 30 def attributes_for_signing @attributes_for_signing end |
#initialize(attributes_for_signing) ⇒ Object
26 27 28 |
# File 'lib/mauth/request_and_response.rb', line 26 def initialize(attributes_for_signing) @attributes_for_signing = attributes_for_signing end |
#string_to_sign(more_attributes) ⇒ Object
composes a string suitable for private-key signing from the SIGNATURE_COMPONENTS keys of attributes for signing, which are themselves taken from #attributes_for_signing and the given argument more_attributes
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/mauth/request_and_response.rb', line 15 def string_to_sign(more_attributes) attributes_for_signing = self.attributes_for_signing.merge(more_attributes) missing_attributes = self.class::SIGNATURE_COMPONENTS.select { |key| !attributes_for_signing.key?(key) || attributes_for_signing[key].nil? } missing_attributes.delete(:body) # body may be omitted if missing_attributes.any? raise(UnableToSignError, "Missing required attributes to sign: #{missing_attributes.inspect}\non object to sign: #{inspect}") end string = self.class::SIGNATURE_COMPONENTS.map { |k| attributes_for_signing[k].to_s }.join("\n") Digest::SHA512.hexdigest(string) end |