Skip to content

fix: suggest --decode when decrypt input looks base64 encoded - #446

Open
MaxonT wants to merge 1 commit into
aws:masterfrom
MaxonT:contrib/162-auto
Open

MaxonT wants to merge 1 commit into
aws:masterfrom
MaxonT:contrib/162-auto

Conversation

@MaxonT

@MaxonT MaxonT commented Nov 25, 2026

Copy link
Copy Markdown

Hi, I had a look at the code behind this issue and made a narrow fix.

Issue #, if available: #162

Description of changes:

When --decode is forgotten, decrypting a base64-encoded message fails with Unsupported version 65 (the "A" of "AY..."), which does not point at the real cause. The check asked for in the issue is now done before the SDK stream is opened: in decrypt and decrypt-unsigned mode without --decode, the first two bytes of the input are peeked, and if they are AY (base64 of the version 1 prefix 0x01 0x80) or Ag (base64 of the version 2 prefix 0x02 0x05), the CLI stops with a BadUserArgumentError: "Input looks like a base64-encoded message, not a raw encrypted message. Use --decode to base64-decode the input before decrypting."

Two details worth knowing: the issue lists only the version 1 values (41 59), and I added the version 2 prefix Ag since that is what current SDK versions write by default. The peek does not consume input, so it works for files and for stdin, and a source with no peek method is simply not checked.

Tests: four test functions in test/unit/internal/test_io_handling.py. One checks rejection for both prefixes in both decrypt modes, that the SDK stream is never opened, and that the source is left unread; one checks that raw version 1 and version 2 prefixes and short input are not flagged; one checks that a source without peek is not flagged; one checks that --decode input is not rejected. With the check turned off, the 4 parameter sets of the rejection test fail; with it, pytest test/unit/internal/test_io_handling.py gives 87 passed. I also ran the CLI by hand on Python 3.11 with a real message encrypted by the SDK: before the change the base64 file gave Unsupported version 65, after it gives the message above, from both a file and stdin. One limit: if a pipe delivers only one byte in its first chunk, the peek sees too little and no hint is shown; the behavior is then the same as before.

In the rest of test/unit, test_compatability.py::TestWarnDeprecatedPython::test_happy_version fails on my setup (pytest.warns(None) with the pytest version I installed); it does not touch these files and I did not run it against the base commit. I did not run the integration tests or the project's lint run; black on my machine wants to reformat unrelated existing lines, so I did not apply it.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Fixes #162

Signed-off-by: Ym <173550318+MaxonT@users.noreply.github.com>
@MaxonT
MaxonT requested a review from a team as a code owner November 25, 2026 14:34

This branch has not been deployed

No deployments
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.

Base64 error messaging in version and type verification

1 participant