Commits

William Pitcock committed 78f1c70

message: ensure we copy the dictionary instead of using it by reference

  • Participants
  • Parent commits 7fadc97

Comments (0)

Files changed (1)

     and validation services.
     """
     def __init__(self, obj, secret, expected_hash=None):
-        self.obj = obj
+        self.obj = obj.copy()
         self.secret = secret
         self.expected_hash = None
 
         return json.dumps(self.obj)
 
     def signature(self):
-        return pbkdf2_hex(self.payload_json(), self.secret, keylen=64)
+        return pbkdf2_hex(self.payload_json(), self.secret, iterations=1000, keylen=64)
 
     def dumps(self, pretty_print=False):
         envelope = self.obj
     secret = 'YNvngbwbWgjh4gbjh'
     message = { 'message': 'doStuff', 'params': [1, 2, 3] }
 
-    print dumps(message, secret, True)
+    print "Secret key is %s" % secret
+
+    jmsg = dumps(message, secret, True)
+    print "Signed JSON structure:", jmsg
+
+    print "Attempting to load signed JSON structure..."
+    unpack_message = loads(jmsg, secret)
+
+    print "Verifying that re-signing the structure yields the same structure..."
+    jmsg2 = dumps(unpack_message, secret, True)
+    assert jmsg == jmsg2
+
+    print "All tests complete."