Skip to content

Commit f167fb7

Browse files
committed
fix: don’t shit when state is encrypted and new file is added
1 parent e515994 commit f167fb7

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

cryptlib.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,25 @@
33
import os
44

55
EXTRA_STR = 'ENCo0D#DT{xTCh$cKe>'
6+
ENCODED_IDF = '=*=EnC0d3dH3aDer==*'
67

78

89
def encode(key, clear):
910
st = ''
10-
clear += EXTRA_STR
11+
if clear.startswith(ENCODED_IDF): # already encoded, no need to encode
12+
return clear
13+
clear += EXTRA_STR # used to check if decrypt is correct
1114
incr = get_key_hash(key)
1215
for _ in clear:
1316
st += chr(incr + ord(_))
14-
return base64.b64encode(st.encode('utf-8')).decode('utf-8')
17+
return ENCODED_IDF + base64.b64encode(st.encode('utf-8')).decode('utf-8')
1518

1619

1720
def decode(key, enc):
1821
st = ''
22+
if not enc.startswith(ENCODED_IDF): # not encoded, so not decode
23+
return enc
24+
enc = enc[len(ENCODED_IDF):] # trim out idf
1925
enc = base64.b64decode(enc).decode('utf-8') # dont know why urlsafe decode doesn't work
2026
incr = get_key_hash(key)
2127
for _ in enc:

0 commit comments

Comments
 (0)