from __future__ import annotations import random import time class EmailSmtpPairingAdapter: id_label = "email_address" def __init__(self): self._codes: dict[str, dict] = {} self._code_ttl = 600 def generate_code(self, peer_id: str) -> str: code = str(random.randint(100000, 999999)) self._codes[peer_id] = {"code": code, "ts": time.monotonic()} return code def verify_code(self, peer_id: str, code: str) -> bool: entry = self._codes.get(peer_id) if not entry: return False if time.monotonic() - entry["ts"] > self._code_ttl: del self._codes[peer_id] return False return entry["code"] == code def normalize_allow_entry(self, entry: str) -> str: return entry.strip().lower()