Skip to content

Make the payload encoder's -key argument usable - #3421

Open
arpitjain099 wants to merge 1 commit into
apache:masterfrom
arpitjain099:fix/payload-encoder-key-flag
Open

arpitjain099 wants to merge 1 commit into
apache:masterfrom
arpitjain099:fix/payload-encoder-key-flag

Conversation

@arpitjain099

Copy link
Copy Markdown

Description

payload_encoder.py takes a -key flag, but passing one has never worked. argparse hands back a str, so key[i % len(key)] is a one character string and the XOR raises:

  File "app/utility/payload_encoder.py", line 31, in xor_bytes
    arr[i] = val ^ cur_key
TypeError: unsupported operand type(s) for ^: 'int' and 'str'

The default path is fine, because DEFAULT_KEY is a list of ints. Only a user supplied key breaks, so the flag is effectively dead.

The server already solves this: file_svc.py:69 does xor_bytes(contents, xor_key.encode()) for the xor_key header. This does the same thing at the argparse layer, so the two paths agree on what a key is and xor_bytes keeps taking anything that indexes to ints.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Added tests/utility/test_payload_encoder.py with three cases: xor_bytes with a byte string key, the CLI with the default key, and the CLI with -key. The third fails on master with the TypeError above and passes here. Ran the file under python 3.12 with flake8 clean.

Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant