Coverage for src / bluetooth_sig / gatt / characteristics / esl_response_key_material.py: 100%

13 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-03 16:41 +0000

1"""ESL Response Key Material characteristic (0x2BF8). 

2 

3Contains the 128-bit key material used by an ESL to encrypt and 

4authenticate response data sent back to the ESL Access Point. 

5 

6References: 

7 Bluetooth SIG Electronic Shelf Label Profile, §3.7.2 

8""" 

9 

10from __future__ import annotations 

11 

12from ...types.gatt_enums import CharacteristicRole 

13from ..context import CharacteristicContext 

14from .base import BaseCharacteristic 

15 

16 

17class ESLResponseKeyMaterialCharacteristic(BaseCharacteristic[bytes]): 

18 """ESL Response Key Material characteristic (0x2BF8). 

19 

20 org.bluetooth.characteristic.esl_response_key_material 

21 

22 128-bit (16 byte) key material for ESL response encryption. 

23 Written by the ESL Access Point during the configuration procedure. 

24 """ 

25 

26 _characteristic_name = "ESL Response Key Material" 

27 _manual_role = CharacteristicRole.INFO 

28 expected_length: int = 16 # 128-bit key 

29 min_length: int = 16 

30 

31 def _decode_value( 

32 self, 

33 data: bytearray, 

34 ctx: CharacteristicContext | None = None, 

35 *, 

36 validate: bool = True, 

37 ) -> bytes: 

38 """Parse ESL response key material (16 bytes). 

39 

40 Args: 

41 data: Raw bytes (16 bytes). 

42 ctx: Optional CharacteristicContext. 

43 validate: Whether to validate (default True). 

44 

45 Returns: 

46 Raw 128-bit key material as bytes. 

47 

48 """ 

49 return bytes(data[:16]) 

50 

51 def _encode_value(self, data: bytes) -> bytearray: 

52 """Encode ESL response key material to bytes. 

53 

54 Args: 

55 data: 16-byte key material. 

56 

57 Returns: 

58 Encoded bytes (16 bytes). 

59 

60 """ 

61 return bytearray(data)