summaryrefslogtreecommitdiff
path: root/backends
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2013-03-05 17:29:37 -0300
committerdrebs <drebs@leap.se>2013-03-05 17:29:37 -0300
commitbf097914f492a2f3973d0b051324d121353fa5fa (patch)
treedbbcadbe7ba5c0a4e2a931bc6ff56a3698847dcc /backends
parent0baf100c59655d1fbe1424f685328ba2de080c98 (diff)
Add a shared remote database to Soledad (client and server).
Diffstat (limited to 'backends')
-rw-r--r--backends/leap_backend.py32
1 files changed, 23 insertions, 9 deletions
diff --git a/backends/leap_backend.py b/backends/leap_backend.py
index 3d423f5d..a37f9d25 100644
--- a/backends/leap_backend.py
+++ b/backends/leap_backend.py
@@ -55,25 +55,39 @@ class LeapDocument(Document):
if encrypted_json:
self.set_encrypted_json(encrypted_json)
- def get_encrypted_json(self):
+ def get_encrypted_content(self):
"""
- Return document's json serialization encrypted with user's public key.
+ Return an encrypted JSON serialization of document's contents.
"""
if not self._soledad:
raise NoSoledadInstance()
- ciphertext = self._soledad.encrypt_symmetric(self.doc_id,
- self.get_json())
- return json.dumps({'_encrypted_json': ciphertext})
+ return self._soledad.encrypt_symmetric(self.doc_id,
+ self.get_json())
+
+ def set_encrypted_content(self, cyphertext):
+ """
+ Set document's content based on an encrypted JSON serialization of
+ contents.
+ """
+ plaintext = self._soledad.decrypt_symmetric(self.doc_id, cyphertext)
+ return self.set_json(plaintext)
+
+ def get_encrypted_json(self):
+ """
+ Return a valid JSON string containing document's content encrypted to
+ the user's public key.
+ """
+ return json.dumps({'_encrypted_json': self.get_encrypted_content()})
def set_encrypted_json(self, encrypted_json):
"""
- Set document's content based on encrypted version of json string.
+ Set document's content based on a valid JSON string containing the
+ encrypted document's contents.
"""
if not self._soledad:
raise NoSoledadInstance()
- ciphertext = json.loads(encrypted_json)['_encrypted_json']
- plaintext = self._soledad.decrypt_symmetric(self.doc_id, ciphertext)
- return self.set_json(plaintext)
+ cyphertext = json.loads(encrypted_json)['_encrypted_json']
+ self.set_encrypted_content(cyphertext)
def _get_syncable(self):
return self._syncable