mirror of
https://github.com/esphome/aioesphomeapi.git
synced 2025-01-12 20:10:42 +01:00
Speed up formatting the cipher nonce (#477)
This commit is contained in:
parent
8306058703
commit
5dd12169f1
@ -4,6 +4,7 @@ import logging
|
||||
from abc import abstractmethod
|
||||
from enum import Enum
|
||||
from functools import partial
|
||||
from struct import Struct
|
||||
from typing import TYPE_CHECKING, Any, Callable, Optional, cast
|
||||
|
||||
import async_timeout
|
||||
@ -34,12 +35,19 @@ SOCKET_ERRORS = (
|
||||
TimeoutError,
|
||||
)
|
||||
|
||||
PACK_NONCE = partial(Struct("<LQ").pack, 0)
|
||||
|
||||
|
||||
class ChaCha20CipherReuseable(ChaCha20Cipher): # type: ignore[misc]
|
||||
"""ChaCha20 cipher that can be reused."""
|
||||
|
||||
@property
|
||||
def klass(self): # type: ignore[no-untyped-def]
|
||||
return ChaCha20Poly1305Reusable
|
||||
|
||||
def format_nonce(self, n: int) -> bytes:
|
||||
return PACK_NONCE(n)
|
||||
|
||||
|
||||
class ESPHomeNoiseBackend(DefaultNoiseBackend): # type: ignore[misc]
|
||||
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
||||
|
Loading…
Reference in New Issue
Block a user