Refactor noise _error_on_incorrect_preamble to improve coverage (#683)

This commit is contained in:
J. Nick Koston 2023-11-24 08:36:31 -06:00 committed by GitHub
parent 39aba56958
commit b31472c569
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -253,16 +253,15 @@ class APINoiseFrameHelper(APIFrameHelper):
def _error_on_incorrect_preamble(self, msg: bytes) -> None:
"""Handle an incorrect preamble."""
explanation = msg[1:].decode()
if explanation == "Handshake MAC failure":
self._handle_error_and_close(
InvalidEncryptionKeyAPIError(
if explanation != "Handshake MAC failure":
exc = HandshakeAPIError(
f"{self._log_name}: Handshake failure: {explanation}"
)
else:
exc = InvalidEncryptionKeyAPIError(
f"{self._log_name}: Invalid encryption key", self._server_name
)
)
return
self._handle_error_and_close(
HandshakeAPIError(f"{self._log_name}: Handshake failure: {explanation}")
)
self._handle_error_and_close(exc)
def _handle_handshake(self, msg: bytes) -> None:
if msg[0] != 0: