aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/src/commands_hash.cpp
diff options
context:
space:
mode:
authorJan HrubĂ˝ <jhruby.web@gmail.com>2017-03-13 08:56:05 +0100
committerGitHub <noreply@github.com>2017-03-13 08:56:05 +0100
commit665f4118f603c5858217ed7a2f2f824b18ff4fc5 (patch)
treef0167041edf71e90f2331b5025f603392a8de67a /toolsrc/src/commands_hash.cpp
parent1bec0fcb73073b5b1719f454c368a63f1bff625e (diff)
parent1c9873a0daf625f67474aaf3e163c592c27ecb65 (diff)
downloadvcpkg-665f4118f603c5858217ed7a2f2f824b18ff4fc5.tar.gz
vcpkg-665f4118f603c5858217ed7a2f2f824b18ff4fc5.zip
Merge pull request #1 from Microsoft/master
pull
Diffstat (limited to 'toolsrc/src/commands_hash.cpp')
-rw-r--r--toolsrc/src/commands_hash.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/toolsrc/src/commands_hash.cpp b/toolsrc/src/commands_hash.cpp
new file mode 100644
index 000000000..805da4153
--- /dev/null
+++ b/toolsrc/src/commands_hash.cpp
@@ -0,0 +1,46 @@
+#include "pch.h"
+#include "vcpkg_Commands.h"
+#include "vcpkg_System.h"
+
+namespace vcpkg::Commands::Hash
+{
+ static void do_file_hash(fs::path const& path, std::wstring const& hashType)
+ {
+ auto cmd_line = Strings::wformat(LR"(CertUtil.exe -hashfile "%s" %s)",
+ path.c_str(), hashType.c_str());
+ auto ec_data = System::cmd_execute_and_capture_output(cmd_line);
+ Checks::check_exit(ec_data.exit_code == 0, "Running command:\n %s\n failed", Strings::utf16_to_utf8(cmd_line));
+
+ std::string const& output = ec_data.output;
+
+ auto start = output.find_first_of("\r\n");
+ Checks::check_exit(start != std::string::npos, "Unexpected output format from command: %s", Strings::utf16_to_utf8(cmd_line));
+
+ auto end = output.find_first_of("\r\n", start + 1);
+ Checks::check_exit(end != std::string::npos, "Unexpected output format from command: %s", Strings::utf16_to_utf8(cmd_line));
+
+ auto hash = output.substr(start, end - start);
+ hash.erase(std::remove_if(hash.begin(), hash.end(), isspace), hash.end());
+ System::println(hash);
+ }
+
+ void perform_and_exit(const vcpkg_cmd_arguments& args)
+ {
+ static const std::string example = Strings::format(
+ "The argument should be a file path\n%s", Commands::Help::create_example_string("hash boost_1_62_0.tar.bz2"));
+ args.check_min_arg_count(1, example);
+ args.check_max_arg_count(2, example);
+ args.check_and_get_optional_command_arguments({});
+
+ if (args.command_arguments.size() == 1)
+ {
+ do_file_hash(args.command_arguments[0], L"SHA512");
+ }
+ if (args.command_arguments.size() == 2)
+ {
+ do_file_hash(args.command_arguments[0], Strings::utf8_to_utf16(args.command_arguments[1]));
+ }
+
+ exit(EXIT_SUCCESS);
+ }
+}