Reduce ChaCha20CipherReuseable overhead (#489)

This commit is contained in:
J. Nick Koston 2023-07-18 13:06:19 -05:00 committed by GitHub
parent 7196ca6ee8
commit 401ff3b61a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,7 +5,7 @@ from abc import abstractmethod
from enum import Enum from enum import Enum
from functools import partial from functools import partial
from struct import Struct from struct import Struct
from typing import TYPE_CHECKING, Any, Callable, Optional, Union, cast from typing import TYPE_CHECKING, Any, Callable, Optional, Type, Union, cast
from chacha20poly1305_reuseable import ChaCha20Poly1305Reusable from chacha20poly1305_reuseable import ChaCha20Poly1305Reusable
from cryptography.exceptions import InvalidTag from cryptography.exceptions import InvalidTag
@ -42,12 +42,11 @@ WRITE_EXCEPTIONS = (RuntimeError, ConnectionResetError, OSError)
class ChaCha20CipherReuseable(ChaCha20Cipher): # type: ignore[misc] class ChaCha20CipherReuseable(ChaCha20Cipher): # type: ignore[misc]
"""ChaCha20 cipher that can be reused.""" """ChaCha20 cipher that can be reused."""
@property format_nonce = PACK_NONCE
def klass(self): # type: ignore[no-untyped-def]
return ChaCha20Poly1305Reusable
def format_nonce(self, n: int) -> bytes: @property
return PACK_NONCE(n) def klass(self) -> Type[ChaCha20Poly1305Reusable]:
return ChaCha20Poly1305Reusable
class ESPHomeNoiseBackend(DefaultNoiseBackend): # type: ignore[misc] class ESPHomeNoiseBackend(DefaultNoiseBackend): # type: ignore[misc]