from __future__ import annotations

"""Gestion de base des clefs RSA pour les licences."""

from pathlib import Path
from typing import Optional

from .generators.key_manager import write_key_pair


class CryptoManager:
    """Fournit les chemins d'accès aux clefs de signature/licence."""

    def __init__(self, key_dir: Optional[Path] = None) -> None:
        self.key_dir = key_dir or (Path.home() / ".web-sentinel" / "keys")
        self.key_dir.mkdir(parents=True, exist_ok=True)
        self.private_key_path = self.key_dir / "license_private.pem"
        self.public_key_path = self.key_dir / "license_public.pem"

    def ensure_keys(self) -> None:
        if not self.private_key_path.exists() or not self.public_key_path.exists():
            write_key_pair(self.key_dir)

    def get_private_key_path(self) -> Path:
        self.ensure_keys()
        return self.private_key_path

    def get_public_key_path(self) -> Path:
        self.ensure_keys()
        return self.public_key_path
