mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 22:13:26 +00:00
validate_token: Move validate_token to avoid dependency cycle.
Prep commit to avoid depencency cycle.
This commit is contained in:
committed by
Tim Abbott
parent
8b3cef554b
commit
e6bdf84363
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user