summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2012-12-04 12:06:31 -0200
committerdrebs <drebs@leap.se>2012-12-04 12:06:31 -0200
commitde920099b67fdee7a2551c7deabec170737c766b (patch)
tree2a9f2e277bf0c284500558a59d85c34a2f51dffb
parent52ed41b982ec43c7cbf6add097abf2db68caaad1 (diff)
Fix json encrypt/decrypt
-rw-r--r--leap.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/leap.py b/leap.py
index b9d253d9..853906a3 100644
--- a/leap.py
+++ b/leap.py
@@ -23,12 +23,12 @@ class LeapDocument(Document):
def __init__(self, doc_id=None, rev=None, json='{}', has_conflicts=False,
encrypted_json=None, default_key=None, gpg_wrapper=None):
super(LeapDocument, self).__init__(doc_id, rev, json, has_conflicts)
- if encrypted_json:
- self.set_encrypted_json(encrypted_json)
if gpg_wrapper:
self._gpg = gpg_wrapper
else:
self._gpg = GPGWrapper()
+ if encrypted_json:
+ self.set_encrypted_json(encrypted_json)
self._default_key = default_key
def get_encrypted_json(self):
@@ -37,15 +37,18 @@ class LeapDocument(Document):
"""
if self._default_key is None:
raise NoDefaultKey()
- cyphertext = self._gpg.encrypt(self.get_json(), self._default_key)
- return json.dumps({'cyphertext' : cyphetext})
+ cyphertext = self._gpg.encrypt(self.get_json(),
+ self._default_key,
+ always_trust = True)
+ # TODO: always trust?
+ return json.dumps({'cyphertext' : str(cyphertext)})
def set_encrypted_json(self, encrypted_json):
"""
Set document's content based on encrypted version of json string.
"""
cyphertext = json.loads(encrypted_json)['cyphertext']
- plaintext = self._gpg.decrypt(cyphertext)
+ plaintext = str(self._gpg.decrypt(cyphertext))
return self.set_json(plaintext)