Island: Add docstrings to KeyBasedEncryptor

This commit is contained in:
Shreya Malviya 2022-07-19 15:04:20 +05:30
parent ca420b8afc
commit bd1c788a4c
1 changed files with 16 additions and 0 deletions

View File

@ -17,11 +17,27 @@ logger = logging.getLogger(__name__)
class KeyBasedEncryptor(IEncryptor):
def __init__(self, key: bytes):
"""
Initializes a KeyBasedEncryptor object
:param bytes key: The encryption key with which the object should be initialized
"""
self._key = key
self._fernet_object = Fernet(self._key)
def encrypt(self, plaintext: bytes) -> bytes:
"""
Encrypts a given bytestream
:param bytes plaintext: The bytestream to encrypt
:return: Encrypted message
:rtype: bytes
"""
return self._fernet_object.encrypt(plaintext)
def decrypt(self, ciphertext: bytes) -> bytes:
"""
Decrypts a given bytestream
:param bytes ciphertext: The bytestream to decrypt
:return: Decrypted message
:rtype: bytes
"""
return self._fernet_object.decrypt(ciphertext)