From da507f8607abf6c58b7773bba6bffcc2d7b8e014 Mon Sep 17 00:00:00 2001 From: Frans de Jonge Date: Tue, 21 Jul 2020 23:25:46 +0200 Subject: [PATCH] [chore] Update MD5 calls with new sha2 library (#6411) Depends on . --- base | 2 +- frontend/cache.lua | 6 +++--- frontend/document/document.lua | 8 ++++---- plugins/evernote.koplugin/clip.lua | 4 ++-- plugins/kosync.koplugin/main.lua | 6 +++--- plugins/statistics.koplugin/main.lua | 8 ++++---- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/base b/base index 19a87bbc1..fac6e7c85 160000 --- a/base +++ b/base @@ -1 +1 @@ -Subproject commit 19a87bbc1019f413976758287e9b754667a505e0 +Subproject commit fac6e7c85250b138a5603f54fc3427d62c141420 diff --git a/frontend/cache.lua b/frontend/cache.lua index 129c82be5..01f95c4a9 100644 --- a/frontend/cache.lua +++ b/frontend/cache.lua @@ -5,7 +5,7 @@ A global LRU cache local DataStorage = require("datastorage") local lfs = require("libs/libkoreader-lfs") local logger = require("logger") -local md5 = require("ffi/MD5") +local md5 = require("ffi/sha2").md5 local CanvasContext = require("document/canvascontext") if CanvasContext.should_restrict_JIT then @@ -129,7 +129,7 @@ function Cache:check(key, ItemClass) end return self.cache[key] elseif ItemClass then - local cached = self.cached[md5.sum(key)] + local cached = self.cached[md5(key)] if cached then local item = ItemClass:new{} local ok, msg = pcall(item.load, item, cached) @@ -166,7 +166,7 @@ function Cache:serialize() -- only dump cache item that requests serialization explicitly if cache_item.persistent and cache_item.dump then - local cache_full_path = cache_path..md5.sum(key) + local cache_full_path = cache_path..md5(key) local cache_file_exists = lfs.attributes(cache_full_path) if cache_file_exists then break end diff --git a/frontend/document/document.lua b/frontend/document/document.lua index 5d300f769..931700a5f 100644 --- a/frontend/document/document.lua +++ b/frontend/document/document.lua @@ -135,20 +135,20 @@ function Document:fastDigest(docsettings) if not result then logger.dbg("computing and storing partial_md5_checksum") local bit = require("bit") - local md5 = require("ffi/MD5") + local md5 = require("ffi/sha2").md5 local lshift = bit.lshift local step, size = 1024, 1024 - local m = md5.new() + local update = md5() for i = -1, 10 do file:seek("set", lshift(step, 2*i)) local sample = file:read(size) if sample then - m:update(sample) + update(sample) else break end end - result = m:sum() + result = update() docsettings:saveSetting("partial_md5_checksum", result) end if tmp_docsettings then diff --git a/plugins/evernote.koplugin/clip.lua b/plugins/evernote.koplugin/clip.lua index 755923f52..2d40c1270 100644 --- a/plugins/evernote.koplugin/clip.lua +++ b/plugins/evernote.koplugin/clip.lua @@ -2,7 +2,7 @@ local DocumentRegistry = require("document/documentregistry") local DocSettings = require("docsettings") local ReadHistory = require("readhistory") local logger = require("logger") -local md5 = require("ffi/MD5") +local md5 = require("ffi/sha2").md5 local util = require("util") local MyClipping = { @@ -222,7 +222,7 @@ function MyClipping:getImage(image) --doc:clipPagePNGFile(image.pos0, image.pos1, --image.pboxes, image.drawer, "/tmp/"..md5(png)..".png") doc:close() - if png then return { png = png, hash = md5.sum(png) } end + if png then return { png = png, hash = md5(png) } end end end diff --git a/plugins/kosync.koplugin/main.lua b/plugins/kosync.koplugin/main.lua index e58a456c4..a4e354e87 100644 --- a/plugins/kosync.koplugin/main.lua +++ b/plugins/kosync.koplugin/main.lua @@ -9,7 +9,7 @@ local Event = require("ui/event") local Math = require("optmath") local Screen = Device.screen local logger = require("logger") -local md5 = require("ffi/MD5") +local md5 = require("ffi/sha2").md5 local random = require("random") local T = require("ffi/util").template local _ = require("gettext") @@ -386,7 +386,7 @@ function KOSync:doRegister(username, password) } -- on Android to avoid ANR (no-op on other platforms) Device:setIgnoreInput(true) - local userkey = md5.sum(password) + local userkey = md5(password) local ok, status, body = pcall(client.register, client, username, userkey) if not ok then if status then @@ -422,7 +422,7 @@ function KOSync:doLogin(username, password) service_spec = self.path .. "/api.json" } Device:setIgnoreInput(true) - local userkey = md5.sum(password) + local userkey = md5(password) local ok, status, body = pcall(client.authorize, client, username, userkey) if not ok then if status then diff --git a/plugins/statistics.koplugin/main.lua b/plugins/statistics.koplugin/main.lua index c70c918bd..cca4c1441 100644 --- a/plugins/statistics.koplugin/main.lua +++ b/plugins/statistics.koplugin/main.lua @@ -288,21 +288,21 @@ function ReaderStatistics:partialMd5(file) return nil end local bit = require("bit") - local md5 = require("ffi/MD5") + local md5 = require("ffi/sha2").md5 local lshift = bit.lshift local step, size = 1024, 1024 - local m = md5.new() + local update = md5() local file_handle = io.open(file, 'rb') for i = -1, 10 do file_handle:seek("set", lshift(step, 2*i)) local sample = file_handle:read(size) if sample then - m:update(sample) + update(sample) else break end end - return m:sum() + return update() end function ReaderStatistics:createDB(conn)