]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Improve readability of endianness conversions
authorŠtěpán Balážik <stepan@isc.org>
Fri, 10 Apr 2026 16:25:17 +0000 (18:25 +0200)
committerŠtěpán Balážik <stepan@isc.org>
Fri, 17 Apr 2026 14:26:07 +0000 (14:26 +0000)
Replace the less obvious and less explicit `struct.unpack()` and
`struct.pack()` calls with calls to `int.from_bytes()` and
`int.to_bytes()`, respectively.

bin/tests/system/isctest/asyncserver.py

index e29d6f7e9a0e98284d1ab27ecab270aa0ddcebd4..53cdfeb47c1ba5a5e03c9fea44e7167be3ddc553 100644 (file)
@@ -26,7 +26,6 @@ import os
 import pathlib
 import re
 import signal
-import struct
 import sys
 
 import dns.exception
@@ -1273,9 +1272,7 @@ class AsyncDnsServer(AsyncServer):
         if not wire_length_bytes:
             return None
 
-        (wire_length,) = struct.unpack("!H", wire_length_bytes)
-
-        return wire_length
+        return int.from_bytes(wire_length_bytes, byteorder="big")
 
     async def _read_tcp_query_wire(
         self, reader: asyncio.StreamReader, peer: Peer, wire_length: int
@@ -1416,8 +1413,7 @@ class AsyncDnsServer(AsyncServer):
                 if protocol == DnsProtocol.UDP:
                     yield response
                 else:
-                    response_length = struct.pack("!H", len(response))
-                    yield response_length + response
+                    yield len(payload).to_bytes(2, byteorder="big") + payload
 
     def _parse_message(self, wire: bytes) -> dns.message.Message:
         try: