Small cleanups to noise write_packet (#627)

This commit is contained in:
J. Nick Koston 2023-11-09 11:28:18 -06:00 committed by GitHub
parent 419bf67e9b
commit 8678fa9ebc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View File

@ -30,3 +30,9 @@ cdef class APINoiseFrameHelper(APIFrameHelper):
type_low=cython.uint
)
cpdef _handle_frame(self, bytes data)
@cython.locals(
data_len=cython.uint,
frame_len=cython.uint
)
cpdef write_packet(self, cython.uint type_, bytes data)

View File

@ -61,6 +61,8 @@ class NoiseConnectionState(Enum):
NOISE_HELLO = b"\x01\x00\x00"
int_ = int
class APINoiseFrameHelper(APIFrameHelper):
"""Frame helper for noise encrypted connections."""
@ -302,7 +304,7 @@ class APINoiseFrameHelper(APIFrameHelper):
)
self._ready_future.set_result(None)
def write_packet(self, type_: int, data: bytes) -> None:
def write_packet(self, type_: int_, data: bytes) -> None:
"""Write a packet to the socket."""
if not self._is_ready:
raise HandshakeAPIError(f"{self._log_name}: Noise connection is not ready")
@ -312,10 +314,10 @@ class APINoiseFrameHelper(APIFrameHelper):
assert self._writer is not None, "Writer is not set"
data_len = len(data)
type_len = bytes(
data_header = bytes(
((type_ >> 8) & 0xFF, type_ & 0xFF, (data_len >> 8) & 0xFF, data_len & 0xFF)
)
frame = self._encrypt(type_len + data)
frame = self._encrypt(data_header + data)
if self._debug_enabled():
_LOGGER.debug("%s: Sending frame: [%s]", self._log_name, frame.hex())