Island: Extract fernet_object to an object variable in KeyBasedEncryptor

This commit is contained in:
Shreya Malviya 2022-07-15 11:19:13 +05:30
parent 373d34dce6
commit 637926ed09
1 changed files with 3 additions and 4 deletions

View File

@ -21,11 +21,10 @@ class KeyBasedEncryptor(IEncryptor):
def __init__(self, key: bytes):
self._key = key
self._fernet_object = Fernet(self._key)
def encrypt(self, plaintext: bytes) -> bytes:
fernet_object = Fernet(self._key)
return fernet_object.encrypt(plaintext.encode())
return self._fernet_object.encrypt(plaintext.encode())
def decrypt(self, ciphertext: bytes) -> bytes:
fernet_object = Fernet(self._key)
return fernet_object.decrypt(ciphertext)
return self._fernet_object.decrypt(ciphertext)