diff options
| author | David Elentok <3david@gmail.com> | 2024-05-14 18:15:13 +0300 |
|---|---|---|
| committer | David Elentok <3david@gmail.com> | 2024-05-14 18:17:09 +0300 |
| commit | a805d34f123bc8add01bd44ad28f0baf57710083 (patch) | |
| tree | b868cef404823eaf4b7c78316459cf8b2a3fd013 /lua/encrypt/decrypt.lua | |
| download | encrypt.nvim-a805d34f123bc8add01bd44ad28f0baf57710083.tar.gz | |
Initial commit
Diffstat (limited to 'lua/encrypt/decrypt.lua')
| -rw-r--r-- | lua/encrypt/decrypt.lua | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lua/encrypt/decrypt.lua b/lua/encrypt/decrypt.lua new file mode 100644 index 0000000..2ae4e2a --- /dev/null +++ b/lua/encrypt/decrypt.lua @@ -0,0 +1,28 @@ +local helpers = require("encrypt.helpers") + +---@return string[] +---@param lines string | string[] +---@param password string +local function decrypt_lines(lines, password) + return vim.fn.systemlist( + "base64 --decode | openssl enc -d -aes-256-cbc -pbkdf2 -salt -in - -out - -k " .. password, + lines + ) +end + +local function decrypt() + local password = helpers.getPassword() + local encrypted_lines = vim.api.nvim_buf_get_lines(0, 1, -1, false) + local decrypted_lines = decrypt_lines(encrypted_lines, password) + if vim.v.shell_error ~= 0 then + vim.notify("Error decrypting", vim.log.levels.ERROR) + return + end + + vim.fn.timer_start(0, function() + vim.api.nvim_buf_set_lines(0, 0, -1, false, decrypted_lines) + vim.bo.modified = false + end) +end + +return decrypt |
