def build_handshake_packet(data): packet = HandshakePacket(*data.splitlines()) assert len(a2b(packet.identity_key)) == KEY_LEN assert len(a2b(packet.handshake_key)) == KEY_LEN assert len(a2b(packet.ratchet_key)) == KEY_LEN return packet
def build_request_packet(data): packet = RequestPacket(*data.splitlines()) assert len(a2b(packet.handshake_packet_hash)) == HASH_LEN assert len(a2b(packet.request_key)) == KEY_LEN a2b(packet.handshake_packet) return packet
def build_reply_packet(data): packet = RegularPacket(*data.splitlines()) check_payload(packet) assert len(a2b(packet.handshake_key)) == ENC_KEY_LEN return packet
def build_regular_packet(data): packet = RegularPacket(*data.splitlines()) check_payload(packet) assert not len(a2b(packet.handshake_key)) return packet
def check_payload(packet): assert len(a2b(packet.payload_hash)) == HASH_LEN a2b(packet.payload)
def check_iv(packet): assert len(a2b(packet.iv)) == IV_LEN assert len(a2b(packet.iv_hash)) == HASH_LEN