@@ -37,34 +37,22 @@ def encrypt_bytes(cls, data: bytes):
3737 def header_length (cls ):
3838 return sum (x [0 ] for x in cls .HEADER )
3939
40- @staticmethod
41- def _decode_chunk (b : bytes , length : int ):
42- data = b [:length ]
43- bnext = b [length :]
44-
45- return data , bnext
46-
4740 @classmethod
4841 def _decode_header (cls , data : bytes ):
49- header = {}
50- b = data
42+ value : bytes | str
5143 for length , name in cls .HEADER :
52- value , b = cls . _decode_chunk ( b = b , length = length )
44+ value , data = data [: length ], data [ length :]
5345
5446 try :
5547 value = value .decode (cls .HENC )
5648 except ValueError :
5749 pass
5850
59- header [name ] = value
60-
61- return header
51+ yield name , value
6252
6353 @classmethod
6454 def _print_header_info (cls , header : bytes ):
65- header_dict = cls ._decode_header (header )
66-
67- for key , value in header_dict .items ():
55+ for key , value in cls ._decode_header (header ):
6856 if key == 'password' :
6957 continue
7058
@@ -108,16 +96,15 @@ def decrypt(cls,
10896 header : None | str | Path = None ,
10997 value : None | str | Path = None ):
11098 path = Path (path )
111- header = (path .with_suffix (cls .HEXT )
112- if header is None else Path (header ))
113- value = (path .with_suffix (cls .VEXT ) if value is None else Path (value ))
99+ header = path .with_suffix (cls .HEXT ) if header is None else Path (header )
100+ value = path .with_suffix (cls .VEXT ) if value is None else Path (value )
114101
115102 logger .info ('Input: "{}"' , path )
116103 logger .debug ('Header: "{}"' , header )
117104 logger .debug ('Value: "{}"' , value )
118105
119106 data = path .read_bytes ()
120- decrypt = ( path .suffix == '.eco' )
107+ decrypt = path .suffix . lower () == '.eco'
121108
122109 try :
123110 hdata , vdata = cls ._decrypt (data = data , decrypt = decrypt )
0 commit comments