mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-30 08:32:26 +00:00
Merge branch 'fix_aesfield_error' into 'dev'
Fix error message when failing to decode an aes_key. See merge request federez/re2o!393
This commit is contained in:
commit
3443965e37
1 changed files with 10 additions and 4 deletions
|
@ -82,16 +82,22 @@ class AESEncryptedField(models.CharField):
|
||||||
return None
|
return None
|
||||||
try:
|
try:
|
||||||
return decrypt(settings.AES_KEY, binascii.a2b_base64(value)).decode('utf-8')
|
return decrypt(settings.AES_KEY, binascii.a2b_base64(value)).decode('utf-8')
|
||||||
except Exception as e:
|
except UnicodeDecodeError as e:
|
||||||
raise ValueError(value)
|
raise ValueError(
|
||||||
|
"Could not decode your field %s, your settings.AES_KEY "
|
||||||
|
"is probably wrong." % self.name
|
||||||
|
)
|
||||||
|
|
||||||
def from_db_value(self, value, *args, **kwargs):
|
def from_db_value(self, value, *args, **kwargs):
|
||||||
if value is None:
|
if value is None:
|
||||||
return value
|
return value
|
||||||
try:
|
try:
|
||||||
return decrypt(settings.AES_KEY, binascii.a2b_base64(value)).decode('utf-8')
|
return decrypt(settings.AES_KEY, binascii.a2b_base64(value)).decode('utf-8')
|
||||||
except Exception as e:
|
except UnicodeDecodeError as e:
|
||||||
raise ValueError(value)
|
raise ValueError(
|
||||||
|
"Could not decode your field %s, your settings.AES_KEY "
|
||||||
|
"is probably wrong." % self.name
|
||||||
|
)
|
||||||
|
|
||||||
def get_prep_value(self, value):
|
def get_prep_value(self, value):
|
||||||
if value is None:
|
if value is None:
|
||||||
|
|
Loading…
Reference in a new issue