ForcePilot/backend/package/yuxi/channel/extensions/matrix/crypto.py

30 lines
965 B
Python
Raw Normal View History

from __future__ import annotations
import logging
logger = logging.getLogger(__name__)
def get_olm_store_path(account_id: str = "default") -> str:
return f"data/matrix_store/{account_id}"
def is_decryption_failure(event) -> bool:
source = getattr(event, "source", {})
return source.get("type") == "m.room.encrypted" and "body" not in source.get("content", {})
def diagnose_decryption(event) -> dict:
source = getattr(event, "source", {})
content = source.get("content", {})
ciphertext = content.get("ciphertext", "")
return {
"event_id": getattr(event, "event_id", ""),
"room_id": getattr(event, "room_id", ""),
"has_body": "body" in content,
"algorithm": content.get("algorithm", "unknown"),
"sender_key": (content.get("sender_key", "") or "")[:16] + "...",
"session_id": content.get("session_id", "unknown"),
"ciphertext_len": len(ciphertext) if ciphertext else 0,
}