Skip to content
This repository was archived by the owner on Feb 28, 2024. It is now read-only.

Commit 4191ac1

Browse files
authored
Merge pull request #3 from Mastercard/feature/fix_multiple_encryption_paths
Fixed NPE when multiple encryption paths are provided
2 parents 6c78dc7 + 06f2d40 commit 4191ac1

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

lib/mcapi/encryption/field_level_encryption.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,15 @@ def decrypt(response)
8181

8282
def encrypt_with_body(path, body)
8383
elem = elem_from_path(path['element'], body)
84+
return unless elem && elem[:node]
8485
encrypted_data = @crypto.encrypt_data(data: JSON.generate(elem[:node]))
8586
McAPI::Utils.mutate_obj_prop(path['obj'], encrypted_data, body)
8687
McAPI::Utils.delete_node(path['element'], body) if path['element'] != "#{path['obj']}.#{@config['encryptedValueFieldName']}"
8788
end
8889

8990
def encrypt_with_header(path, enc_params, header, body)
9091
elem = elem_from_path(path['element'], body)
92+
return unless elem && elem[:node]
9193
encrypted_data = @crypto.encrypt_data(data: JSON.generate(elem[:node]), encryption_params: enc_params)
9294
body = { path['obj'] => { @config['encryptedValueFieldName'] => encrypted_data[@config['encryptedValueFieldName']] } }
9395
set_header(header, enc_params)

0 commit comments

Comments
 (0)