first commit

This commit is contained in:
2026-06-07 21:11:06 +03:00
commit 9d0f0f86ed
6 changed files with 736 additions and 0 deletions
+49
View File
@@ -0,0 +1,49 @@
--[[
[[ 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 fs = require("filesystem")
local shell = require("shell")
local args = {...}
if not files[1] then
return shell.run("help sha256sum")
end
local sha256 = require("sha256")
for _, file in ipairs(args) do
file = shell.resolvePath(file)
local handle = fs.open(file, "r")
if not handle then
print("\27[91msha256sum: can't open " .. file .. ".\27[0m")
goto continue
end
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