Island: Fix string/bytes bug in StringListEncryptor

For some reason, bytes objects do not come out of mongo the same way
they go in. This class will be removed when reporting is reworked, so
rather than spend the time on figuring out exactly what's going on, just
use strings.
This commit is contained in:
Mike Salvatore 2022-07-13 14:59:27 -04:00
parent e1c5972ccc
commit e349a78334
2 changed files with 6 additions and 5 deletions

View File

@ -29,7 +29,8 @@ def save_report(report_dict: dict):
def get_report() -> dict:
report_dict = Report.objects.first().to_mongo()
return _decode_dot_char_before_mongo_insert(decrypt_dict(sensitive_fields, report_dict))
decrypted = decrypt_dict(sensitive_fields, report_dict)
return _decode_dot_char_before_mongo_insert(decrypted)
# TODO remove this unnecessary encoding. I think these are legacy methods from back in the day

View File

@ -6,9 +6,9 @@ from . import IFieldEncryptor
class StringListEncryptor(IFieldEncryptor):
@staticmethod
def encrypt(value: List[str]):
return [get_datastore_encryptor().encrypt(string.encode()) for string in value]
def encrypt(value: List[str]) -> List[str]:
return [get_datastore_encryptor().encrypt(string.encode()).decode() for string in value]
@staticmethod
def decrypt(value: List[bytes]):
return [get_datastore_encryptor().decrypt(bytes_).decode() for bytes_ in value]
def decrypt(value: List[str]) -> List[str]:
return [get_datastore_encryptor().decrypt(string.encode()).decode() for string in value]