diff --git a/helios/crypto/electionalgs.py b/helios/crypto/electionalgs.py index c677140432abd01bb6638ce09977de247c0cc5aa..a17ff6a2ea53d4f655ce32405893d838d86fc504 100644 --- a/helios/crypto/electionalgs.py +++ b/helios/crypto/electionalgs.py @@ -340,7 +340,7 @@ class EncryptedVote(HeliosObject): return True 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): return { diff --git a/helios/crypto/utils.py b/helios/crypto/utils.py index 258f4130cb45bf509bc62710674363830ebe6a5d..9953bdc6aee3c80a3c668dbd0b892a490c879fe6 100644 --- a/helios/crypto/utils.py +++ b/helios/crypto/utils.py @@ -15,8 +15,11 @@ def hash_b64(s): result= base64.b64encode(hasher.digest())[:-1] return result -def to_json(d): - return json.dumps(d, sort_keys=True) +def to_json(d, no_whitespace=False): + if no_whitespace: + return json.dumps(d, sort_keys=True, separators=(',',':')) + else: + return json.dumps(d, sort_keys=True) def from_json(json_str): if not json_str: return None