(data: str, password: str)
| 109 | |
| 110 | |
| 111 | def decrypt(data: str, password: str) -> str: |
| 112 | _, algo, encoded_salt, encoded_token = data.split('$') |
| 113 | salt = base64.urlsafe_b64decode(encoded_salt) |
| 114 | token = base64.urlsafe_b64decode(encoded_token) |
| 115 | |
| 116 | if algo != 'argon2id': |
| 117 | raise ValueError(f'Unsupported algorithm {algo!r}') |
| 118 | |
| 119 | f = _get_fernet(salt, password) |
| 120 | try: |
| 121 | decrypted = f.decrypt(token) |
| 122 | except InvalidToken: |
| 123 | raise ValueError('Invalid password') |
| 124 | |
| 125 | return decrypted.decode('utf-8') |
no test coverage detected