from __future__ import annotations import logging import random logger = logging.getLogger(__name__) class ZulipPairing: def __init__(self): self._codes: dict[str, tuple[str, float]] = {} async def generate_code(self, peer_id: str) -> str: import time as _time code = f"{random.randint(100000, 999999)}" self._codes[peer_id] = (code, _time.time()) return code async def verify_code(self, peer_id: str, code: str) -> bool: import time as _time if peer_id not in self._codes: return False stored_code, timestamp = self._codes[peer_id] if _time.time() - timestamp > 600: self._codes.pop(peer_id, None) return False if stored_code != code.strip(): return False self._codes.pop(peer_id, None) return True def normalize_allow_entry(self, entry: str) -> str: return entry.strip().lower()