def bytes_fixlen(byteseq: bytes, length: int) -> bytes:
    """
    Fix the length of a byte sequence.
    :param byteseq: The byte sequence to fix the length of.
    :param length: The length of the sequence.
    :return: The byte sequence with fixed length.
    """
    if len(byteseq) > length:
        return byteseq[:length]
    else:
        return (b'\x00' * (length - len(byteseq))) + byteseq