Skip to content

Commit

Permalink
feat: use sha256 for hashing
Browse files Browse the repository at this point in the history
  • Loading branch information
3rd committed May 14, 2024
1 parent e3d2cc1 commit 4d7ae21
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lua/image/image.lua
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ local from_url = function(url, options, callback, state)
return
end

local tmp_path = state.tmp_dir .. "/" .. utils.hash.simple(url) .. ".png"
local tmp_path = state.tmp_dir .. "/" .. utils.hash.sha256(url) .. ".png"
local stdout = vim.loop.new_pipe()

vim.loop.spawn("curl", {
Expand Down
2 changes: 1 addition & 1 deletion lua/image/utils/document.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ local create_document_integration = function(config)
window.id,
window.buffer,
match.range.start_row,
utils.hash.simple(match.url)
utils.hash.sha256(match.url)
)

if ctx.options.only_render_image_at_cursor and match.range.start_row ~= cursor_row then goto continue end
Expand Down
9 changes: 7 additions & 2 deletions lua/image/utils/hash.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local bit = require("bit")

local filename = function(str)
local simple = function(str)
local hash = 5381
for i = 1, #str do
local char = string.byte(str, i)
Expand All @@ -9,6 +9,11 @@ local filename = function(str)
return hash
end

local sha256 = function(str)
return vim.fn.sha256(str)
end

return {
simple = filename,
simple = simple,
sha256 = sha256,
}

0 comments on commit 4d7ae21

Please sign in to comment.