Debian Codegraph @

tests/benchmarks/test_resolve_private_address.py

raw symbols SCIP
1 from pytest_codspeed import BenchmarkFixture
2
3 from bluetooth_data_tools import get_cipher_for_irk, resolve_private_address
4
5 # IRK + addresses borrowed from tests/test_privacy.py so the AES path
6 # walks the same code shape as the existing functional coverage.
7 _IRK = b"\x00" * 16
8 _CIPHER = get_cipher_for_irk(_IRK)
9
10 # Top two bits != 0b01: skipped before the AES encrypt. Real BLE scans
11 # see this every time a public/static-random address is encountered.
12 _NON_RPA = "00:01:ff:a0:3a:76"
13
14 # Top two bits == 0b01 with a hash that matches under the zero IRK.
15 _RPA_MATCH = "40:01:02:0a:c4:a6"
16
17 # Top two bits == 0b01 but the hash does not match — exercises the full
18 # encrypt + compare_digest path with a False result.
19 _RPA_MISMATCH = "40:00:00:d2:74:ce"
20
21
22 def test_resolve_private_address_non_rpa(benchmark: BenchmarkFixture) -> None:
23 benchmark(lambda: resolve_private_address(_CIPHER, _NON_RPA))
24
25
26 def test_resolve_private_address_match(benchmark: BenchmarkFixture) -> None:
27 benchmark(lambda: resolve_private_address(_CIPHER, _RPA_MATCH))
28
29
30 def test_resolve_private_address_mismatch(benchmark: BenchmarkFixture) -> None:
31 benchmark(lambda: resolve_private_address(_CIPHER, _RPA_MISMATCH))