diff --git a/boards/models/post/sync.py b/boards/models/post/sync.py --- a/boards/models/post/sync.py +++ b/boards/models/post/sync.py @@ -149,7 +149,8 @@ class SyncManager: for tag_model in tag_models: tag_content = tag_model.find(TAG_CONTENT) - signatures = SyncManager._verify_model(tag_content, tag_model) + content_str = et.tostring(tag_content, ENCODING_UNICODE) + signatures = SyncManager._verify_model(content_str, tag_model) tag_id = tag_content.find(TAG_ID) global_id, exists = GlobalId.from_xml_element(tag_id) @@ -157,8 +158,7 @@ class SyncManager: if exists: print('Post with same ID already exists') else: - global_id.content = et.tostring(tag_content, - ENCODING_UNICODE) + global_id.content = content_str global_id.save() for signature in signatures: signature.global_id = global_id @@ -229,7 +229,7 @@ class SyncManager: return et.tostring(response, ENCODING_UNICODE) @staticmethod - def _verify_model(tag_content, tag_model): + def _verify_model(content_str, tag_model): """ Verifies all signatures for a single model. """ @@ -246,11 +246,8 @@ class SyncManager: key=signature_key, signature=signature_value) - content = et.tostring(tag_content, ENCODING_UNICODE) - - if not KeyPair.objects.verify( - signature, content): - raise SyncException('Invalid model signature for {}'.format(content)) + if not KeyPair.objects.verify(signature, content_str): + raise SyncException('Invalid model signature for {}'.format(content_str)) signatures.append(signature)