move order logic to xml_elements
This commit is contained in:
parent
3e8534c5c4
commit
a91e3c2c97
2 changed files with 18 additions and 6 deletions
|
|
@ -146,19 +146,26 @@ module DiasporaFederation
|
||||||
Base64.strict_encode64(privkey.sign(DIGEST, signature_data))
|
Base64.strict_encode64(privkey.sign(DIGEST, signature_data))
|
||||||
end
|
end
|
||||||
|
|
||||||
# Sort all XML elements according to the order used for the signatures.
|
# Update the signatures with the keys of the author and the parent
|
||||||
# It updates also the signatures with the keys of the author and the parent
|
|
||||||
# if the signatures are not there yet and if the keys are available.
|
# 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
|
def enriched_properties
|
||||||
data = super.merge(additional_xml_elements)
|
super.merge(additional_xml_elements).tap do |hash|
|
||||||
signature_order.map {|element| [element, data[element] || ""] }.to_h.tap do |hash|
|
|
||||||
hash[:author_signature] = author_signature || sign_with_author
|
hash[:author_signature] = author_signature || sign_with_author
|
||||||
hash[:parent_author_signature] = parent_author_signature || sign_with_parent_author_if_available.to_s
|
hash[:parent_author_signature] = parent_author_signature || sign_with_parent_author_if_available.to_s
|
||||||
end
|
end
|
||||||
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
|
# The order for signing
|
||||||
# @return [Array]
|
# @return [Array]
|
||||||
def signature_order
|
def signature_order
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,7 @@ module DiasporaFederation
|
||||||
def to_xml
|
def to_xml
|
||||||
doc = Nokogiri::XML::DocumentFragment.new(Nokogiri::XML::Document.new)
|
doc = Nokogiri::XML::DocumentFragment.new(Nokogiri::XML::Document.new)
|
||||||
Nokogiri::XML::Element.new(self.class.entity_name, doc).tap do |root_element|
|
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)
|
add_property_to_xml(doc, root_element, name, value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -224,6 +224,11 @@ module DiasporaFederation
|
||||||
normalized_properties
|
normalized_properties
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# default: no special order
|
||||||
|
def xml_elements
|
||||||
|
enriched_properties
|
||||||
|
end
|
||||||
|
|
||||||
def add_property_to_xml(doc, root_element, name, value)
|
def add_property_to_xml(doc, root_element, name, value)
|
||||||
if value.is_a? String
|
if value.is_a? String
|
||||||
root_element << simple_node(doc, name, value)
|
root_element << simple_node(doc, name, value)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue