Skip to content
Snippets Groups Projects
Commit ae6e3594 authored by Paulo Matias's avatar Paulo Matias Committed by Ben Adida
Browse files

EncryptedVote JSON should not contain whitespace

Otherwise the hash displayed in the audited-ballots page will not match
the hash displayed to the user when they prepared their vote.
parent 15cfd7c5
No related branches found
No related tags found
No related merge requests found
...@@ -340,7 +340,7 @@ class EncryptedVote(HeliosObject): ...@@ -340,7 +340,7 @@ class EncryptedVote(HeliosObject):
return True return True
def get_hash(self): def get_hash(self):
return utils.hash_b64(utils.to_json(self.toJSONDict())) return utils.hash_b64(utils.to_json(self.toJSONDict(), no_whitespace=True))
def toJSONDict(self, with_randomness=False): def toJSONDict(self, with_randomness=False):
return { return {
......
...@@ -15,8 +15,11 @@ def hash_b64(s): ...@@ -15,8 +15,11 @@ def hash_b64(s):
result= base64.b64encode(hasher.digest())[:-1] result= base64.b64encode(hasher.digest())[:-1]
return result return result
def to_json(d): def to_json(d, no_whitespace=False):
return json.dumps(d, sort_keys=True) if no_whitespace:
return json.dumps(d, sort_keys=True, separators=(',',':'))
else:
return json.dumps(d, sort_keys=True)
def from_json(json_str): def from_json(json_str):
if not json_str: return None if not json_str: return None
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment