diff --git a/ChangeLog.md b/ChangeLog.md index 96c681f..0ad32fb 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,6 +1,6 @@ # ChangeLog for sha256 -## Version NEXT (2022-11-??) +## Version 1.5 (2022-11-12) - An error in the program's help text is fixed. - The minimum required CMake version to build the program is raised to CMake 3.8. diff --git a/sha256/main.cpp b/sha256/main.cpp index 7231198..f211379 100644 --- a/sha256/main.cpp +++ b/sha256/main.cpp @@ -64,7 +64,7 @@ void showGPLNotice() void showVersion() { showGPLNotice(); - std::cout << "SHA-256 file hash calculator, version 1.4, 2015-08-06\n"; + std::cout << "SHA-256 file hash calculator, version 1.5, 2022-11-12\n"; } void showHelp() @@ -72,18 +72,18 @@ void showHelp() std::cout << "\nsha256 [--sha1 | --sha224 | --sha256 | --sha384 | --sha512] FILENAME\n" << "\n" << "options:\n" - << " --help - displays this help message and quits\n" + << " --help - Displays this help message and quits.\n" << " -? - same as --help\n" - << " --version - displays the version of the program and quits\n" + << " --version - Displays the version of the program and quits.\n" << " -v - same as --version\n" - << " FILENAME - set path to file that should be hashed. Can be repeated\n" + << " FILENAME - Set path to file that should be hashed. Can be repeated\n" << " multiple times. Has to appear at least once.\n" - << " --sha1 - use SHA-1 instead of SHA-256 to hash files.\n" - << " --sha224 - use SHA-224 instead of SHA-256 to hash files.\n" - << " --sha256 - use SHA-256 to hash files. This option is active by\n" + << " --sha1 - Use SHA-1 instead of SHA-256 to hash files.\n" + << " --sha224 - Use SHA-224 instead of SHA-256 to hash files.\n" + << " --sha256 - Use SHA-256 to hash files. This option is active by\n" << " default.\n" - << " --sha384 - use SHA-384 instead of SHA-256 to hash files.\n" - << " --sha512 - use SHA-512 instead of SHA-256 to hash files.\n"; + << " --sha384 - Use SHA-384 instead of SHA-256 to hash files.\n" + << " --sha512 - Use SHA-512 instead of SHA-256 to hash files.\n"; } int main(int argc, char **argv) @@ -94,180 +94,178 @@ int main(int argc, char **argv) SHAHashType hashType = htUnspecified; - if ((argc>1) and (argv!=NULL)) + if ((argc > 1) && (argv != nullptr)) { - int i=1; - while (i::const_iterator iter = files.begin(); SHA512::MessageDigest hash512; SHA384::MessageDigest hash384; SHA256::MessageDigest hash256; SHA224::MessageDigest hash224; SHA1::MessageDigest hash160; - while (iter!=files.end()) + for (const auto& item: files) { switch (hashType) { case htSHA1: - hash160 = SHA1::computeFromFile(*iter); - std::cout << hash160.toHexString() << " " << *iter << std::endl; + hash160 = SHA1::computeFromFile(item); + std::cout << hash160.toHexString() << " " << item << std::endl; break; case htSHA224: - hash224 = SHA224::computeFromFile(*iter); - std::cout << hash224.toHexString() << " " << *iter << std::endl; + hash224 = SHA224::computeFromFile(item); + std::cout << hash224.toHexString() << " " << item << std::endl; break; case htSHA384: - hash384 = SHA384::computeFromFile(*iter); - std::cout << hash384.toHexString() << " " << *iter << std::endl; + hash384 = SHA384::computeFromFile(item); + std::cout << hash384.toHexString() << " " << item << std::endl; break; case htSHA512: - hash512 = SHA512::computeFromFile(*iter); - std::cout << hash512.toHexString() << " " << *iter << std::endl; + hash512 = SHA512::computeFromFile(item); + std::cout << hash512.toHexString() << " " << item << std::endl; break; default: - hash256 = SHA256::computeFromFile(*iter); - std::cout << hash256.toHexString() << " " << *iter << std::endl; + hash256 = SHA256::computeFromFile(item); + std::cout << hash256.toHexString() << " " << item << std::endl; break; - }//swi - ++iter; - }//while + } + } return 0; } diff --git a/sha256/sha256.cbp b/sha256/sha256.cbp index de16a4f..f217fbe 100644 --- a/sha256/sha256.cbp +++ b/sha256/sha256.cbp @@ -30,8 +30,8 @@ - + @@ -74,9 +74,6 @@ - - - diff --git a/tests/sha160/secure-hashing-examples/main.cpp b/tests/sha160/secure-hashing-examples/main.cpp index de6c928..d36c700 100644 --- a/tests/sha160/secure-hashing-examples/main.cpp +++ b/tests/sha160/secure-hashing-examples/main.cpp @@ -49,7 +49,7 @@ int main() //next statement contains a nasty typecast const SHA1::MessageDigest md_sha1 = SHA1::computeFromBuffer( reinterpret_cast(const_cast(i.first.c_str())), - i.first.size()*8); + i.first.size() * 8); std::cout << "Message:" << std::endl << i.first << std::endl << "Expected digest: " << i.second << std::endl @@ -59,7 +59,7 @@ int main() std::cout << "ERROR: Message digest is not as expected!" << std::endl; return 1; } - } //for + } std::cout << "Passed test!" << std::endl; return 0; } diff --git a/tests/sha224/secure-hashing-examples/main.cpp b/tests/sha224/secure-hashing-examples/main.cpp index a6833a3..a07007e 100644 --- a/tests/sha224/secure-hashing-examples/main.cpp +++ b/tests/sha224/secure-hashing-examples/main.cpp @@ -49,7 +49,7 @@ int main() //next statement contains a nasty typecast const SHA224::MessageDigest md_sha224 = SHA224::computeFromBuffer( reinterpret_cast(const_cast(i.first.c_str())), - i.first.size()*8); + i.first.size() * 8); std::cout << "Message:" << std::endl << i.first << std::endl << "Expected digest: " << i.second << std::endl @@ -59,7 +59,7 @@ int main() std::cout << "ERROR: Message digest is not as expected!" << std::endl; return 1; } - } //for + } std::cout << "Passed test!" << std::endl; return 0; } diff --git a/tests/sha256/secure-hashing-examples/main.cpp b/tests/sha256/secure-hashing-examples/main.cpp index 56cfe4e..d625971 100644 --- a/tests/sha256/secure-hashing-examples/main.cpp +++ b/tests/sha256/secure-hashing-examples/main.cpp @@ -48,7 +48,7 @@ int main() //next statement contains a nasty typecast const SHA256::MessageDigest md_sha256 = SHA256::computeFromBuffer( reinterpret_cast(const_cast(i.first.c_str())), - i.first.size()*8); + i.first.size() * 8); std::cout << "Message:" << std::endl << i.first << std::endl << "Expected digest: " << i.second << std::endl @@ -58,7 +58,7 @@ int main() std::cout << "ERROR: Message digest is not as expected!" << std::endl; return 1; } - } //for + } std::cout << "Passed test!" << std::endl; return 0; } diff --git a/tests/sha384/secure-hashing-examples/main.cpp b/tests/sha384/secure-hashing-examples/main.cpp index bc6bff9..cc36785 100644 --- a/tests/sha384/secure-hashing-examples/main.cpp +++ b/tests/sha384/secure-hashing-examples/main.cpp @@ -49,7 +49,7 @@ int main() //next statement contains a nasty typecast const SHA384::MessageDigest md_sha384 = SHA384::computeFromBuffer( reinterpret_cast(const_cast(i.first.c_str())), - i.first.size()*8); + i.first.size() * 8); std::cout << "Message:" << std::endl << i.first << std::endl << "Expected digest: " << i.second << std::endl @@ -59,7 +59,7 @@ int main() std::cout << "ERROR: Message digest is not as expected!" << std::endl; return 1; } - } //for + } std::cout << "Passed test!" << std::endl; return 0; } diff --git a/tests/sha512/secure-hashing-examples/main.cpp b/tests/sha512/secure-hashing-examples/main.cpp index 84677d0..a6718a7 100644 --- a/tests/sha512/secure-hashing-examples/main.cpp +++ b/tests/sha512/secure-hashing-examples/main.cpp @@ -48,7 +48,7 @@ int main() //next statement contains a nasty cast const SHA512::MessageDigest md_sha512 = SHA512::computeFromBuffer( reinterpret_cast(const_cast(i.first.c_str())), - i.first.size()*8); + i.first.size() * 8); std::cout << "Message:" << std::endl << i.first << std::endl << "Expected digest: " << i.second << std::endl @@ -58,7 +58,7 @@ int main() std::cout << "ERROR: Message digest is not as expected!" << std::endl; return 1; } - } //for + } std::cout << "Passed test!" << std::endl; return 0; }