def create(self): if not os.path.exists(self.dr): os.makedirs(self.dr) pwd, hsh = create_pass() # (password, hash) self.key_store.add_db_key(self.name, hsh) self.key_store.save() open(meta_loc(self.name), 'w').close() self.meta_data = Meta(self.name, pwd)
def __init__(self, name): self.name = name self.key_store = Key() self.dr = conf['home'] + '/data/' + self.name # file storage location if os.path.exists(meta_loc(name)): # database exists pwd = ask_pass(self.key_store.get_hashed_key(name)) if pwd == -1: sys.exit(1) # TODO: Something better self.meta_data = Meta(name, pwd) # auth success
def __init__(self, name, key): self.name = name self.key = encode_key(key) fs = open(meta_loc(name), mode='rb') cont = fs.read() if cont == '': self.broot = {'data': []} self.data = self.broot['data'] return ps = fdecrypt(cont, self.key) self.broot = bson.loads(ps) self.data = self.broot['data']
def save(self): with open(meta_loc(self.name), mode='wb') as stream: stream.write(fencrypt(bson.dumps(self.broot), self.key))
def destroy(self): os.remove(meta_loc(self.name))