Skip to content

Commit

Permalink
fix: torrent id hex validation
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed May 31, 2024
1 parent 781973b commit c432732
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions transmission_rpc/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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")

Expand Down

0 comments on commit c432732

Please sign in to comment.