File size: 1,238 Bytes
5e56bcf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""
upif.core.interfaces
~~~~~~~~~~~~~~~~~~~~

Defines the abstract base classes and interfaces for the UPIF system.
All security modules must adhere to these contracts to ensure strict type safety
and consistent execution by the Coordinator.

:copyright: (c) 2025 Yash Dhone.
:license: Proprietary, see LICENSE for details.
"""

from abc import ABC, abstractmethod
from typing import Any, Dict, Optional

class SecurityModule(ABC):
    """
    Abstract Base Class for all Security Modules (Input Guard, Output Shield, etc.).
    
    Enforces a strict 'scan' contract. Modules should be stateless if possible
    or manage their own thread-safe state.
    """

    @abstractmethod
    def scan(self, content: Any, metadata: Optional[Dict[str, Any]] = None) -> Any:
        """
        Scans the provided content for security threats.

        Args:
            content (Any): The payload to scan (usually string, but can be structured).
            metadata (Optional[Dict[str, Any]]): Contextual metadata (e.g., user ID, session).

        Returns:
            Any: The sanitized content (if safe) or a refusal message (if unsafe).
                 MUST NOT raise exceptions; handle internal errors gracefully.
        """
        pass