Skip to content

Commit 519f22f

Browse files
authored
Switch to using ChaCha20Poly1305Reusable for encryption (#413)
The ChaCha20Poly1305 that comes with cryptography recreates the ctx every time encrypt is called. Since we call encrypt in a loop, we can avoid this overhead by using ChaCha20Poly1305Reusable instead as we are doing everything in the same thread and not concerned about thread safety
1 parent 379ac36 commit 519f22f

13 files changed

Lines changed: 14 additions & 17 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
runs-on: ubuntu-latest
1010
strategy:
1111
matrix:
12-
python-version: [3.6, 3.7, 3.8, 3.9]
12+
python-version: [3.7, 3.8, 3.9, "3.10"]
1313

1414
steps:
1515
- uses: actions/checkout@v1

docs/source/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
#
6161
# This is also used if you do content translation via gettext catalogs.
6262
# Usually you set "language" from the command line for these cases.
63-
language = None
63+
#language = None
6464

6565
# List of patterns, relative to source directory, that match files and
6666
# directories to ignore when looking for source files.
@@ -158,4 +158,4 @@
158158
]
159159

160160

161-
# -- Extension configuration -------------------------------------------------
161+
# -- Extension configuration -------------------------------------------------

pyhap/accessory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def setup_message(self):
245245
)
246246
else:
247247
print(
248-
"To use the QR Code feature, use 'pip install " "HAP-python[QRCode]'",
248+
"To use the QR Code feature, use 'pip install HAP-python[QRCode]'",
249249
flush=True,
250250
)
251251
print(

pyhap/camera.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ async def start_stream(self, session_info, stream_config):
842842

843843
return True
844844

845-
async def stop_stream(self, session_info): # pylint: disable=no-self-use
845+
async def stop_stream(self, session_info):
846846
"""Stop the stream for the given ``session_id``.
847847
848848
This method can be implemented if custom stop stream commands are needed. The
@@ -886,7 +886,7 @@ async def reconfigure_stream(self, session_info, stream_config):
886886
"""
887887
await self.start_stream(session_info, stream_config)
888888

889-
def get_snapshot(self, image_size): # pylint: disable=unused-argument, no-self-use
889+
def get_snapshot(self, image_size): # pylint: disable=unused-argument
890890
"""Return a jpeg of a snapshot from the camera.
891891
892892
Overwrite to implement getting snapshots from your camera.

pyhap/hap_crypto.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
import logging
33
import struct
44

5+
from chacha20poly1305_reuseable import ChaCha20Poly1305Reusable as ChaCha20Poly1305
56
from cryptography.hazmat.backends import default_backend
67
from cryptography.hazmat.primitives import hashes
7-
from cryptography.hazmat.primitives.ciphers.aead import ChaCha20Poly1305
88
from cryptography.hazmat.primitives.kdf.hkdf import HKDF
99

1010
logger = logging.getLogger(__name__)

pyhap/hap_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from cryptography.exceptions import InvalidSignature, InvalidTag
1313
from cryptography.hazmat.primitives import serialization
1414
from cryptography.hazmat.primitives.asymmetric import ed25519, x25519
15-
from cryptography.hazmat.primitives.ciphers.aead import ChaCha20Poly1305
15+
from chacha20poly1305_reuseable import ChaCha20Poly1305Reusable as ChaCha20Poly1305
1616

1717
from pyhap import tlv
1818
from pyhap.const import (

pyhap/hap_protocol.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
logger = logging.getLogger(__name__)
2020

21-
HIGH_WRITE_BUFFER_SIZE = 2 ** 19
21+
HIGH_WRITE_BUFFER_SIZE = 2**19
2222
# We timeout idle connections after 90 hours as we must
2323
# clean up unused sockets periodically. 90 hours was choosen
2424
# as its the longest time we expect a user to be away from

pylintrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@ disable=
1010
too-many-public-methods,
1111
too-many-return-statements,
1212
too-many-statements,
13-
bad-continuation,
1413
unused-argument,
1514
consider-using-with

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
README = f.read()
2323

2424

25-
REQUIRES = ["cryptography", "zeroconf>=0.36.2", "h11"]
25+
REQUIRES = ["cryptography", "chacha20poly1305-reuseable", "zeroconf>=0.36.2", "h11"]
2626

2727

2828
setup(

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,5 @@ def __init__(self):
5252
def publish(self, data, client_addr=None, immediate=False):
5353
pass
5454

55-
def add_job(self, target, *args): # pylint: disable=no-self-use
55+
def add_job(self, target, *args):
5656
asyncio.new_event_loop().run_until_complete(target(*args))

0 commit comments

Comments
 (0)