Skip to content

Commit d2983f2

Browse files
Tom MoserCopilot
authored andcommitted
Clarify sample comments for protection flow
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 687f378 commit d2983f2

4 files changed

Lines changed: 17 additions & 28 deletions

File tree

mipsdk-protectionapi-cpp-sample-basic/action.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ using mip::ProtectionHandler;
6262
namespace sample {
6363
namespace protection {
6464

65-
// Constructor accepts mip::ApplicationInfo object and uses it to initialize AuthDelegateImpl.
66-
// Specifically, AuthDelegateInfo uses mAppInfo.ApplicationId for AAD client_id value.
65+
// Constructor accepts mip::ApplicationInfo and uses it to initialize AuthDelegateImpl.
66+
// AuthDelegateImpl forwards mAppInfo.applicationId as the Microsoft Entra client ID.
6767
Action::Action(const mip::ApplicationInfo appInfo,
6868
const std::string& username)
6969
: mAppInfo(appInfo),
@@ -169,19 +169,18 @@ namespace sample {
169169
}
170170

171171

172-
// Function recursively lists all labels available for a user to std::cout.
172+
// List all protection templates available to the current user.
173173
void Action::ListTemplates() {
174174

175-
// If mEngine hasn't been set, call AddNewFileEngine() to load the engine.
175+
// If mEngine has not been set, call AddNewProtectionEngine() to load it.
176176
if (!mEngine) {
177177
AddNewProtectionEngine();
178178
}
179179

180180
const shared_ptr<ProtectionEngineObserverImpl> engineObserver = std::make_shared<ProtectionEngineObserverImpl>();
181181

182-
// Create a context to pass to 'ProtectionEngine::GetTemplateListAsync'. That context will be forwarded to the
183-
// corresponding ProtectionEngine::Observer methods. In this case, we use promises/futures as a simple way to detect
184-
// the async operation completes synchronously.
182+
// Create context for GetTemplatesAsync. The observer receives this same context, and
183+
// promises/futures let the sample block until the async call completes.
185184
auto loadPromise = std::make_shared<std::promise<vector<shared_ptr<mip::TemplateDescriptor>>>>();
186185
std::future<vector<shared_ptr<mip::TemplateDescriptor>>> loadFuture = loadPromise->get_future();
187186
mEngine->GetTemplatesAsync(engineObserver, loadPromise);
@@ -205,7 +204,6 @@ namespace sample {
205204

206205
auto handler = CreateProtectionHandlerForPublishing(descriptor);
207206
std::vector<uint8_t> outputBuffer;
208-
// std::vector<uint8_t> inputBuffer(static_cast<size_t>(plaintext.size()));
209207
std::vector<uint8_t> inputBuffer(plaintext.begin(), plaintext.end());
210208

211209
outputBuffer.resize(static_cast<size_t>(handler->GetProtectedContentLength(plaintext.size(), true)));
@@ -232,8 +230,6 @@ namespace sample {
232230
auto handler = CreateProtectionHandlerForConsumption(serializedLicense);
233231
std::vector<uint8_t> outputBuffer(static_cast<size_t>(ciphertext.size()));
234232

235-
236-
// std::vector<uint8_t> inputBuffer(static_cast<size_t>(plaintext.size()));
237233
std::vector<uint8_t> inputBuffer(ciphertext.begin(), ciphertext.end());
238234

239235
int64_t decryptedSize = handler->DecryptBuffer(

mipsdk-protectionapi-cpp-sample-basic/consent_delegate_impl.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace sample {
3737
namespace consent {
3838

3939
Consent ConsentDelegateImpl::GetUserConsent(const string& url) {
40-
// Accept the consent to connect to the url
40+
// This sample runs non-interactively and accepts SDK consent prompts by default.
4141
std::cout << "This is the consent delegate." << std::endl << std::endl;
4242

4343
std::cout << "SDK will connect to: " << url << std::endl;
@@ -47,8 +47,7 @@ Consent ConsentDelegateImpl::GetUserConsent(const string& url) {
4747
std::cout << "3) Reject" << std::endl;
4848
std::cout << "Select an option: ";
4949
char input;
50-
// std::cin >> input;
51-
input = 1;
50+
input = '2';
5251

5352
switch (input)
5453
{

mipsdk-protectionapi-cpp-sample-basic/main.cpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ int RunSample(int argc, char* argv[])
6161
}
6262
}
6363

64-
// local variables to store target file and the label that will be applied to the file.
64+
// Local variables for template selection and plaintext/ciphertext flow.
6565

6666
string templateToApply;
6767
string plaintext;
@@ -79,21 +79,19 @@ int RunSample(int argc, char* argv[])
7979
// Friendly Name should be the name of the application as it should appear in reports.
8080
mip::ApplicationInfo appInfo{ clientId, "MIP SDK Protection Sample for C++", "1.18.0" };
8181

82-
// All actions for this tutorial project are implemented in samples::policy::Action
83-
// Source files are Action.h/cpp.
84-
// Action's constructor takes in the mip::ApplicationInfo object and uses the client ID for auth.
82+
// Sample operations are implemented in sample::protection::Action (Action.h/cpp).
83+
// Action's constructor accepts app metadata and the username used for authentication.
8584
Action action = Action(appInfo, userName);
8685

8786
while (true)
8887
{
8988
templateToApply = "";
9089

91-
// Call action.ListLabels() to display all available labels, then pause.
90+
// Display all available protection templates.
9291
cout << "*** Template List: " << endl;
9392
action.ListTemplates();
9493

95-
// Prompt the user to copy the Label ID from a displayed label. This will be stored
96-
// then applied later to a file.
94+
// Prompt for a template ID from the list.
9795
cout << "Copy a template ID from above to apply to a new string or q to quit." << endl;
9896
cout << endl << "Template ID: ";
9997
cin >> templateToApply;
@@ -103,15 +101,12 @@ int RunSample(int argc, char* argv[])
103101
return 0;
104102
}
105103

106-
// Generate a new protection descriptor and store publishing license
107-
108-
109-
// Prompt the user to enter a file. A labeled copy of this file will be created.
104+
// Prompt for plaintext to encrypt.
110105
cout << "Enter some text to encrypt: ";
111106
std::getline(std::cin >> std::ws, plaintext);
112107

113-
// Show action plan
114-
cout << "Applying Label ID " + templateToApply + " to: " << endl << plaintext << endl;
108+
// Show selected template and input text.
109+
cout << "Applying template ID " + templateToApply + " to: " << endl << plaintext << endl;
115110

116111
// Protect the input string using the previously generated PL.
117112
auto publishingLicense = action.ProtectString(plaintext, ciphertext, templateToApply);

mipsdk-protectionapi-cpp-sample-basic/protection_observers.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ using std::vector;
1515
using std::string;
1616
using std::exception_ptr;
1717

18-
// Protection Profile Observers
18+
// Observer callbacks that bridge MIP async APIs to std::promise/std::future.
1919
void ProtectionProfileObserverImpl::OnLoadSuccess(
2020
const shared_ptr<mip::ProtectionProfile>& profile,
2121
const shared_ptr<void>& context) {
@@ -67,4 +67,3 @@ void ProtectionEngineObserverImpl::OnGetTemplatesFailure(const exception_ptr& Fa
6767
auto loadPromise = static_cast<promise<vector<shared_ptr<mip::TemplateDescriptor>>>*>(context.get());
6868
loadPromise->set_exception(Failure);
6969
};
70-

0 commit comments

Comments
 (0)