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