Skip to content

Commit

Permalink
fixed linter
Browse files Browse the repository at this point in the history
  • Loading branch information
volodymyrkir committed Apr 7, 2024
1 parent ea63094 commit f64fde2
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
Empty file removed examples/__init__.py
Empty file.
5 changes: 3 additions & 2 deletions py4phi/_encryption/_encryptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad, unpad

from py4phi.consts import STR_TAG_START, STR_TAG_END
from py4phi.logger_setup import logger
from py4phi.utils import DataFrame

Expand Down Expand Up @@ -54,8 +55,8 @@ def _decrypt_string(data: bytes, key: bytes, aad: bytes) -> str:
Returns: (str) The decrypted string.
"""
data = b64decode(data)
tag = data[16:32] # TODO move to utils
ciphertext = data[32:]
tag = data[STR_TAG_START:STR_TAG_END]
ciphertext = data[STR_TAG_END:]

cipher = AES.new(key, AES.MODE_GCM, nonce=aad)
decrypted_data = unpad(
Expand Down
3 changes: 3 additions & 0 deletions py4phi/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@
PYSPARK = 'pyspark'
POLARS = 'polars'
PANDAS = 'pandas'

STR_TAG_START = 16
STR_TAG_END = 32
4 changes: 3 additions & 1 deletion tests/unit/py4phi/encryption/test_base_encryptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ def test_decrypt(encryptor, mocker, decryption_dict, columns):
expected_calls = [call(col, decryption_dict[col])
for col in columns if col in decryption_dict]
mock_decrypt_col.assert_has_calls(expected_calls, any_order=True)
assert mock_error.call_count == len(set(columns).difference(set(decryption_dict.keys())))
assert mock_error.call_count == len(
set(columns).difference(set(decryption_dict.keys()))
)


def test_get_and_save_salt(encryptor):
Expand Down

0 comments on commit f64fde2

Please sign in to comment.