Island: Use EncryptionKey32Bytes in KeyBasedEncryptor

This commit is contained in:
Shreya Malviya 2022-07-19 18:15:56 +05:30
parent 4e755bbd2f
commit 80104381d7
1 changed files with 7 additions and 5 deletions

View File

@ -1,7 +1,9 @@
import base64
import logging import logging
from cryptography.fernet import Fernet from cryptography.fernet import Fernet
from . import EncryptionKey32Bytes
from .i_encryptor import IEncryptor from .i_encryptor import IEncryptor
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -16,14 +18,14 @@ logger = logging.getLogger(__name__)
class KeyBasedEncryptor(IEncryptor): class KeyBasedEncryptor(IEncryptor):
def __init__(self, key: bytes): def __init__(self, key: EncryptionKey32Bytes):
""" """
Initializes a KeyBasedEncryptor object Initializes a KeyBasedEncryptor object
:param bytes key: The encryption key with which the object should be initialized. :param EncryptionKey32Bytes key: The encryption key with which the object should be
This should be a URL-safe base64-encoded 32-byte key. initialized.
""" """
self._key = key self._formatted_key = base64.urlsafe_b64encode(key)
self._fernet_object = Fernet(self._key) self._fernet_object = Fernet(self._formatted_key)
def encrypt(self, plaintext: bytes) -> bytes: def encrypt(self, plaintext: bytes) -> bytes:
""" """