Coverage for pass_import/detecter.py: 100%
21 statements
« prev ^ index » next coverage.py v7.4.3, created at 2024-02-26 12:11 +0000
« prev ^ index » next coverage.py v7.4.3, created at 2024-02-26 12:11 +0000
1# -*- encoding: utf-8 -*-
2# pass import - Passwords importer swiss army knife
3# Copyright (C) 2017-2024 Alexandre PUJOL <alexandre@pujol.io>.
4#
6from typing import List
7from abc import abstractmethod
9from pass_import.core import Asset, Cap
12class Detecter(Asset):
13 """Abstract Password manager format/encryption detection.
15 To be listed as detecter a class must be registered using
16 :func:`~register_detecters`
18 """
20 def detecter_open(self):
21 """Detector context manager. Only required if different than open."""
22 self.open()
24 def detecter_close(self):
25 """Detector context manager. Only required if different than close."""
26 self.close()
29class Decrypter(Detecter):
30 """File encryption detection and decryption."""
31 cap = Cap.DECRYPT
33 @abstractmethod
34 def decrypt(self):
35 """Decrypt the data source.
37 :return: Plain data
39 """
42class Formatter(Detecter):
43 """Manager format dectection."""
44 cap = Cap.FORMAT
46 @abstractmethod
47 def is_format(self) -> bool:
48 """Return ``True`` if the prefix has same format than the pm."""
50 @abstractmethod
51 def checkheader(self, header: List, only: bool = False) -> bool:
52 """Ensure the file header is the same than the pm header."""
54 @classmethod
55 @abstractmethod
56 def header(cls):
57 """Commom interface to get format header."""