Add support for 'coercion_listener' to the encrypted type.
This commit is contained in:
@@ -3,6 +3,7 @@ import base64
|
|||||||
import six
|
import six
|
||||||
from sqlalchemy.types import TypeDecorator, String, Binary
|
from sqlalchemy.types import TypeDecorator, String, Binary
|
||||||
from sqlalchemy_utils.exceptions import ImproperlyConfigured
|
from sqlalchemy_utils.exceptions import ImproperlyConfigured
|
||||||
|
from .scalar_coercible import ScalarCoercible
|
||||||
|
|
||||||
cryptography = None
|
cryptography = None
|
||||||
try:
|
try:
|
||||||
@@ -111,7 +112,7 @@ class FernetEngine(EncryptionDecryptionBaseEngine):
|
|||||||
return decrypted
|
return decrypted
|
||||||
|
|
||||||
|
|
||||||
class EncryptedType(TypeDecorator):
|
class EncryptedType(TypeDecorator, ScalarCoercible):
|
||||||
"""
|
"""
|
||||||
EncryptedType provides a way to encrypt and decrypt values,
|
EncryptedType provides a way to encrypt and decrypt values,
|
||||||
to and from databases, that their type is a basic SQLAlchemy type.
|
to and from databases, that their type is a basic SQLAlchemy type.
|
||||||
@@ -223,3 +224,9 @@ class EncryptedType(TypeDecorator):
|
|||||||
self._update_key()
|
self._update_key()
|
||||||
decrypted_value = self.engine.decrypt(value)
|
decrypted_value = self.engine.decrypt(value)
|
||||||
return self.underlying_type.python_type(decrypted_value)
|
return self.underlying_type.python_type(decrypted_value)
|
||||||
|
|
||||||
|
def _coerce(self, value):
|
||||||
|
if isinstance(self.underlying_type, ScalarCoercible):
|
||||||
|
return self.underlying_type._coerce(value)
|
||||||
|
|
||||||
|
return value
|
||||||
|
Reference in New Issue
Block a user