Files
MoviePilot/app/application/download/validation.py

14 lines
376 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""下载应用服务共享的输入校验。"""
from __future__ import annotations
import re
_TORRENT_HASH_PATTERN = re.compile(r"^[0-9a-fA-F]{40}$")
def validate_torrent_hash(hash_value: str) -> None:
"""校验 BitTorrent v1 Hash,拒绝模糊任务定位。"""
if not _TORRENT_HASH_PATTERN.fullmatch(hash_value):
raise ValueError("hash 格式无效")