bumble 0.0.210__py3-none-any.whl → 0.0.212__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. bumble/_version.py +2 -2
  2. bumble/apps/bench.py +8 -4
  3. bumble/apps/console.py +2 -2
  4. bumble/apps/pair.py +185 -32
  5. bumble/att.py +13 -12
  6. bumble/avctp.py +2 -2
  7. bumble/avdtp.py +122 -68
  8. bumble/avrcp.py +11 -5
  9. bumble/core.py +13 -7
  10. bumble/{crypto.py → crypto/__init__.py} +11 -95
  11. bumble/crypto/builtin.py +652 -0
  12. bumble/crypto/cryptography.py +84 -0
  13. bumble/device.py +365 -185
  14. bumble/drivers/intel.py +3 -0
  15. bumble/gatt.py +3 -5
  16. bumble/gatt_client.py +5 -3
  17. bumble/gatt_server.py +8 -6
  18. bumble/hci.py +81 -4
  19. bumble/hfp.py +44 -20
  20. bumble/hid.py +24 -12
  21. bumble/host.py +24 -0
  22. bumble/keys.py +64 -48
  23. bumble/l2cap.py +19 -9
  24. bumble/pandora/host.py +11 -11
  25. bumble/pandora/l2cap.py +2 -2
  26. bumble/pandora/security.py +72 -56
  27. bumble/profiles/aics.py +3 -5
  28. bumble/profiles/ancs.py +3 -1
  29. bumble/profiles/ascs.py +11 -5
  30. bumble/profiles/asha.py +11 -6
  31. bumble/profiles/csip.py +1 -3
  32. bumble/profiles/gatt_service.py +1 -3
  33. bumble/profiles/hap.py +16 -33
  34. bumble/profiles/mcp.py +12 -9
  35. bumble/profiles/vcs.py +5 -5
  36. bumble/profiles/vocs.py +6 -9
  37. bumble/rfcomm.py +17 -8
  38. bumble/smp.py +14 -8
  39. {bumble-0.0.210.dist-info → bumble-0.0.212.dist-info}/METADATA +4 -4
  40. {bumble-0.0.210.dist-info → bumble-0.0.212.dist-info}/RECORD +44 -42
  41. {bumble-0.0.210.dist-info → bumble-0.0.212.dist-info}/WHEEL +1 -1
  42. {bumble-0.0.210.dist-info → bumble-0.0.212.dist-info}/entry_points.txt +0 -0
  43. {bumble-0.0.210.dist-info → bumble-0.0.212.dist-info}/licenses/LICENSE +0 -0
  44. {bumble-0.0.210.dist-info → bumble-0.0.212.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,84 @@
1
+ # Copyright 2021-2025 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License")
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ from __future__ import annotations
16
+
17
+ import functools
18
+
19
+ from cryptography.hazmat.primitives import ciphers
20
+ from cryptography.hazmat.primitives.ciphers import algorithms
21
+ from cryptography.hazmat.primitives.ciphers import modes
22
+ from cryptography.hazmat.primitives.asymmetric import ec
23
+ from cryptography.hazmat.primitives import cmac
24
+
25
+
26
+ def e(key: bytes, data: bytes) -> bytes:
27
+ '''
28
+ AES-128 ECB, expecting byte-swapped inputs and producing a byte-swapped output.
29
+
30
+ See Bluetooth spec Vol 3, Part H - 2.2.1 Security function e
31
+ '''
32
+
33
+ cipher = ciphers.Cipher(algorithms.AES(key[::-1]), modes.ECB())
34
+ encryptor = cipher.encryptor()
35
+ return encryptor.update(data[::-1])[::-1]
36
+
37
+
38
+ class EccKey:
39
+ def __init__(self, private_key: ec.EllipticCurvePrivateKey) -> None:
40
+ self.private_key = private_key
41
+
42
+ @classmethod
43
+ def generate(cls) -> EccKey:
44
+ return EccKey(ec.generate_private_key(ec.SECP256R1()))
45
+
46
+ @classmethod
47
+ def from_private_key_bytes(cls, d_bytes: bytes) -> EccKey:
48
+ d = int.from_bytes(d_bytes, byteorder='big', signed=False)
49
+ return EccKey(ec.derive_private_key(d, ec.SECP256R1()))
50
+
51
+ @functools.cached_property
52
+ def x(self) -> bytes:
53
+ return (
54
+ self.private_key.public_key()
55
+ .public_numbers()
56
+ .x.to_bytes(32, byteorder='big')
57
+ )
58
+
59
+ @functools.cached_property
60
+ def y(self) -> bytes:
61
+ return (
62
+ self.private_key.public_key()
63
+ .public_numbers()
64
+ .y.to_bytes(32, byteorder='big')
65
+ )
66
+
67
+ def dh(self, public_key_x: bytes, public_key_y: bytes) -> bytes:
68
+ x = int.from_bytes(public_key_x, byteorder='big', signed=False)
69
+ y = int.from_bytes(public_key_y, byteorder='big', signed=False)
70
+ return self.private_key.exchange(
71
+ ec.ECDH(),
72
+ ec.EllipticCurvePublicNumbers(x, y, ec.SECP256R1()).public_key(),
73
+ )
74
+
75
+
76
+ def aes_cmac(m: bytes, k: bytes) -> bytes:
77
+ '''
78
+ See Bluetooth spec, Vol 3, Part H - 2.2.5 FunctionAES-CMAC
79
+
80
+ NOTE: the input and output of this internal function are in big-endian byte order
81
+ '''
82
+ mac = cmac.CMAC(algorithms.AES(k))
83
+ mac.update(m)
84
+ return mac.finalize()