db and settings encryption

This commit is contained in:
ingvar1995
2016-05-15 23:02:05 +03:00
parent 0fa7ca7b5c
commit 21d5eed719
3 changed files with 28 additions and 0 deletions

View File

@ -2,6 +2,8 @@
from sqlite3 import connect
import settings
from os import chdir
import os.path
from toxencryptsave import LibToxEncryptSave
PAGE_SIZE = 42
@ -17,6 +19,15 @@ class History(object):
def __init__(self, name):
self._name = name
chdir(settings.ProfileHelper.get_path())
path = settings.ProfileHelper.get_path() + self._name + '.hstr'
if os.path.exists(path):
decr = LibToxEncryptSave.get_instance()
if decr.has_password():
with open(path, 'rb') as fin:
data = fin.read()
data = decr.pass_decrypt(data)
with open(path, 'wb') as fout:
fout.write(data)
db = connect(name + '.hstr')
cursor = db.cursor()
cursor.execute('CREATE TABLE IF NOT EXISTS friends('
@ -24,6 +35,16 @@ class History(object):
')')
db.close()
def save(self):
encr = LibToxEncryptSave.get_instance()
if encr.has_password():
path = settings.ProfileHelper.get_path() + self._name + '.hstr'
with open(path, 'rb') as fin:
data = fin.read()
data = encr.pass_encrypt(data)
with open(path, 'wb') as fout:
fout.write(data)
def export(self, directory):
path = settings.ProfileHelper.get_path() + self._name + '.hstr'
new_path = directory + self._name + '.hstr'