py-spectre/spectre/scope.py

43 lines
1.0 KiB
Python

import abc
from enum import Enum
from spectre.template import Template
class Scope(Enum):
AUTHENTICATION = "Authentication"
IDENTIFICATION = "Identification"
RECOVERY = "Recovery"
def default_template(self) -> Template:
if self == Scope.AUTHENTICATION:
return Template.LONG
elif self == Scope.IDENTIFICATION:
return Template.NAME
elif self == Scope.RECOVERY:
return Template.PHRASE
return Template.MAXIMUM
class Scoper(abc.ABC):
@abc.abstractmethod
def scope(self, scope: Scope) -> str:
pass
class SimpleScoper(Scoper):
def __init__(self, key: str):
self.key = key
def scope(self, scope: Scope) -> str:
if scope == Scope.AUTHENTICATION:
return self.key
elif scope == Scope.IDENTIFICATION:
return f"{self.key}.login"
elif scope == Scope.RECOVERY:
return f"{self.key}.answer"
return self.key
default_scoper = SimpleScoper("com.lyndir.masterpassword")