Skip to content

Commit

Permalink
fixed code smell
Browse files Browse the repository at this point in the history
  • Loading branch information
pqlMC committed Jun 20, 2019
1 parent 4f780a7 commit db389e6
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions client_encryption/field_level_encryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ def encrypt_payload(payload, config, _params=None):
"""Encrypt some fields of a JSON payload using the given configuration."""

try:
if type(payload) is dict:
json_payload = copy.deepcopy(payload)
else:
json_payload = json.loads(payload)
json_payload = copy.deepcopy(payload) if type(payload) is dict else json.loads(payload)

for elem, target in config.paths["$"].to_encrypt.items():
if not _params:
Expand Down Expand Up @@ -50,13 +47,7 @@ def decrypt_payload(payload, config, _params=None):
"""Decrypt some fields of a JSON payload using the given configuration."""

try:
if type(payload) is dict:
json_payload = payload
else:
try:
json_payload = json.loads(payload)
except json.JSONDecodeError: # not a json response - return it as is
return payload
json_payload = payload if type(payload) is dict else json.loads(payload)

for elem, target in config.paths["$"].to_decrypt.items():
try:
Expand Down Expand Up @@ -92,6 +83,8 @@ def decrypt_payload(payload, config, _params=None):

return json_payload

except json.JSONDecodeError: # not a json response - return it as is
return payload
except (IOError, ValueError, TypeError) as e:
raise EncryptionError("Payload decryption failed!", e)

Expand Down

0 comments on commit db389e6

Please sign in to comment.