summaryrefslogtreecommitdiff
path: root/src
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
commita2c076b8d142ea75721dd25a655f72fc9457f222 (patch)
treea4aa0118cc88272efabb26201ba9870a0c864f09 /src
parentdc84b200916a5f6677f6b1735fd58a6383b0734e (diff)
Fix json encrypt/decrypt
Diffstat (limited to 'src')
-rw-r--r--src/leap/soledad/leap.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/leap/soledad/leap.py b/src/leap/soledad/leap.py
index b9d253d9..853906a3 100644
--- a/src/leap/soledad/leap.py
+++ b/src/leap/soledad/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)