MCPcopy
hub / github.com/mitmproxy/mitmproxy / masked_bytes

Function masked_bytes

test/mitmproxy/proxy/layers/test_websocket.py:47–53  ·  view source on GitHub ↗
(unmasked: bytes)

Source from the content-addressed store, hash-verified

45
46
47def masked_bytes(unmasked: bytes) -> bytes:
48 header = bytearray(unmasked[:2])
49 assert header[1] < 126 # assert that this is neither masked nor extended payload
50 header[1] |= 0b1000_0000
51 mask = secrets.token_bytes(4)
52 masked = bytes(x ^ mask[i % 4] for i, x in enumerate(unmasked[2:]))
53 return bytes(header + mask + masked)
54
55
56def test_masking():

Callers 5

test_maskingFunction · 0.85
test_upgradeFunction · 0.85
test_upgrade_streamedFunction · 0.85
test_pingFunction · 0.85
test_close_normalFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…