import struct


def read_packet_header(packet, header_size):
    """
    Gets type and length of packet. On error, returns None tuple.

    :param packet: Full packet
    :return: Type and length of packet in bytes
    """
    try:
        return struct.unpack('!bi', packet[:header_size])
    except (struct.error, TypeError) as e:
        return None, None