def is_hexstring(string):
    """
    Determines if a string is a hexstring.
    :param Union[ByteString, str] string: A string.
    :return: Whether the string's length is even and all of its characters
        are in [0-9a-fA-f].
    """
    if isinstance(string, str):
        string = string.encode()
    return not len(string) % 2 and all(
        0x30 <= c <= 0x39 or 0x61 <= c <= 0x66 for c in string.lower()
    )