Reject odd-length tag UIDs

This commit is contained in:
dajiaohuang committed 2026-10-02 23:06:38 +08:00
1 parent 7c4dcc7da7
commit bce0d8069a
1 file changed
+2
+2
View File
@@ -82,6 +82,8 @@ def normalize_uid(uid: str) -> str:
raise ValueError("A tag UID must not be empty.")
if not _HEX_ONLY.match(normalized):
raise ValueError(f'"{uid}" is not a valid tag UID. A UID must be hexadecimal.')
if len(normalized) % 2:
raise ValueError("A tag UID must contain a whole number of bytes (an even number of hex characters).")
if len(normalized) > UID_MAX_LENGTH:
raise ValueError(f"A tag UID can be at most {UID_MAX_LENGTH} hex characters.")
return normalized