47 lines
1.5 KiB
Lua
47 lines
1.5 KiB
Lua
--[[
|
|
[[ User program to compute SHA-256 hashes of files for Halude
|
|
[[ Copyright (C) 2026 tema5002
|
|
[[
|
|
[[ This program is free software; you can redistribute it and/or
|
|
[[ modify it under the terms of the GNU General Public License
|
|
[[ as published by the Free Software Foundation; either version 2
|
|
[[ of the License, or (at your option) any later version.
|
|
[[
|
|
[[ This program is distributed in the hope that it will be useful,
|
|
[[ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
[[ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
[[ GNU General Public License for more details.
|
|
[[
|
|
[[ You should have received a copy of the GNU General Public License
|
|
[[ along with this program; If not, see <http://www.gnu.org/licenses/>.
|
|
]]--
|
|
|
|
local files = {...}
|
|
local sha256 = import("sha256")
|
|
local fs = import("filesystem")
|
|
if not files or not files[1] then
|
|
shell.run("help sha256sum")
|
|
return
|
|
end
|
|
|
|
for _, file in ipairs(files) do
|
|
if file:sub(1, 1) ~= "/" then
|
|
file = fs.concat(shell.workingDirectory, file)
|
|
end
|
|
if not fs.exists(file) then
|
|
print("\27[91mFile does not exist.")
|
|
goto continue
|
|
end
|
|
local handle = fs.open(file, "r")
|
|
local ctx = sha256.init()
|
|
while true do
|
|
local chunk = handle:read(256)
|
|
if not chunk then break end
|
|
sha256.update(ctx, chunk)
|
|
end
|
|
handle:close()
|
|
local hash_bytes = sha256.final(ctx)
|
|
termlib.write(sha256.to_hex(hash_bytes).." "..file.."\n")
|
|
::continue::
|
|
end
|