From c432732ce5a69db3dced8222ef2cd8d2e34aeab8 Mon Sep 17 00:00:00 2001 From: Trim21 Date: Fri, 31 May 2024 21:04:20 +0800 Subject: [PATCH] fix: torrent id hex validation --- transmission_rpc/client.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/transmission_rpc/client.py b/transmission_rpc/client.py index 70f47dcf..c9944681 100644 --- a/transmission_rpc/client.py +++ b/transmission_rpc/client.py @@ -26,7 +26,7 @@ from transmission_rpc.types import Group, _Timeout from transmission_rpc.utils import _try_read_torrent, get_torrent_arguments -valid_hash_char = string.digits + string.ascii_letters +_hex_chars = frozenset(string.hexdigits.lower()) _TorrentID = Union[int, str] _TorrentIDs = Union[_TorrentID, List[_TorrentID], None] @@ -57,8 +57,8 @@ def _parse_torrent_id(raw_torrent_id: int | str) -> int | str: if raw_torrent_id >= 0: return raw_torrent_id elif isinstance(raw_torrent_id, str): - if len(raw_torrent_id) != 40 or (set(raw_torrent_id) - set(valid_hash_char)): - raise ValueError(f"torrent ids {raw_torrent_id} is not valid torrent id") + if len(raw_torrent_id) != 40 or (set(raw_torrent_id) - _hex_chars): + raise ValueError(f"torrent ids {raw_torrent_id} is not valid torrent id, should be a hex str for sha1 hash") return raw_torrent_id raise ValueError(f"{raw_torrent_id} is not valid torrent id")