aboutsummaryrefslogtreecommitdiff
path: root/lua/encrypt/helpers.lua
blob: a2ccc5115625f0bec18a81fde43f98ad1706a8bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
---@return function string
local getPasswordFactory = function()
  local bufferPasswordMap = {}

  return function()
    local key = string.format("%s", vim.fn.bufnr())
    if bufferPasswordMap[key] == nil then
      password = vim.fn.inputsecret("Enter password: ")
      bufferPasswordMap[key] = password
    end
    return bufferPasswordMap[key]
  end
end

local getPassword = getPasswordFactory()
local ENCRYPTED_PREFIX = "# <<<encrypted>>>"

---@enum buftype
local BUFTYPE = {
  encrypted = 1,
  plaintext = 2,
}

return { getPassword = getPassword, ENCRYPTED_PREFIX = ENCRYPTED_PREFIX, BUFTYPE = BUFTYPE}