diff --git a/lib/diaspora_federation/entities/relayable.rb b/lib/diaspora_federation/entities/relayable.rb index df8818f..1cc3d77 100644 --- a/lib/diaspora_federation/entities/relayable.rb +++ b/lib/diaspora_federation/entities/relayable.rb @@ -146,19 +146,26 @@ module DiasporaFederation Base64.strict_encode64(privkey.sign(DIGEST, signature_data)) end - # Sort all XML elements according to the order used for the signatures. - # It updates also the signatures with the keys of the author and the parent + # Update the signatures with the keys of the author and the parent # if the signatures are not there yet and if the keys are available. # - # @return [Hash] sorted xml elements with updated signatures + # @return [Hash] properties with updated signatures def enriched_properties - data = super.merge(additional_xml_elements) - signature_order.map {|element| [element, data[element] || ""] }.to_h.tap do |hash| + super.merge(additional_xml_elements).tap do |hash| hash[:author_signature] = author_signature || sign_with_author hash[:parent_author_signature] = parent_author_signature || sign_with_parent_author_if_available.to_s end end + # Sort all XML elements according to the order used for the signatures. + # + # @return [Hash] sorted xml elements + def xml_elements + data = super + order = signature_order + %i(author_signature parent_author_signature) + order.map {|element| [element, data[element] || ""] }.to_h + end + # The order for signing # @return [Array] def signature_order diff --git a/lib/diaspora_federation/entity.rb b/lib/diaspora_federation/entity.rb index 34b1874..5bbb64d 100644 --- a/lib/diaspora_federation/entity.rb +++ b/lib/diaspora_federation/entity.rb @@ -96,7 +96,7 @@ module DiasporaFederation def to_xml doc = Nokogiri::XML::DocumentFragment.new(Nokogiri::XML::Document.new) Nokogiri::XML::Element.new(self.class.entity_name, doc).tap do |root_element| - enriched_properties.each do |name, value| + xml_elements.each do |name, value| add_property_to_xml(doc, root_element, name, value) end end @@ -224,6 +224,11 @@ module DiasporaFederation normalized_properties end + # default: no special order + def xml_elements + enriched_properties + end + def add_property_to_xml(doc, root_element, name, value) if value.is_a? String root_element << simple_node(doc, name, value)