Newly implemented GCM encryption method#442
Merged
bdraco merged 11 commits intosblibs:masterfrom Jan 26, 2026
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Implements support for SwitchBot’s upcoming AES-GCM encryption mode (alongside existing AES-CTR) for encrypted BLE devices.
Changes:
- Added
AESModedetection from the encryption init response and mode-specific IV parsing (CTR=16 bytes, GCM=12 bytes with padding trim). - Updated encryption/decryption flow to support GCM (including returning a 2-byte header derived from the GCM tag and incrementing GCM IV after encrypted commands).
- Expanded unit tests to cover mode resolution, GCM IV increment behavior, and updated
_encryptreturn shape.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
switchbot/devices/device.py |
Adds AES mode enum/detection, GCM-specific IV parsing, encryption/decryption changes, and GCM IV increment logic. |
tests/test_encrypted_device.py |
Updates tests for new _encrypt return type and adds coverage for GCM mode behavior and mode resolution. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
bdraco
approved these changes
Jan 25, 2026
Member
|
Thanks @zerzhang I did some tweaks. If its all still working as expected, please let me know and I'll merge and do a release. |
Collaborator
Author
@bdraco All works well |
fankai777
pushed a commit
to fankai777/pySwitchbot
that referenced
this pull request
Jan 26, 2026
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: J. Nick Koston <nick@koston.org> Co-authored-by: J. Nick Koston <nick@home-assistant.io>
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.
Breaking change
SwitchBot will be implementing the new AES_GCM encryption method in its upcoming firmware update.
Switchbot Encryption Modes (CTR/GCM)
Mode Identification
2) indicates the encryption mode:0x00: AES-CTR0x01: AES-GCM0x00/0x01will throw an exception.IV Parsing
result[4:]from the random number response, length is 16 bytes.result[4:-4]from the random number response, length is 12 bytes (the last 4 bytes are for compatibility padding).GCM IV Increment Rule
GCM Tag Handling
decryptor.update(...), notfinalize().