forked from microsoft/winget-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashCommand.cpp
More file actions
68 lines (58 loc) · 2.37 KB
/
Copy pathHashCommand.cpp
File metadata and controls
68 lines (58 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#include "pch.h"
#include "HashCommand.h"
#include "Workflows/WorkflowBase.h"
#include "Resources.h"
#include <AppInstallerMsixInfo.h>
namespace AppInstaller::CLI
{
using namespace std::string_view_literals;
using namespace Utility::literals;
std::vector<Argument> HashCommand::GetArguments() const
{
return {
Argument::ForType(Execution::Args::Type::HashFile),
Argument::ForType(Execution::Args::Type::Msix),
};
}
Resource::LocString HashCommand::ShortDescription() const
{
return { Resource::String::HashCommandShortDescription };
}
Resource::LocString HashCommand::LongDescription() const
{
return { Resource::String::HashCommandLongDescription };
}
Utility::LocIndView HashCommand::HelpLink() const
{
return "https://aka.ms/winget-command-hash"_liv;
}
void HashCommand::ExecuteInternal(Execution::Context& context) const
{
context <<
Workflow::VerifyFile(Execution::Args::Type::HashFile) <<
[](Execution::Context& context)
{
auto inputFile = context.Args.GetArg(Execution::Args::Type::HashFile);
std::ifstream inStream{ Utility::ConvertToUTF16(inputFile), std::ifstream::binary };
context.Reporter.Info() << "InstallerSha256: "_liv << Utility::LocIndString{ Utility::SHA256::ConvertToString(Utility::SHA256::ComputeHash(inStream)) } << std::endl;
if (context.Args.Contains(Execution::Args::Type::Msix))
{
try
{
Msix::MsixInfo msixInfo{ inputFile };
auto signatureHash = msixInfo.GetSignatureHash();
context.Reporter.Info() << "SignatureSha256: "_liv << Utility::LocIndString{ Utility::SHA256::ConvertToString(signatureHash) } << std::endl;
}
catch (const wil::ResultException& re)
{
context.Reporter.Warn() <<
Resource::String::MsixSignatureHashFailed << std::endl <<
Resource::String::VerifyFileSignedMsix << std::endl;
AICLI_TERMINATE_CONTEXT(re.GetErrorCode());
}
}
};
}
}