##// END OF EJS Templates
Don't stringify content tag twice
neko259 -
r1537:ae763fd6 decentral
parent child Browse files
Show More
@@ -149,7 +149,8 b' class SyncManager:'
149 for tag_model in tag_models:
149 for tag_model in tag_models:
150 tag_content = tag_model.find(TAG_CONTENT)
150 tag_content = tag_model.find(TAG_CONTENT)
151
151
152 signatures = SyncManager._verify_model(tag_content, tag_model)
152 content_str = et.tostring(tag_content, ENCODING_UNICODE)
153 signatures = SyncManager._verify_model(content_str, tag_model)
153
154
154 tag_id = tag_content.find(TAG_ID)
155 tag_id = tag_content.find(TAG_ID)
155 global_id, exists = GlobalId.from_xml_element(tag_id)
156 global_id, exists = GlobalId.from_xml_element(tag_id)
@@ -157,8 +158,7 b' class SyncManager:'
157 if exists:
158 if exists:
158 print('Post with same ID already exists')
159 print('Post with same ID already exists')
159 else:
160 else:
160 global_id.content = et.tostring(tag_content,
161 global_id.content = content_str
161 ENCODING_UNICODE)
162 global_id.save()
162 global_id.save()
163 for signature in signatures:
163 for signature in signatures:
164 signature.global_id = global_id
164 signature.global_id = global_id
@@ -229,7 +229,7 b' class SyncManager:'
229 return et.tostring(response, ENCODING_UNICODE)
229 return et.tostring(response, ENCODING_UNICODE)
230
230
231 @staticmethod
231 @staticmethod
232 def _verify_model(tag_content, tag_model):
232 def _verify_model(content_str, tag_model):
233 """
233 """
234 Verifies all signatures for a single model.
234 Verifies all signatures for a single model.
235 """
235 """
@@ -246,11 +246,8 b' class SyncManager:'
246 key=signature_key,
246 key=signature_key,
247 signature=signature_value)
247 signature=signature_value)
248
248
249 content = et.tostring(tag_content, ENCODING_UNICODE)
249 if not KeyPair.objects.verify(signature, content_str):
250
250 raise SyncException('Invalid model signature for {}'.format(content_str))
251 if not KeyPair.objects.verify(
252 signature, content):
253 raise SyncException('Invalid model signature for {}'.format(content))
254
251
255 signatures.append(signature)
252 signatures.append(signature)
256
253
General Comments 0
You need to be logged in to leave comments. Login now