Skip to content

Commit

Permalink
Version 1.0.6
Browse files Browse the repository at this point in the history
Bug fixes
  • Loading branch information
Romani authored and Romani committed Dec 22, 2021
1 parent 0ee36a2 commit 2370036
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion db/example.sdb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
b'gAAAAABhwIuCeO5C6Y5z_xqS0z-nZDqPFceF0fvrebjfw3sb-X5_E1lEc8BikGOJqcINCA2xZgZn9tRbyYkynhUdseeyAWU2ew=='
b'gAAAAABhwzSm1DRB9YYELlhgOcUkJT0ycJv4Icnwsg0ag-nA99Nb7UooayGZ-FhDDBZV0WcP80c-nujguwtV9cqUQy5nXZwkJQ=='
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='securedb',
version='1.0.5',
version='1.0.6',
description='securedb is a fast and lightweight Python framework to easily interact with JSON-based encrypted databases.',
py_modules=["securedb"],
package_dir={'': 'src'},
Expand Down
21 changes: 13 additions & 8 deletions src/securedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def __init__(self, path, key):
print("The specified database does not exist.")

def write(self, key, value):
to_dict = decrypt(self.key, bytes(self.payload))
f = open(self.path, "r").read()
to_dict = decrypt(self.key, bytes(eval(f)))
ev = eval(to_dict.decode())
data = dict(ev)
data[key] = value
Expand All @@ -55,7 +56,8 @@ def write(self, key, value):
return "Key written to the database"

def write_many(self, payload: dict):
to_dict = decrypt(self.key, bytes(self.payload))
f = open(self.path, "r").read()
to_dict = decrypt(self.key, bytes(eval(f)))
ev = eval(to_dict.decode())
data = dict(ev)
for key, value in payload.items():
Expand Down Expand Up @@ -100,13 +102,15 @@ def get_many(self, keys : list):
return els

def delete(self, key):
to_dict = decrypt(self.key, bytes(self.payload))
f = open(self.path, "r").read()
to_dict = decrypt(self.key, bytes(eval(f)))
ev = eval(to_dict.decode())
data = dict(ev)
try:
data.pop(key)
except:
print(f"Key {key} was not deleted because it does not exist.")
#try:
print(data)
data.pop(key)
#except:
# print(f"Key {key} was not deleted because it does not exist.")
with open(self.path, "w") as f:
to_encrypt = str(data).encode()
to_write = encrypt(self.key, (to_encrypt))
Expand All @@ -115,7 +119,8 @@ def delete(self, key):
return "Key deleted from the database"

def delete_many(self, payload: list):
to_dict = decrypt(self.key, bytes(self.payload))
f = open(self.path, "r").read()
to_dict = decrypt(self.key, bytes(eval(f)))
ev = eval(to_dict.decode())
data = dict(ev)
for x in payload:
Expand Down
1 change: 0 additions & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

db.write("lol", 2)

print(db.get_many(["lol", "lol1"]))

db.delete("lol")

Expand Down

0 comments on commit 2370036

Please sign in to comment.