MCPcopy
hub / github.com/mitmproxy/mitmproxy / unpack

Function unpack

mitmproxy/net/dns/https_records.py:94–113  ·  view source on GitHub ↗

Unpacks HTTPS RDATA from byte data. Raises: struct.error if the record is malformed.

(data: bytes)

Source from the content-addressed store, hash-verified

92
93
94def unpack(data: bytes) -> HTTPSRecord:
95 """
96 Unpacks HTTPS RDATA from byte data.
97
98 Raises:
99 struct.error if the record is malformed.
100 """
101 offset = 0
102
103 # Priority (2 bytes)
104 priority = struct.unpack("!h", data[offset : offset + 2])[0]
105 offset += 2
106
107 # TargetName (variable length)
108 target_name, offset = domain_names.unpack_from(data, offset)
109
110 # Service Parameters (remaining bytes)
111 params = _unpack_params(data, offset)
112
113 return HTTPSRecord(priority=priority, target_name=target_name, params=params)
114
115
116def _pack_params(params: dict[int, bytes]) -> bytes:

Callers

nothing calls this directly

Calls 4

_unpack_paramsFunction · 0.85
HTTPSRecordClass · 0.85
unpackMethod · 0.80
unpack_fromMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…