Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't log error message when decoding valid discovery packets #1832

Conversation

gunjambi
Copy link
Contributor

@gunjambi gunjambi commented Sep 24, 2023

Fix Unable to decrypt, returning raw bytes warning message when decoding Discovery messages. Fixes #1824

I opted for a quick surgical fix here rather than rework the whole message parsing. While separating the Discovery messages from normal data messages is quite easy in the context of miioprotocol, there's a quite bit of uses of the Message in other places too. I didn't feel confident in changing those.

Additionally, it doesn't even seem desirable to separate Discovery-Ack and Data messages. It seems useful in some cases to be able to parse any message without knowing ahead of time what kind of data it might contain. (I doesn't really matter right now as the token, i.e. decryption key, must be supplied ahead of time, but it is conceivable that a parser might first match the ID of the reply to the request and then parse the contents. )

Fixes #1824

@codecov
Copy link

codecov bot commented Sep 24, 2023

Codecov Report

Merging #1832 (d292d9d) into master (8f567fe) will increase coverage by 0.07%.
Report is 3 commits behind head on master.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #1832      +/-   ##
==========================================
+ Coverage   80.80%   80.87%   +0.07%     
==========================================
  Files         192      193       +1     
  Lines       18546    18599      +53     
  Branches     4012     4021       +9     
==========================================
+ Hits        14986    15042      +56     
+ Misses       3282     3279       -3     
  Partials      278      278              
Files Coverage Δ
miio/protocol.py 93.75% <100.00%> (-3.06%) ⬇️

... and 3 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Owner

@rytilahti rytilahti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of simple changes and this is good to go, thanks! 👍

miio/protocol.py Outdated
Comment on lines 167 to 168
if obj == b"":
return b""
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if obj == b"":
return b""
if not obj:
return obj

miio/protocol.py Outdated
Comment on lines 164 to 166
# if there is no payload, decode to 0 bytes. Missing payload is expected for discovery messages.
# note that we don't have "token" in the context for discovery replies so we couldn't decode it
# anyway.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# if there is no payload, decode to 0 bytes. Missing payload is expected for discovery messages.
# note that we don't have "token" in the context for discovery replies so we couldn't decode it
# anyway.
# Missing payload is expected for discovery messages.

let's keep it simple here, also, there are some (very) old devices that actually respond with a valid token :-)

@rytilahti rytilahti changed the title Don't log error message when decoding valid discovery packets (#1824). Don't log error message when decoding valid discovery packets Oct 4, 2023
@rytilahti rytilahti added the bug label Oct 4, 2023
@gunjambi
Copy link
Contributor Author

gunjambi commented Oct 7, 2023

Proposed changes applied.

Copy link
Owner

@rytilahti rytilahti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks again! 👍

@rytilahti rytilahti merged commit fb69fbc into rytilahti:master Oct 7, 2023
16 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

KeyError('token') in EncryptionAdapter
2 participants