Buckets:

download
raw
1.1 kB
import binascii
from cryptography.fernet import Fernet
from sqlalchemy import Text
from sqlalchemy_utils.types.encrypted.encrypted_type import (
FernetEngine as BaseFernetEngine,
)
from sqlalchemy_utils.types.encrypted.encrypted_type import (
StringEncryptedType as BaseStringEncryptedType,
)
class StringEncryptedType(BaseStringEncryptedType):
impl = Text
def generate_key() -> bytes:
return Fernet.generate_key()
def is_valid_key(key: bytes) -> bool:
try:
Fernet(key)
except binascii.Error:
return False
else:
return True
class FernetEngine(BaseFernetEngine):
"""
Overload of the built-in SQLAlchemy Utils Fernet engine.
For unknown reasons, they hash the encryption key before using it.
For backward compatibility, we adjust the implementation to use the key as provided.
"""
def _update_key(self, key: bytes):
return self._initialize_engine(key)
def _initialize_engine(self, parent_class_key: bytes):
self.secret_key = parent_class_key
self.fernet = Fernet(self.secret_key)

Xet Storage Details

Size:
1.1 kB
·
Xet hash:
9794db68d9d1c91f719b72f423e01c8d7ac84ad9ea2b08d3665f13adca81e744

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.