2024-07-20 13:50:59 +00:00
|
|
|
#include <luna/SHA.h>
|
|
|
|
#include <os/ArgumentParser.h>
|
|
|
|
#include <os/File.h>
|
|
|
|
|
|
|
|
Result<int> luna_main(int argc, char** argv)
|
|
|
|
{
|
|
|
|
Vector<StringView> files;
|
|
|
|
|
|
|
|
os::ArgumentParser parser;
|
|
|
|
parser.add_description("Calculate SHA256 hashes for a series of files."_sv);
|
|
|
|
parser.add_system_program_info("sha256sum"_sv);
|
|
|
|
parser.set_vector_argument(files, "files"_sv, "-"_sv);
|
|
|
|
parser.parse(argc, argv);
|
|
|
|
|
|
|
|
for (auto path : files)
|
|
|
|
{
|
|
|
|
auto file = TRY(os::File::open_input_file(path));
|
|
|
|
auto data = TRY(file->read_all());
|
|
|
|
|
|
|
|
SHA256 sha;
|
|
|
|
|
|
|
|
TRY(sha.append(data.data(), data.size()));
|
2024-07-20 14:12:43 +00:00
|
|
|
auto digest = TRY(sha.digest());
|
|
|
|
auto string = TRY(digest.to_string());
|
2024-07-20 13:50:59 +00:00
|
|
|
|
|
|
|
os::println("%s %s", string.chars(), path.chars());
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|