from .validation_gs1_check_digit_gs1_check_digit import gs1_check_digit def is_gs1_check_digit_valid(key: str) -> bool: """Whether the last digit of `key` is the GS1 check digit of the digits before it. Only the arithmetic: the length, the prefix and an all-zero key are the caller's to judge. Validators answer rather than raise, so anything that is not two or more ASCII digits is False. """ if not isinstance(key, str) or len(key) < 2 or any(ch < "0" or ch > "9" for ch in key): return False return gs1_check_digit(key[:-1]) == ord(key[-1]) - 48