Skip to content

Commit

Permalink
rename encrypt and decrypt methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jaedsonpys committed Jan 2, 2023
1 parent 715d0af commit c2deb00
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions cookiedb/_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ def exists_document(self, database: str) -> bool:
document_path = os.path.join(self._document_local, database + '.cookiedb')
return os.path.isfile(document_path)

def encrypt_json(self, obj: dict) -> str:
def _encrypt(self, obj: dict) -> str:
dict_str = str(obj)
encrypted_data = self._fernet.encrypt(dict_str.encode())
pickle_file = secpickle.dumps(encrypted_data, self._key)
return pickle_file

def decrypt_json(self, encrypted: bytes) -> dict:
def _decrypt(self, encrypted: bytes) -> dict:
decrypted_data = self._fernet.decrypt(encrypted)
data = str(decrypted_data)
return data
Expand All @@ -63,7 +63,7 @@ def create_document(self, name: str) -> dict:
'items': {}
}

data = self.encrypt_json(document)
data = self._encrypt(document)
self._save_file(data, document_path)

return document
Expand All @@ -79,7 +79,7 @@ def get_document(self, database: str) -> Union[None, dict]:
except sp_exceptions.IntegrityUnconfirmedError:
raise exceptions.InvalidDatabaseKeyError(f'Invalid key to "{database}" database')
else:
document = self.decrypt_json(data)
document = self._decrypt(data)

return document

Expand All @@ -92,5 +92,5 @@ def update_document(self, database: str, items: dict):
document['items'] = items
document['updated_at'] = str(update_time)

encrypted_json = self.encrypt_json(document)
encrypted_json = self._encrypt(document)
self._save_file(encrypted_json, document_path)

0 comments on commit c2deb00

Please sign in to comment.