| 1 |
"""Security tools.""" |
| 2 |
|
| 3 |
from __future__ import annotations |
| 4 |
|
| 5 |
from enum import IntEnum, unique |
| 6 |
|
| 7 |
from asusrouter.const import UNKNOWN_MEMBER |
| 8 |
from asusrouter.tools.enum import FromIntMixin |
| 9 |
|
| 10 |
|
| 11 |
@unique |
| 12 |
class ARSecurityLevel(FromIntMixin, IntEnum): |
| 13 |
"""Security levels for the data processed by AsusRouter. |
| 14 |
|
| 15 |
Levels: |
| 16 |
- **STRICT** - no user-related data is exposed outside |
| 17 |
- **DEFAULT** - non-sensitive user-related data is exposed |
| 18 |
- **SANITIZED** - user-related data is available but is |
| 19 |
automatically sanitized before being exposed |
| 20 |
- **UNSAFE** - user-related data is exposed |
| 21 |
""" |
| 22 |
|
| 23 |
UNKNOWN = UNKNOWN_MEMBER |
| 24 |
STRICT = 0 |
| 25 |
DEFAULT = 1 |
| 26 |
SANITIZED = 5 |
| 27 |
UNSAFE = 9 |
| 28 |
|
| 29 |
@classmethod |
| 30 |
def at_least_strict(cls, level: ARSecurityLevel) -> bool: |
| 31 |
"""Check if the security level is at least strict.""" |
| 32 |
|
| 33 |
return level.value >= cls.STRICT.value |
| 34 |
|
| 35 |
@classmethod |
| 36 |
def at_least_default(cls, level: ARSecurityLevel) -> bool: |
| 37 |
"""Check if the security level is at least default.""" |
| 38 |
|
| 39 |
return level.value >= cls.DEFAULT.value |
| 40 |
|
| 41 |
@classmethod |
| 42 |
def at_least_sanitized(cls, level: ARSecurityLevel) -> bool: |
| 43 |
"""Check if the security level is at least sanitized.""" |
| 44 |
|
| 45 |
return level.value >= cls.SANITIZED.value |