27
27
28
28
#include " action.h"
29
29
30
- #include " mip/mip_init.h"
31
30
#include " mip/common_types.h"
32
31
#include " mip/protection/protection_profile.h"
33
32
#include " mip/protection/protection_engine.h"
@@ -83,16 +82,22 @@ namespace sample {
83
82
84
83
void sample::file::Action::AddNewProtectionProfile ()
85
84
{
85
+
86
+
87
+ auto telemetryConfig = std::make_shared<mip::TelemetryConfiguration>();
88
+ telemetryConfig->isTelemetryOptedOut = true ;
89
+
86
90
// Create MipContext
87
91
mMipContext = mip::MipContext::Create (
88
92
mAppInfo ,
89
93
" mip_data" ,
90
94
mip::LogLevel::Trace,
91
95
false ,
92
96
nullptr /* loggerDelegateOverride*/ ,
93
- nullptr /* telemetryOverride*/
97
+ telemetryConfig /* telemetryOverride*/
94
98
);
95
99
100
+
96
101
// Initialize ProtectionProfileSettings using MipContext
97
102
ProtectionProfile::Settings profileSettings (mMipContext ,
98
103
mip::CacheStorageType::OnDiskEncrypted,
@@ -123,45 +128,40 @@ namespace sample {
123
128
mEngine = engineFuture.get ();
124
129
}
125
130
126
- std::shared_ptr<mip::ProtectionHandler> Action::CreateProtectionHandler (const ProtectionOptions protectionOptions )
131
+ std::shared_ptr<mip::ProtectionHandler> Action::CreateProtectionHandlerForPublishing (const std::shared_ptr<mip::ProtectionDescriptor>& descriptor )
127
132
{
128
133
auto handlerPromise = std::make_shared<std::promise<std::shared_ptr<ProtectionHandler>>>();
129
134
auto handlerFuture = handlerPromise->get_future ();
130
- auto descriptor = CreateProtectionDescriptor (protectionOptions);
131
- auto observer = std::make_shared<ProtectionHandlerObserverImpl>();
132
135
133
- mEngine ->CreateProtectionHandlerFromDescriptorAsync (descriptor,
134
- mip::ProtectionHandlerCreationOptions::None,
135
- observer,
136
- handlerPromise);
136
+ auto handlerObserver = std::make_shared<ProtectionHandlerObserverImpl>();
137
137
138
+ mip::ProtectionHandler::PublishingSettings publishingSettings = mip::ProtectionHandler::PublishingSettings (descriptor);
139
+ mEngine ->CreateProtectionHandlerForPublishingAsync (publishingSettings, handlerObserver, handlerPromise);
140
+
138
141
return handlerFuture.get ();
139
142
}
140
143
141
- std::shared_ptr<mip::ProtectionHandler> Action::CreateProtectionHandler (const std::vector<uint8_t >& serializedPublishingLicense) {
144
+ std::shared_ptr<mip::ProtectionHandler> Action::CreateProtectionHandlerForConsumption (const std::vector<uint8_t >& serializedPublishingLicense) {
142
145
// Note: Applications can optionally require user consent to acquire a protection handler by implementing the
143
146
// ConsentDelegate interfaces and passing the object when creating a ProtectionProfile
144
147
145
148
auto handlerPromise = std::make_shared<std::promise<std::shared_ptr<ProtectionHandler>>>();
146
149
auto handlerFuture = handlerPromise->get_future ();
147
- shared_ptr<ProtectionHandlerObserverImpl> handleObserver = std::make_shared<ProtectionHandlerObserverImpl>();
150
+ shared_ptr<ProtectionHandlerObserverImpl> handlerObserver = std::make_shared<ProtectionHandlerObserverImpl>();
148
151
152
+ mip::ProtectionHandler::ConsumptionSettings consumptionSettings = mip::ProtectionHandler::ConsumptionSettings (serializedPublishingLicense);
153
+ mEngine ->CreateProtectionHandlerForConsumptionAsync (consumptionSettings, handlerObserver, handlerPromise);
149
154
150
-
151
- mEngine ->CreateProtectionHandlerFromPublishingLicenseAsync (
152
- serializedPublishingLicense,
153
- mip::ProtectionHandlerCreationOptions::None,
154
- handleObserver,
155
- handlerPromise);
156
- return handlerFuture.get ();
155
+ auto h = handlerFuture.get ();
156
+ return h;
157
157
}
158
158
159
159
160
160
std::shared_ptr<mip::ProtectionDescriptor> Action::CreateProtectionDescriptor (const ProtectionOptions protectionOptions)
161
161
{
162
162
if (!protectionOptions.templateId .empty ())
163
163
{
164
- auto descriptorBuilder = mip::ProtectionDescriptorBuilder::CreateFromTemplate (protectionOptions.templateId );
164
+ auto descriptorBuilder = mip::ProtectionDescriptorBuilder::CreateFromTemplate (protectionOptions.templateId );
165
165
return descriptorBuilder->Build ();
166
166
}
167
167
return nullptr ;
@@ -191,13 +191,18 @@ namespace sample {
191
191
}
192
192
}
193
193
194
- void Action::ProtectString (const std::string& plaintext, std::string& ciphertext, const std::vector< uint8_t >& serializedLicense )
194
+ std::vector< uint8_t > Action::ProtectString (const std::string& plaintext, std::string& ciphertext, const std::string& templateId )
195
195
{
196
196
if (!mEngine ) {
197
197
AddNewProtectionEngine ();
198
198
}
199
199
200
- auto handler = CreateProtectionHandler (serializedLicense);
200
+ ProtectionOptions protectionOptions;
201
+ protectionOptions.templateId = templateId;
202
+
203
+ auto descriptor = CreateProtectionDescriptor (protectionOptions);
204
+
205
+ auto handler = CreateProtectionHandlerForPublishing (descriptor);
201
206
std::vector<uint8_t > outputBuffer;
202
207
// std::vector<uint8_t> inputBuffer(static_cast<size_t>(plaintext.size()));
203
208
std::vector<uint8_t > inputBuffer (plaintext.begin (), plaintext.end ());
@@ -213,6 +218,8 @@ namespace sample {
213
218
214
219
std::string output (outputBuffer.begin (), outputBuffer.end ());
215
220
ciphertext = output;
221
+
222
+ return handler->GetSerializedPublishingLicense ();
216
223
}
217
224
218
225
void Action::DecryptString (std::string& plaintext, const std::string& ciphertext, const std::vector<uint8_t >& serializedLicense)
@@ -221,7 +228,7 @@ namespace sample {
221
228
AddNewProtectionEngine ();
222
229
}
223
230
224
- auto handler = CreateProtectionHandler (serializedLicense);
231
+ auto handler = CreateProtectionHandlerForConsumption (serializedLicense);
225
232
std::vector<uint8_t > outputBuffer (static_cast <size_t >(ciphertext.size ()));
226
233
227
234
@@ -240,18 +247,5 @@ namespace sample {
240
247
std::string output (outputBuffer.begin (), outputBuffer.end ());
241
248
plaintext = output;
242
249
}
243
-
244
- std::vector<uint8_t > Action::GetPublishingLicense (const std::string& templateId)
245
- {
246
- if (!mEngine ) {
247
- AddNewProtectionEngine ();
248
- }
249
-
250
- ProtectionOptions protectionOptions;
251
- protectionOptions.templateId = templateId;
252
-
253
- auto handler = CreateProtectionHandler (protectionOptions);
254
- return handler->GetSerializedPublishingLicense ();
255
- }
256
250
}
257
251
}
0 commit comments