Repository navigation
Conversation
Signed-off-by: Ym <173550318+MaxonT@users.noreply.github.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi, I had a look at the code behind this issue and made a narrow fix.
Issue #, if available: #162
Description of changes:
When
--decodeis forgotten, decrypting a base64-encoded message fails withUnsupported 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 areAY(base64 of the version 1 prefix0x01 0x80) orAg(base64 of the version 2 prefix0x02 0x05), the CLI stops with aBadUserArgumentError: "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 prefixAgsince 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 nopeekmethod 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 withoutpeekis not flagged; one checks that--decodeinput 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.pygives 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 gaveUnsupported 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_versionfails 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;blackon 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