Project

Profile

Help

Revision 58dd663a

ID58dd663a6c5a289acda6b3431bca82527ffd74b9
Parent 738db9e9
Child 79410025, 2b064aa0, e5a2b431

Added by Vincent Le Goff over 1 year ago

Fix the issue with new character's encrypted data

View differences:

src/safe.py
149 149
    def load(self):
150 150
        """Load the data from the 'secret' file if exists."""
151 151
        if os.path.exists(self.secret):
152
            try:
153
                with open(self.secret, "rb") as file:
154
                    upic = pickle.Unpickler(file, encoding="utf-8")
155
                    print("Load as UTF8")
156
                    self.data = upic.load()
157
            except UnicodeDecodeError:
158
                with open(self.secret, "rb") as file:
159
                    upic = pickle.Unpickler(file, encoding="latin-1")
160
                    print("Load at latin-1")
161
                    self.data = upic.load()
162

  
163
                self.save()
152
            with open(self.secret, "rb") as file:
153
                upic = pickle.Unpickler(file, encoding="utf-8")
154
                self.data = upic.load()
164 155

  
165 156
            if not isinstance(self.data, dict):
166 157
                raise ValueError("the data contained in the file " \
......
182 173
            raise KeyError(key)
183 174

  
184 175
        value = self.data[key]
185
        if isinstance(value, tuple) and value[0] == "str":
176
        if isinstance(value, (bytes, str)):
186 177
            salt = self.get_salt_from_key(key)
187
            return self.decrypt(value[1], salt)
178
            return self.decrypt(value, salt)
188 179

  
189 180
        return value
190 181

  
......
199 190
        if isinstance(value, str):
200 191
            salt = self.get_salt_from_key(key)
201 192
            crypted = self.encrypt(value, salt)
202
            self.data[key] = ("str", crypted)
193
            self.data[key] = crypted
203 194
        else:
204 195
            self.data[key] = value
205 196

  

Also available in: Unified diff