Coverage for oarepo_c4gh/crypt4gh/analyzer.py: 100%

23 statements  

« prev     ^ index     » next       coverage.py v7.10.2, created at 2025-08-07 12:05 +0000

1""" 

2Module with the Crypt4GH container analyzer. 

3""" 

4 

5from .common.header_packet import HeaderPacket 

6from .common.data_block import DataBlock 

7 

8 

9class Analyzer: 

10 """The instance of this class keeps track of readable header 

11 packets and accessible data blocks and provides summary results 

12 about these. 

13 

14 """ 

15 

16 def __init__(self): 

17 """Initializes the instance with empty lists and no key 

18 information. 

19 """ 

20 self._packet_info = [] 

21 self._block_info = [] 

22 self._public_keys = [] 

23 

24 def analyze_packet(self, packet: HeaderPacket) -> None: 

25 """Analyzes single header packet and adds the result into the 

26 packet_info list. 

27 

28 Parameters: 

29 packet: single header packet instance 

30 

31 """ 

32 if packet.is_readable: 

33 self._packet_info.append(packet.reader_key) 

34 if not packet.reader_key in self._public_keys: 

35 self._public_keys.append(packet.reader_key) 

36 else: 

37 self._packet_info.append(False) 

38 

39 def analyze_block(self, block: DataBlock) -> None: 

40 """Analyzes single data block and adds the result into the 

41 block_info list. 

42 

43 Parameters: 

44 block: data block information class instance 

45 

46 """ 

47 if block.is_deciphered: 

48 self._block_info.append(block.dek_index) 

49 else: 

50 self._block_info.append(False) 

51 

52 def to_dict(self) -> dict: 

53 """Returns dictionary representation of the analysis.""" 

54 result = {} 

55 result["header"] = self._packet_info 

56 result["readers"] = self._public_keys 

57 result["blocks"] = self._block_info 

58 return result