File: test_v1_encryption.py

package info (click to toggle)
bthome-ble 3.20.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 736 kB
  • sloc: python: 6,600; makefile: 15
file content (22 lines) | stat: -rw-r--r-- 806 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
"""Tests for the parser of BLE advertisements in BTHome V1 format."""

import binascii

from bthome_ble.bthome_v1_encryption import decrypt_aes_ccm, encrypt_payload


def test_encryption_example():
    """Test BTHome V1 encryption example."""
    data = bytes(bytearray.fromhex("2302CA090303BF13"))  # BTHome data (not encrypted)
    count_id = bytes(bytearray.fromhex("00112233"))  # count id (change every message)
    mac = binascii.unhexlify("5448E68F80A5")  # MAC
    uuid16 = b"\x1e\x18"
    bindkey = binascii.unhexlify("231d39c1d7cc1ab1aee224cd096db932")

    payload = encrypt_payload(
        data=data, mac=mac, uuid16=uuid16, count_id=count_id, key=bindkey
    )
    assert decrypt_aes_ccm(key=bindkey, mac=mac, data=payload) == {
        "humidity": 50.55,
        "temperature": 25.06,
    }