Debian Codegraph @

tests/test_v1_encryption.py

raw symbols SCIP
1 """Tests for the parser of BLE advertisements in BTHome V1 format."""
2
3 import binascii
4
5 from bthome_ble.bthome_v1_encryption import decrypt_aes_ccm, encrypt_payload
6
7
8 def test_encryption_example():
9 """Test BTHome V1 encryption example."""
10 data = bytes(bytearray.fromhex("2302CA090303BF13")) # BTHome data (not encrypted)
11 count_id = bytes(bytearray.fromhex("00112233")) # count id (change every message)
12 mac = binascii.unhexlify("5448E68F80A5") # MAC
13 uuid16 = b"\x1e\x18"
14 bindkey = binascii.unhexlify("231d39c1d7cc1ab1aee224cd096db932")
15
16 payload = encrypt_payload(
17 data=data, mac=mac, uuid16=uuid16, count_id=count_id, key=bindkey
18 )
19 assert decrypt_aes_ccm(key=bindkey, mac=mac, data=payload) == {
20 "humidity": 50.55,
21 "temperature": 25.06,
22 }