forked from MirrorHub/synapse
fix pyflakes warnings
This commit is contained in:
parent
acb2d171e8
commit
5e2236f9ff
3 changed files with 6 additions and 6 deletions
|
@ -35,12 +35,12 @@ def add_event_pdu_content_hash(pdu, hash_algorithm=hashlib.sha256):
|
||||||
|
|
||||||
def check_event_pdu_content_hash(pdu, hash_algorithm=hashlib.sha256):
|
def check_event_pdu_content_hash(pdu, hash_algorithm=hashlib.sha256):
|
||||||
"""Check whether the hash for this PDU matches the contents"""
|
"""Check whether the hash for this PDU matches the contents"""
|
||||||
computed_hash = _compute_content_hash(pdu, hash_algortithm)
|
computed_hash = _compute_content_hash(pdu, hash_algorithm)
|
||||||
if computed_hash.name not in pdu.hashes:
|
if computed_hash.name not in pdu.hashes:
|
||||||
raise Exception("Algorithm %s not in hashes %s" % (
|
raise Exception("Algorithm %s not in hashes %s" % (
|
||||||
computed_hash.name, list(pdu.hashes)
|
computed_hash.name, list(pdu.hashes)
|
||||||
))
|
))
|
||||||
message_hash_base64 = hashes[computed_hash.name]
|
message_hash_base64 = pdu.hashes[computed_hash.name]
|
||||||
try:
|
try:
|
||||||
message_hash_bytes = decode_base64(message_hash_base64)
|
message_hash_bytes = decode_base64(message_hash_base64)
|
||||||
except:
|
except:
|
||||||
|
@ -54,7 +54,7 @@ def _compute_content_hash(pdu, hash_algorithm):
|
||||||
pdu_json.pop("age_ts", None)
|
pdu_json.pop("age_ts", None)
|
||||||
pdu_json.pop("unsigned", None)
|
pdu_json.pop("unsigned", None)
|
||||||
pdu_json.pop("signatures", None)
|
pdu_json.pop("signatures", None)
|
||||||
hashes = pdu_json.pop("hashes", {})
|
pdu_json.pop("hashes", None)
|
||||||
pdu_json_bytes = encode_canonical_json(pdu_json)
|
pdu_json_bytes = encode_canonical_json(pdu_json)
|
||||||
return hash_algorithm(pdu_json_bytes)
|
return hash_algorithm(pdu_json_bytes)
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ def sign_event_pdu(pdu, signature_name, signing_key):
|
||||||
tmp_pdu = Pdu(**pdu.get_dict())
|
tmp_pdu = Pdu(**pdu.get_dict())
|
||||||
tmp_pdu = prune_pdu(tmp_pdu)
|
tmp_pdu = prune_pdu(tmp_pdu)
|
||||||
pdu_json = tmp_pdu.get_dict()
|
pdu_json = tmp_pdu.get_dict()
|
||||||
pdu_jdon = sign_json(pdu_json, signature_name, signing_key)
|
pdu_json = sign_json(pdu_json, signature_name, signing_key)
|
||||||
pdu.signatures = pdu_json["signatures"]
|
pdu.signatures = pdu_json["signatures"]
|
||||||
return pdu
|
return pdu
|
||||||
|
|
||||||
|
|
|
@ -155,6 +155,8 @@ class Pdu(JsonEncodedObject):
|
||||||
|
|
||||||
return Pdu(
|
return Pdu(
|
||||||
prev_pdus=prev_pdus,
|
prev_pdus=prev_pdus,
|
||||||
|
hashes=hashes,
|
||||||
|
signatures=signatures,
|
||||||
**args
|
**args
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -15,8 +15,6 @@
|
||||||
|
|
||||||
from _base import SQLBaseStore
|
from _base import SQLBaseStore
|
||||||
|
|
||||||
from twisted.internet import defer
|
|
||||||
|
|
||||||
|
|
||||||
class SignatureStore(SQLBaseStore):
|
class SignatureStore(SQLBaseStore):
|
||||||
"""Persistence for PDU signatures and hashes"""
|
"""Persistence for PDU signatures and hashes"""
|
||||||
|
|
Loading…
Reference in a new issue