2727
2828#include " action.h"
2929
30- #include " mip/mip_init.h"
3130#include " mip/common_types.h"
3231#include " mip/protection/protection_profile.h"
3332#include " mip/protection/protection_engine.h"
@@ -83,16 +82,22 @@ namespace sample {
8382
8483 void sample::file::Action::AddNewProtectionProfile ()
8584 {
85+
86+
87+ auto telemetryConfig = std::make_shared<mip::TelemetryConfiguration>();
88+ telemetryConfig->isTelemetryOptedOut = true ;
89+
8690 // Create MipContext
8791 mMipContext = mip::MipContext::Create (
8892 mAppInfo ,
8993 " mip_data" ,
9094 mip::LogLevel::Trace,
9195 false ,
9296 nullptr /* loggerDelegateOverride*/ ,
93- nullptr /* telemetryOverride*/
97+ telemetryConfig /* telemetryOverride*/
9498 );
9599
100+
96101 // Initialize ProtectionProfileSettings using MipContext
97102 ProtectionProfile::Settings profileSettings (mMipContext ,
98103 mip::CacheStorageType::OnDiskEncrypted,
@@ -123,45 +128,40 @@ namespace sample {
123128 mEngine = engineFuture.get ();
124129 }
125130
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 )
127132 {
128133 auto handlerPromise = std::make_shared<std::promise<std::shared_ptr<ProtectionHandler>>>();
129134 auto handlerFuture = handlerPromise->get_future ();
130- auto descriptor = CreateProtectionDescriptor (protectionOptions);
131- auto observer = std::make_shared<ProtectionHandlerObserverImpl>();
132135
133- mEngine ->CreateProtectionHandlerFromDescriptorAsync (descriptor,
134- mip::ProtectionHandlerCreationOptions::None,
135- observer,
136- handlerPromise);
136+ auto handlerObserver = std::make_shared<ProtectionHandlerObserverImpl>();
137137
138+ mip::ProtectionHandler::PublishingSettings publishingSettings = mip::ProtectionHandler::PublishingSettings (descriptor);
139+ mEngine ->CreateProtectionHandlerForPublishingAsync (publishingSettings, handlerObserver, handlerPromise);
140+
138141 return handlerFuture.get ();
139142 }
140143
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) {
142145 // Note: Applications can optionally require user consent to acquire a protection handler by implementing the
143146 // ConsentDelegate interfaces and passing the object when creating a ProtectionProfile
144147
145148 auto handlerPromise = std::make_shared<std::promise<std::shared_ptr<ProtectionHandler>>>();
146149 auto handlerFuture = handlerPromise->get_future ();
147- shared_ptr<ProtectionHandlerObserverImpl> handleObserver = std::make_shared<ProtectionHandlerObserverImpl>();
150+ shared_ptr<ProtectionHandlerObserverImpl> handlerObserver = std::make_shared<ProtectionHandlerObserverImpl>();
148151
152+ mip::ProtectionHandler::ConsumptionSettings consumptionSettings = mip::ProtectionHandler::ConsumptionSettings (serializedPublishingLicense);
153+ mEngine ->CreateProtectionHandlerForConsumptionAsync (consumptionSettings, handlerObserver, handlerPromise);
149154
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;
157157 }
158158
159159
160160 std::shared_ptr<mip::ProtectionDescriptor> Action::CreateProtectionDescriptor (const ProtectionOptions protectionOptions)
161161 {
162162 if (!protectionOptions.templateId .empty ())
163163 {
164- auto descriptorBuilder = mip::ProtectionDescriptorBuilder::CreateFromTemplate (protectionOptions.templateId );
164+ auto descriptorBuilder = mip::ProtectionDescriptorBuilder::CreateFromTemplate (protectionOptions.templateId );
165165 return descriptorBuilder->Build ();
166166 }
167167 return nullptr ;
@@ -191,13 +191,18 @@ namespace sample {
191191 }
192192 }
193193
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 )
195195 {
196196 if (!mEngine ) {
197197 AddNewProtectionEngine ();
198198 }
199199
200- auto handler = CreateProtectionHandler (serializedLicense);
200+ ProtectionOptions protectionOptions;
201+ protectionOptions.templateId = templateId;
202+
203+ auto descriptor = CreateProtectionDescriptor (protectionOptions);
204+
205+ auto handler = CreateProtectionHandlerForPublishing (descriptor);
201206 std::vector<uint8_t > outputBuffer;
202207 // std::vector<uint8_t> inputBuffer(static_cast<size_t>(plaintext.size()));
203208 std::vector<uint8_t > inputBuffer (plaintext.begin (), plaintext.end ());
@@ -213,6 +218,8 @@ namespace sample {
213218
214219 std::string output (outputBuffer.begin (), outputBuffer.end ());
215220 ciphertext = output;
221+
222+ return handler->GetSerializedPublishingLicense ();
216223 }
217224
218225 void Action::DecryptString (std::string& plaintext, const std::string& ciphertext, const std::vector<uint8_t >& serializedLicense)
@@ -221,7 +228,7 @@ namespace sample {
221228 AddNewProtectionEngine ();
222229 }
223230
224- auto handler = CreateProtectionHandler (serializedLicense);
231+ auto handler = CreateProtectionHandlerForConsumption (serializedLicense);
225232 std::vector<uint8_t > outputBuffer (static_cast <size_t >(ciphertext.size ()));
226233
227234
@@ -240,18 +247,5 @@ namespace sample {
240247 std::string output (outputBuffer.begin (), outputBuffer.end ());
241248 plaintext = output;
242249 }
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- }
256250 }
257251}
0 commit comments