validate_token: Move validate_token to avoid dependency cycle.

Prep commit to avoid depencency cycle.
This commit is contained in:
Prakhar Pratyush
2025-06-16 23:17:02 +05:30
committed by Tim Abbott
parent 8b3cef554b
commit e6bdf84363
3 changed files with 13 additions and 13 deletions

View File

@@ -85,6 +85,17 @@ def hex_to_b64(data: str) -> str:
return base64.b64encode(bytes.fromhex(data)).decode()
def validate_token(token_str: str, kind: int) -> None:
if token_str == "" or len(token_str) > 4096:
raise JsonableError(_("Empty or invalid length token"))
if kind == PushDeviceToken.APNS:
# Validate that we can actually decode the token.
try:
b64_to_hex(token_str)
except Exception:
raise JsonableError(_("Invalid APNS token"))
def get_message_stream_name_from_database(message: Message) -> str:
"""
Never use this function outside of the push-notifications