| 27 | |
| 28 | @dataclass |
| 29 | class _Masked: |
| 30 | unmasked: bytes |
| 31 | |
| 32 | def __eq__(self, other): |
| 33 | other = bytearray(other) |
| 34 | assert other[1] & 0b1000_0000 # assert this is actually masked |
| 35 | other[1] &= 0b0111_1111 # remove mask bit |
| 36 | assert other[1] < 126 # (we don't support extended payload length here) |
| 37 | mask = other[2:6] |
| 38 | payload = bytes(x ^ mask[i % 4] for i, x in enumerate(other[6:])) |
| 39 | return self.unmasked == other[:2] + payload |
| 40 | |
| 41 | |
| 42 | # noinspection PyTypeChecker |