@staticmethod
    def from_stream(body):
        if len(body) < 3:
            raise ValueError("Not enough data")
        # TODO: Support for long (3 byte) header
        if ord(body[0]) & 0x80 == 0:
            raise ValueError("Long header not supported")
        length, msg_type = struct.unpack_from("!HB", body, 0)
        length &= 0x7fff
        msg_data = body[3:2 + length]
        if len(msg_data) != length - 1:
            raise ValueError("Not enough data")
        type = typemap.get(msg_type)
        if not type:
            raise ValueError("Unsupported message type: %d" % msg_type)
        obj, size = type.from_stream(msg_data)
        if len(msg_data) != size:
            raise ValueError("Read mismatch")
        return HandshakeMessage(msg_type, obj), 2 + length
dataset/ETHPy150Open google/nogotofail/nogotofail/mitm/util/ssl2/types/handshake.py/HandshakeMessage.from_stream/original