From bf097914f492a2f3973d0b051324d121353fa5fa Mon Sep 17 00:00:00 2001 From: drebs Date: Tue, 5 Mar 2013 17:29:37 -0300 Subject: Add a shared remote database to Soledad (client and server). --- backends/leap_backend.py | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'backends') 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 -- cgit v1.2.3