mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-23 11:53:12 +00:00
Support de postgreSQL pour AESENCryptedField
This commit is contained in:
parent
c05f8f826c
commit
17da4a52dc
1 changed files with 7 additions and 8 deletions
|
@ -72,9 +72,10 @@ class AESEncryptedFormField(forms.CharField):
|
|||
class AESEncryptedField(models.CharField):
|
||||
""" A Field that can be used in forms for adding the support
|
||||
of AES ecnrypted fields """
|
||||
|
||||
def save_form_data(self, instance, data):
|
||||
setattr(instance, self.name,
|
||||
binascii.b2a_base64(encrypt(settings.AES_KEY, data)))
|
||||
setattr(instance, self.name, binascii.b2a_base64(
|
||||
encrypt(settings.AES_KEY, data)).decode('utf-8'))
|
||||
|
||||
def to_python(self, value):
|
||||
if value is None:
|
||||
|
@ -83,8 +84,7 @@ class AESEncryptedField(models.CharField):
|
|||
return decrypt(settings.AES_KEY,
|
||||
binascii.a2b_base64(value)).decode('utf-8')
|
||||
except Exception as e:
|
||||
v = decrypt(settings.AES_KEY, binascii.a2b_base64(value))
|
||||
raise ValueError(v)
|
||||
raise ValueError(value)
|
||||
|
||||
def from_db_value(self, value, *args, **kwargs):
|
||||
if value is None:
|
||||
|
@ -93,8 +93,7 @@ class AESEncryptedField(models.CharField):
|
|||
return decrypt(settings.AES_KEY,
|
||||
binascii.a2b_base64(value)).decode('utf-8')
|
||||
except Exception as e:
|
||||
v = decrypt(settings.AES_KEY, binascii.a2b_base64(value))
|
||||
raise ValueError(v)
|
||||
raise ValueError(value)
|
||||
|
||||
def get_prep_value(self, value):
|
||||
if value is None:
|
||||
|
@ -102,7 +101,7 @@ class AESEncryptedField(models.CharField):
|
|||
return binascii.b2a_base64(encrypt(
|
||||
settings.AES_KEY,
|
||||
value
|
||||
))
|
||||
)).decode('utf-8')
|
||||
|
||||
def formfield(self, **kwargs):
|
||||
defaults = {'form_class': AESEncryptedFormField}
|
||||
|
|
Loading…
Reference in a new issue