mirror of
https://github.com/netinvent/npbackup.git
synced 2025-09-13 16:35:43 +08:00
Don't encrypt null values
This commit is contained in:
parent
4ab2d0f5dd
commit
668b99e1eb
1 changed files with 31 additions and 29 deletions
|
@ -261,31 +261,32 @@ def crypt_config(
|
||||||
|
|
||||||
def _crypt_config(key: str, value: Any) -> Any:
|
def _crypt_config(key: str, value: Any) -> Any:
|
||||||
if key_should_be_encrypted(key, encrypted_options):
|
if key_should_be_encrypted(key, encrypted_options):
|
||||||
if operation == "encrypt":
|
if value is not None:
|
||||||
if (
|
if operation == "encrypt":
|
||||||
isinstance(value, str)
|
if (
|
||||||
and (
|
isinstance(value, str)
|
||||||
not value.startswith(ID_STRING)
|
and (
|
||||||
or not value.endswith(ID_STRING)
|
not value.startswith(ID_STRING)
|
||||||
)
|
or not value.endswith(ID_STRING)
|
||||||
) or not isinstance(value, str):
|
)
|
||||||
value = enc.encrypt_message_hf(
|
) or not isinstance(value, str):
|
||||||
value, aes_key, ID_STRING, ID_STRING
|
value = enc.encrypt_message_hf(
|
||||||
).decode("utf-8")
|
value, aes_key, ID_STRING, ID_STRING
|
||||||
elif operation == "decrypt":
|
).decode("utf-8")
|
||||||
if (
|
elif operation == "decrypt":
|
||||||
isinstance(value, str)
|
if (
|
||||||
and value.startswith(ID_STRING)
|
isinstance(value, str)
|
||||||
and value.endswith(ID_STRING)
|
and value.startswith(ID_STRING)
|
||||||
):
|
and value.endswith(ID_STRING)
|
||||||
_, value = enc.decrypt_message_hf(
|
):
|
||||||
value,
|
_, value = enc.decrypt_message_hf(
|
||||||
aes_key,
|
value,
|
||||||
ID_STRING,
|
aes_key,
|
||||||
ID_STRING,
|
ID_STRING,
|
||||||
)
|
ID_STRING,
|
||||||
else:
|
)
|
||||||
raise ValueError(f"Bogus operation {operation} given")
|
else:
|
||||||
|
raise ValueError(f"Bogus operation {operation} given")
|
||||||
return value
|
return value
|
||||||
|
|
||||||
return replace_in_iterable(
|
return replace_in_iterable(
|
||||||
|
@ -307,10 +308,11 @@ def is_encrypted(full_config: dict) -> bool:
|
||||||
nonlocal is_encrypted
|
nonlocal is_encrypted
|
||||||
|
|
||||||
if key_should_be_encrypted(key, ENCRYPTED_OPTIONS):
|
if key_should_be_encrypted(key, ENCRYPTED_OPTIONS):
|
||||||
if isinstance(value, str) and (
|
if value is not None:
|
||||||
not value.startswith(ID_STRING) or not value.endswith(ID_STRING)
|
if isinstance(value, str) and (
|
||||||
):
|
not value.startswith(ID_STRING) or not value.endswith(ID_STRING)
|
||||||
is_encrypted = False
|
):
|
||||||
|
is_encrypted = False
|
||||||
return value
|
return value
|
||||||
|
|
||||||
replace_in_iterable(
|
replace_in_iterable(
|
||||||
|
|
Loading…
Add table
Reference in a new issue