diff options
Diffstat (limited to 'service')
-rw-r--r-- | service/pixelated/adapter/soledad/soledad_search_key_masterkey_retrieval_mixin.py | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/service/pixelated/adapter/soledad/soledad_search_key_masterkey_retrieval_mixin.py b/service/pixelated/adapter/soledad/soledad_search_key_masterkey_retrieval_mixin.py index f8fed0aa..14472693 100644 --- a/service/pixelated/adapter/soledad/soledad_search_key_masterkey_retrieval_mixin.py +++ b/service/pixelated/adapter/soledad/soledad_search_key_masterkey_retrieval_mixin.py @@ -16,14 +16,17 @@ from pixelated.adapter.soledad.soledad_facade_mixin import SoledadDbFacadeMixin import nacl.secret import nacl.utils +import base64 class SoledadSearchIndexMasterkeyRetrievalMixin(SoledadDbFacadeMixin, object): def get_index_masterkey(self): - index_key = self.get_search_index_masterkey() - if len(index_key) == 0: - index_key = nacl.utils.random(nacl.secret.SecretBox.KEY_SIZE) - self.create_doc(dict(type='index_key', value=index_key)) - return index_key - return str(index_key[0].content['value']) + result = self.get_search_index_masterkey() + index_key_doc = result[0] if result else None + + if not index_key_doc: + new_index_key = nacl.utils.random(nacl.secret.SecretBox.KEY_SIZE) + self.create_doc(dict(type='index_key', value=base64.encodestring(new_index_key))) + return new_index_key + return base64.decodestring(index_key_doc.content['value']) |