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

1# -*- encoding: utf-8 -*- 

2# pass import - Passwords importer swiss army knife 

3# Copyright (C) 2017-2024 Alexandre PUJOL <alexandre@pujol.io>. 

4# 

5 

6from typing import List 

7from abc import abstractmethod 

8 

9from pass_import.core import Asset, Cap 

10 

11 

12class Detecter(Asset): 

13 """Abstract Password manager format/encryption detection. 

14 

15 To be listed as detecter a class must be registered using 

16 :func:`~register_detecters` 

17 

18 """ 

19 

20 def detecter_open(self): 

21 """Detector context manager. Only required if different than open.""" 

22 self.open() 

23 

24 def detecter_close(self): 

25 """Detector context manager. Only required if different than close.""" 

26 self.close() 

27 

28 

29class Decrypter(Detecter): 

30 """File encryption detection and decryption.""" 

31 cap = Cap.DECRYPT 

32 

33 @abstractmethod 

34 def decrypt(self): 

35 """Decrypt the data source. 

36 

37 :return: Plain data 

38 

39 """ 

40 

41 

42class Formatter(Detecter): 

43 """Manager format dectection.""" 

44 cap = Cap.FORMAT 

45 

46 @abstractmethod 

47 def is_format(self) -> bool: 

48 """Return ``True`` if the prefix has same format than the pm.""" 

49 

50 @abstractmethod 

51 def checkheader(self, header: List, only: bool = False) -> bool: 

52 """Ensure the file header is the same than the pm header.""" 

53 

54 @classmethod 

55 @abstractmethod 

56 def header(cls): 

57 """Commom interface to get format header."""