Microsoft Information Protection SDK - C++ 1.17
API Reference Documentation for C++
Loading...
Searching...
No Matches
file_handler.h
Go to the documentation of this file.
1/*
2 *
3 * Copyright (c) Microsoft Corporation.
4 * All rights reserved.
5 *
6 * This code is licensed under the MIT License.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files(the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions :
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 * THE SOFTWARE.
25 *
26 */
27
28#ifndef API_MIP_FILE_FILE_HANDLER_H_
29#define API_MIP_FILE_FILE_HANDLER_H_
30
31#include <memory>
32
38#include "mip/mip_context.h"
39#include "mip/mip_namespace.h"
42#include "mip/stream.h"
43#include "mip/upe/action.h"
46
47MIP_NAMESPACE_BEGIN
48
53public:
54
61 class Observer {
62 public:
64 virtual ~Observer() {}
71 const std::shared_ptr<FileHandler>& fileHandler,
72 const std::shared_ptr<void>& context) { UNUSED(fileHandler); UNUSED(context); }
73
78 const std::exception_ptr& error,
79 const std::shared_ptr<void>& context) { UNUSED(error); UNUSED(context); }
80
84 virtual void OnClassifySuccess(
85 const std::vector<std::shared_ptr<Action>>& actions, const std::shared_ptr<void>& context) {
86 UNUSED(actions);
87 UNUSED(context);
88 }
89
93 virtual void OnClassifyFailure(const std::exception_ptr& error, const std::shared_ptr<void>& context) {
94 UNUSED(error);
95 UNUSED(context);
96 }
97
102 const std::string& decryptedFilePath, const std::shared_ptr<void>& context) {
103 UNUSED(decryptedFilePath);
104 UNUSED(context);
105 }
106
110 virtual void OnGetDecryptedTemporaryFileFailure(const std::exception_ptr& error, const std::shared_ptr<void>& context) {
111 UNUSED(error);
112 UNUSED(context);
113 }
114
119 const std::shared_ptr<Stream>& decryptedStream, const std::shared_ptr<void>& context) {
120 UNUSED(decryptedStream);
121 UNUSED(context);
122 }
123
128 const std::exception_ptr& error, const std::shared_ptr<void>& context) {
129 UNUSED(error);
130 UNUSED(context);
131 }
132
136 virtual void OnCommitSuccess(
137 bool committed,
138 const std::shared_ptr<void>& context) { UNUSED(committed); UNUSED(context); }
139
143 virtual void OnCommitFailure(
144 const std::exception_ptr& error,
145 const std::shared_ptr<void>& context) { UNUSED(error); UNUSED(context); }
146
150 virtual void OnInspectSuccess(
151 const std::shared_ptr<FileInspector>& fileInspector, const std::shared_ptr<void>& context) {
152 UNUSED(fileInspector);
153 UNUSED(context);
154 }
155
159 virtual void OnInspectFailure(const std::exception_ptr& error, const std::shared_ptr<void>& context) {
160 UNUSED(error);
161 UNUSED(context);
162 }
163
164 protected:
166 Observer() {}
168 };
169
174 virtual std::shared_ptr<ContentLabel> GetLabel() = 0;
175
179 virtual std::vector<std::pair<std::string, std::string>> GetProperties(uint32_t version) = 0;
180
184 virtual std::shared_ptr<ProtectionHandler> GetProtection() = 0;
185
197 bool isOwnerNotificationEnabled,
198 const std::shared_ptr<ProtectionEngine::Observer>& observer,
199 const std::shared_ptr<void>& context) = 0;
200
209 virtual void RevokeContentAsync(
210 const std::shared_ptr<ProtectionEngine::Observer>& observer, const std::shared_ptr<void>& context) = 0;
211
221 FILE_API static bool __CDECL IsProtected(
222 const std::string& filePath,
223 const std::shared_ptr<MipContext>& mipContext);
224
235 FILE_API static bool __CDECL IsProtected(
236 const std::string& filePath,
237 const std::shared_ptr<MipContext>& mipContext,
238 const std::shared_ptr<void>& loggerContext);
239
251 FILE_API static bool __CDECL IsProtected(
252 const std::shared_ptr<Stream>& stream,
253 const std::string& filePath,
254 const std::shared_ptr<MipContext>& mipContext);
255
268 FILE_API static bool __CDECL IsProtected(
269 const std::shared_ptr<Stream>& stream,
270 const std::string& filePath,
271 const std::shared_ptr<MipContext>& mipContext,
272 const std::shared_ptr<void>& loggerContext);
273
288 FILE_API static bool __CDECL IsLabeledOrProtected(
289 const std::string& filePath,
290 const std::shared_ptr<MipContext>& mipContext);
291
307 FILE_API static bool __CDECL IsLabeledOrProtected(
308 const std::string& filePath,
309 const std::shared_ptr<MipContext>& mipContext,
310 const std::shared_ptr<void>& loggerContext);
311
328 FILE_API static bool __CDECL IsLabeledOrProtected(
329 const std::shared_ptr<Stream>& stream,
330 const std::string& filePath,
331 const std::shared_ptr<MipContext>& mipContext);
332
350 FILE_API static bool __CDECL IsLabeledOrProtected(
351 const std::shared_ptr<Stream>& stream,
352 const std::string& filePath,
353 const std::shared_ptr<MipContext>& mipContext,
354 const std::shared_ptr<void>& loggerContext);
355
373 FILE_API static std::shared_ptr<FileStatus> __CDECL GetFileStatus(
374 const std::string& filePath,
375 const std::shared_ptr<MipContext>& mipContext,
376 const std::shared_ptr<void>& loggerContext = nullptr);
377
397 FILE_API static std::shared_ptr<FileStatus> __CDECL GetFileStatus(
398 const std::shared_ptr<Stream>& stream,
399 const std::string& filePath,
400 const std::shared_ptr<MipContext>& mipContext,
401 const std::shared_ptr<void>& loggerContext = nullptr);
402
410 FILE_API static std::vector<uint8_t> __CDECL GetSerializedPublishingLicense(
411 const std::string& filePath,
412 const std::shared_ptr<MipContext>& mipContext);
413
422 FILE_API static std::vector<uint8_t> __CDECL GetSerializedPublishingLicense(
423 const std::string& filePath,
424 const std::shared_ptr<MipContext>& mipContext,
425 const std::shared_ptr<void>& loggerContext);
426
436 FILE_API static std::vector<uint8_t> __CDECL GetSerializedPublishingLicense(
437 const std::shared_ptr<Stream>& stream,
438 const std::string& filePath,
439 const std::shared_ptr<MipContext>& mipContext);
440
451 FILE_API static std::vector<uint8_t> __CDECL GetSerializedPublishingLicense(
452 const std::shared_ptr<Stream>& stream,
453 const std::string& filePath,
454 const std::shared_ptr<MipContext>& mipContext,
455 const std::shared_ptr<void>& loggerContext);
456
464 virtual void ClassifyAsync(const std::shared_ptr<void>& context) = 0;
465
471 virtual void InspectAsync(const std::shared_ptr<void>& context) = 0;
472
482 virtual void SetLabel(
483 const std::shared_ptr<Label>& label,
484 const LabelingOptions& labelingOptions,
485 const ProtectionSettings& protectionSettings) = 0;
486
496 virtual void DeleteLabel(const LabelingOptions& labelingOptions) = 0;
497
504 virtual void SetProtection(
505 const std::shared_ptr<ProtectionDescriptor>& protectionDescriptor,
506 const ProtectionSettings& protectionSettings) = 0;
507
513 virtual void SetProtection(
514 const std::shared_ptr<ProtectionHandler>& protectionHandler) = 0;
515
524 virtual void RemoveProtection() = 0;
525
534 virtual void CommitAsync(const std::string& outputFilePath, const std::shared_ptr<void>& context) = 0;
535
546 virtual void CommitAsync(const std::shared_ptr<Stream>& outputStream, const std::shared_ptr<void>& context) = 0;
547
552 virtual bool IsModified() = 0;
553
559 virtual void GetDecryptedTemporaryFileAsync(const std::shared_ptr<void>& context) = 0;
560
566 virtual void GetDecryptedTemporaryStreamAsync(const std::shared_ptr<void>& context) = 0;
567
574 virtual void NotifyCommitSuccessful(const std::string& actualFilePath) = 0;
575
579 virtual std::string GetOutputFileName() = 0;
580
582 virtual ~FileHandler() {}
585protected:
587 FileHandler() {}
589};
590
591MIP_NAMESPACE_END
592
593#endif // API_MIP_FILE_FILE_HANDLER_H_
A file containing the Action base class and the ActionType enumerator.
Observer interface for clients to get notifications events related to file handler.
Definition file_handler.h:61
virtual void OnCommitFailure(const std::exception_ptr &error, const std::shared_ptr< void > &context)
Called when committing the changes to the file failed.
Definition file_handler.h:143
virtual void OnCreateFileHandlerFailure(const std::exception_ptr &error, const std::shared_ptr< void > &context)
Called when creating the handler failed.
Definition file_handler.h:77
virtual void OnInspectSuccess(const std::shared_ptr< FileInspector > &fileInspector, const std::shared_ptr< void > &context)
Called when inspect success.
Definition file_handler.h:150
virtual void OnGetDecryptedTemporaryFileFailure(const std::exception_ptr &error, const std::shared_ptr< void > &context)
Called when getting the decrypted temporary file failed.
Definition file_handler.h:110
virtual void OnGetDecryptedTemporaryFileSuccess(const std::string &decryptedFilePath, const std::shared_ptr< void > &context)
Called when getting the decrypted temporary file success.
Definition file_handler.h:101
virtual void OnGetDecryptedTemporaryStreamSuccess(const std::shared_ptr< Stream > &decryptedStream, const std::shared_ptr< void > &context)
Called when getting the decrypted temporary stream success.
Definition file_handler.h:118
virtual void OnClassifySuccess(const std::vector< std::shared_ptr< Action > > &actions, const std::shared_ptr< void > &context)
Called when classify success.
Definition file_handler.h:84
virtual void OnGetDecryptedTemporaryStreamFailure(const std::exception_ptr &error, const std::shared_ptr< void > &context)
Called when getting the decrypted temporary stream failed.
Definition file_handler.h:127
virtual void OnClassifyFailure(const std::exception_ptr &error, const std::shared_ptr< void > &context)
Called when classify failed.
Definition file_handler.h:93
virtual void OnCommitSuccess(bool committed, const std::shared_ptr< void > &context)
Called when committing the changes to the file were successful.
Definition file_handler.h:136
virtual void OnInspectFailure(const std::exception_ptr &error, const std::shared_ptr< void > &context)
Called when inspect failed.
Definition file_handler.h:159
virtual void OnCreateFileHandlerSuccess(const std::shared_ptr< FileHandler > &fileHandler, const std::shared_ptr< void > &context)
Called when the handler is created successfully.
Definition file_handler.h:70
Interface for all file handling functions.
Definition file_handler.h:52
virtual void DeleteLabel(const LabelingOptions &labelingOptions)=0
Deletes the sensitivity label from the file.
static FILE_API bool __CDECL IsLabeledOrProtected(const std::shared_ptr< Stream > &stream, const std::string &filePath, const std::shared_ptr< MipContext > &mipContext, const std::shared_ptr< void > &loggerContext)
Checks whether a file is labeled/protected or not.
static FILE_API bool __CDECL IsProtected(const std::string &filePath, const std::shared_ptr< MipContext > &mipContext, const std::shared_ptr< void > &loggerContext)
Checks whether a file is protected or not.
static FILE_API std::shared_ptr< FileStatus > __CDECL GetFileStatus(const std::string &filePath, const std::shared_ptr< MipContext > &mipContext, const std::shared_ptr< void > &loggerContext=nullptr)
Checks whether a file is labeled, protected, or contains protected objects.
virtual void SetLabel(const std::shared_ptr< Label > &label, const LabelingOptions &labelingOptions, const ProtectionSettings &protectionSettings)=0
Sets the sensitivity label to the file.
static FILE_API std::shared_ptr< FileStatus > __CDECL GetFileStatus(const std::shared_ptr< Stream > &stream, const std::string &filePath, const std::shared_ptr< MipContext > &mipContext, const std::shared_ptr< void > &loggerContext=nullptr)
Checks whether a file is labeled, protected, or contains protected objects.
static FILE_API bool __CDECL IsProtected(const std::shared_ptr< Stream > &stream, const std::string &filePath, const std::shared_ptr< MipContext > &mipContext, const std::shared_ptr< void > &loggerContext)
Checks whether a file is protected or not.
static FILE_API bool __CDECL IsProtected(const std::string &filePath, const std::shared_ptr< MipContext > &mipContext)
Checks whether a file is protected or not.
static FILE_API std::vector< uint8_t > __CDECL GetSerializedPublishingLicense(const std::string &filePath, const std::shared_ptr< MipContext > &mipContext)
Get publishing license from the file.
virtual void RemoveProtection()=0
Removes protection from the file. If the original file format does not support labeling,...
virtual void CommitAsync(const std::shared_ptr< Stream > &outputStream, const std::shared_ptr< void > &context)=0
Writes the changes to the stream specified by the |outputStream| parameter.
static FILE_API std::vector< uint8_t > __CDECL GetSerializedPublishingLicense(const std::shared_ptr< Stream > &stream, const std::string &filePath, const std::shared_ptr< MipContext > &mipContext)
Get publishing license from the file.
virtual void SetProtection(const std::shared_ptr< ProtectionHandler > &protectionHandler)=0
Sets protection on a document using an existing protection handler.
virtual void InspectAsync(const std::shared_ptr< void > &context)=0
Create a file inspector object, used to retrieve file contents from compatible file formats.
static FILE_API bool __CDECL IsLabeledOrProtected(const std::string &filePath, const std::shared_ptr< MipContext > &mipContext)
Checks whether a file is labeled/protected or not.
static FILE_API bool __CDECL IsProtected(const std::shared_ptr< Stream > &stream, const std::string &filePath, const std::shared_ptr< MipContext > &mipContext)
Checks whether a file is protected or not.
virtual void RegisterContentForTrackingAndRevocationAsync(bool isOwnerNotificationEnabled, const std::shared_ptr< ProtectionEngine::Observer > &observer, const std::shared_ptr< void > &context)=0
Register the content for tracking and revocation.
virtual std::shared_ptr< ProtectionHandler > GetProtection()=0
Starts retrieving the protection policy from the file.
virtual void GetDecryptedTemporaryStreamAsync(const std::shared_ptr< void > &context)=0
Returns a stream - representing the decrypted content.
virtual std::shared_ptr< ContentLabel > GetLabel()=0
Starts retrieving the sensitivity label from the file.
virtual void SetProtection(const std::shared_ptr< ProtectionDescriptor > &protectionDescriptor, const ProtectionSettings &protectionSettings)=0
Sets either custom or template-based permissions (according to protectionDescriptor->GetProtectionTyp...
virtual void GetDecryptedTemporaryFileAsync(const std::shared_ptr< void > &context)=0
Returns a path to a temporary file (that will be deleted if possible) - representing the decrypted co...
static FILE_API std::vector< uint8_t > __CDECL GetSerializedPublishingLicense(const std::shared_ptr< Stream > &stream, const std::string &filePath, const std::shared_ptr< MipContext > &mipContext, const std::shared_ptr< void > &loggerContext)
Get publishing license from the file.
virtual void RevokeContentAsync(const std::shared_ptr< ProtectionEngine::Observer > &observer, const std::shared_ptr< void > &context)=0
Perform revocation for the content.
virtual std::vector< std::pair< std::string, std::string > > GetProperties(uint32_t version)=0
Retrieves the file properties according to version.
virtual void NotifyCommitSuccessful(const std::string &actualFilePath)=0
To be called when the changes have been committed to disk.
static FILE_API bool __CDECL IsLabeledOrProtected(const std::string &filePath, const std::shared_ptr< MipContext > &mipContext, const std::shared_ptr< void > &loggerContext)
Checks whether a file is labeled/protected or not.
virtual void ClassifyAsync(const std::shared_ptr< void > &context)=0
Executes the rules in the handler and returns the list of actions to be executed.
static FILE_API bool __CDECL IsLabeledOrProtected(const std::shared_ptr< Stream > &stream, const std::string &filePath, const std::shared_ptr< MipContext > &mipContext)
Checks whether a file is labeled/protected or not.
virtual std::string GetOutputFileName()=0
Calculates the output file name and extension based on the original file name and the accumulated cha...
static FILE_API std::vector< uint8_t > __CDECL GetSerializedPublishingLicense(const std::string &filePath, const std::shared_ptr< MipContext > &mipContext, const std::shared_ptr< void > &loggerContext)
Get publishing license from the file.
virtual bool IsModified()=0
Checks if there are changes to commit to the file.
virtual void CommitAsync(const std::string &outputFilePath, const std::shared_ptr< void > &context)=0
Writes the changes to the file specified by the |outputFilePath| parameter.
Interface for configuring labeling options for the SetLabel/DeleteLabel methods.
Definition labeling_options.h:43
Interface for configuring protection options for the SetLabel method.
Definition protection_settings.h:40
A file Containing the ContentLabel class.
#define FILE_API
Definition file_export.h:49
File containing definition of MipContext.
MIP namespace macros.
Defines ProtectionDescriptor interface.
Defines ProtectionEngine interface.
Defines ProtectionHandler interface.
A file containing the Stream interface/class definition.