mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:07:35 +00:00
checksum: Use new format functions
This commit is contained in:
parent
7626f9e0bb
commit
d182f3224a
1 changed files with 6 additions and 7 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2020, Linus Groh <mail@linusgroh.de>
|
* Copyright (c) 2020-2021, Linus Groh <mail@linusgroh.de>
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
@ -27,7 +27,6 @@
|
||||||
#include <LibCore/ArgsParser.h>
|
#include <LibCore/ArgsParser.h>
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/File.h>
|
||||||
#include <LibCrypto/Hash/HashManager.h>
|
#include <LibCrypto/Hash/HashManager.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
|
@ -38,7 +37,7 @@ int main(int argc, char** argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
auto program_name = StringView { argv[0] };
|
auto program_name = StringView { argv[0] };
|
||||||
auto hash_kind { Crypto::Hash::HashKind::None };
|
auto hash_kind = Crypto::Hash::HashKind::None;
|
||||||
|
|
||||||
if (program_name == "md5sum")
|
if (program_name == "md5sum")
|
||||||
hash_kind = Crypto::Hash::HashKind::MD5;
|
hash_kind = Crypto::Hash::HashKind::MD5;
|
||||||
|
@ -50,7 +49,7 @@ int main(int argc, char** argv)
|
||||||
hash_kind = Crypto::Hash::HashKind::SHA512;
|
hash_kind = Crypto::Hash::HashKind::SHA512;
|
||||||
|
|
||||||
if (hash_kind == Crypto::Hash::HashKind::None) {
|
if (hash_kind == Crypto::Hash::HashKind::None) {
|
||||||
fprintf(stderr, "Error: program must be executed as 'md5sum', 'sha1sum', 'sha256sum' or 'sha512sum'; got '%s'\n", argv[0]);
|
warnln("Error: program must be executed as 'md5sum', 'sha1sum', 'sha256sum' or 'sha512sum'; got '{}'", argv[0]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +80,7 @@ int main(int argc, char** argv)
|
||||||
success = file->open(Core::IODevice::OpenMode::ReadOnly);
|
success = file->open(Core::IODevice::OpenMode::ReadOnly);
|
||||||
}
|
}
|
||||||
if (!success) {
|
if (!success) {
|
||||||
fprintf(stderr, "%s: %s: %s\n", argv[0], path, file->error_string());
|
warnln("{}: {}: {}", argv[0], path, file->error_string());
|
||||||
has_error = true;
|
has_error = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -92,9 +91,9 @@ int main(int argc, char** argv)
|
||||||
auto digest_data = digest.immutable_data();
|
auto digest_data = digest.immutable_data();
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
for (size_t i = 0; i < hash.digest_size(); ++i)
|
for (size_t i = 0; i < hash.digest_size(); ++i)
|
||||||
builder.appendf("%02x", digest_data[i]);
|
builder.appendff("{:02x}", digest_data[i]);
|
||||||
auto hash_sum_hex = builder.build();
|
auto hash_sum_hex = builder.build();
|
||||||
printf("%s %s\n", hash_sum_hex.characters(), path);
|
outln("{} {}", hash_sum_hex, path);
|
||||||
}
|
}
|
||||||
return has_error ? 1 : 0;
|
return has_error ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue