(master: str, text: str)
| 825 | |
| 826 | |
| 827 | def vault_encrypt(master: str, text: str) -> Optional[str]: |
| 828 | text = (text or "").strip() |
| 829 | if not text: |
| 830 | return None |
| 831 | env = os.environ.copy() |
| 832 | env["FS_PASS"] = master |
| 833 | res = subprocess.run( |
| 834 | ["openssl", "enc", "-aes-256-cbc", "-pbkdf2", "-salt", "-a", "-A", "-pass", "env:FS_PASS"], |
| 835 | input=text.encode("utf-8"), capture_output=True, env=env, check=False |
| 836 | ) |
| 837 | if res.returncode != 0: |
| 838 | raise RuntimeError(res.stderr.decode("utf-8", "ignore") or "Encryption failed") |
| 839 | return res.stdout.decode("utf-8").strip() |
| 840 | |
| 841 | |
| 842 | def vault_decrypt(master: str, token: Optional[str]) -> str: |
no test coverage detected