codernity avatar codernity committed 2eb51b5

Fixed salsa storage example (issue #8)

Comments (0)

Files changed (1)

docs/demo_secure_storage.py

 
 class Salsa20Storage(Storage):
 
-    def __init__(self, db_path, name):
+    def __init__(self, db_path, name, enc_key):
         super(Salsa20Storage, self).__init__(db_path, name)
-        self.enc_key = None
+        self.enc_key = enc_key
 
     def data_from(self, data):
         iv = data[:8]
             self.__enc_key = value
         self.storage.enc_key = self.__enc_key
 
+    def _open_storage(self):
+        if not self.storage:
+            self.storage = Salsa20Storage(
+                self.db_path, self.name, self.enc_key)
+            self.storage.open()
+
+    def _create_storage(self):
+        if not self.storage:
+            self.storage = Salsa20Storage(
+                self.db_path, self.name, self.enc_key)
+            self.storage.create()
+
 
 def main():
     db = Database('/tmp/demo_secure')
     key = 'abcdefgh'
-    id_ind = EncUniqueHashIndex(db.path, 'id', storage_class='Salsa20Storage')
+    id_ind = EncUniqueHashIndex(db.path, 'id')
     db.set_indexes([id_ind])
     db.create()
     db.id_ind.enc_key = key
+    print db.id_ind.storage
 
     for x in xrange(100):
         db.insert(dict(x=x, data='testing'))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.