Microsoft Information Protection SDK - C++ 1.17
API Reference Documentation for C++
Loading...
Searching...
No Matches
common_types.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 */
33#ifndef API_MIP_COMMON_TYPES_H_
34#define API_MIP_COMMON_TYPES_H_
35
36#include <cstring>
37#include <exception>
38#include <map>
39#include <memory>
40#include <string>
41#include <unordered_map>
42#include <vector>
43
44#include "mip/mip_namespace.h"
45
47#ifndef UNUSED
48#define UNUSED(x) (void)x
49#endif
52MIP_NAMESPACE_BEGIN
53
57enum class WatermarkLayout : unsigned int {
58 HORIZONTAL = 0,
59 DIAGONAL = 1,
60};
61
65enum class ContentMarkAlignment : unsigned int {
66 LEFT = 0,
67 RIGHT = 1,
68 CENTER = 2,
69};
70
75enum class AssignmentMethod : unsigned int {
76 STANDARD = 0,
77 PRIVILEGED = 1,
78 AUTO = 2,
79};
80
84enum class ActionSource : unsigned int {
85 MANUAL,
86 AUTOMATIC,
88 DEFAULT
89};
90
94enum class DataState : unsigned int {
95 REST,
96 MOTION,
97 USE,
98};
99
100inline const std::string& GetFileContentFormat() {
101 static const std::string fileContentFormat = "file";
102 return fileContentFormat;
103}
104
105inline const std::string& GetEmailContentFormat() {
106 static const std::string emailContentFormat = "email";
107 return emailContentFormat;
108}
109
129
135
137 return static_cast<FunctionalityFilterType>(static_cast<int>(firstFilter) | static_cast<int>(secondFilter));
138}
139
141 return static_cast<FunctionalityFilterType>(static_cast<int>(firstFilter) & static_cast<int>(secondFilter));
142}
143
145 return static_cast<FunctionalityFilterType>(~(static_cast<int>(filter)));
146}
147
151enum class FeatureId : unsigned int {
153};
154
167enum class VariableTextMarkingType : unsigned int {
168 Default = 0,
169 PassThrough = 1,
170 None = 2,
171};
172
178enum class ContainerDecryptionOption : unsigned int {
179 Default = 0,
180 Msg = 1,
181 Top = 2,
182 All = 3,
183};
184
191inline std::string ContainerDecryptionOptionString(ContainerDecryptionOption option) {
192 static std::string kMethodArray[] = { "default", "msg", "top", "all" };
193 return kMethodArray[static_cast<int>(option)];
194}
195
201enum class Classifier : unsigned int {
202 SensitiveInformation = 0, // Classifier based on specific content (credit cards); Uses Microsoft Classification Engine
203 MachineLearning = 1, // Classifier based on Machine Learning recognition (offensive language)
204 ExtendedSensitiveInformation = 2, // Classifier based on specific content (credit cards); Does not use Microsoft Classification Engine
205};
206
210enum class Workload : unsigned int {
211 Office = 0, // Office type workloads, which include File and Email content types.
212 Purview = 1, // Purview type workloads, which includes File, Email and SchematizedData content types.
213};
214
216{
217 std::unordered_map<std::string, std::string> uniqueIds;
218 std::vector<std::string> contentFormats;
219};
220typedef std::map<mip::Classifier, UniqueIdsAndContentFormats> ClassifierUniqueIdsAndContentFormats;
221
228inline std::string GetAssignmentMethodString(AssignmentMethod method) {
229 static std::string kMethodArray[] = { "Standard", "Privileged", "Auto" };
230 return kMethodArray[static_cast<int>(method)];
231}
232
239inline static std::string GetActionSourceString(ActionSource actionSource) {
240 static std::string kMethodArray[] = { "Manual", "Automatic", "Recommended", "Default" };
241 return kMethodArray[static_cast<int>(actionSource)];
242}
243
250inline static std::string GetDataStateString(DataState state) {
251 static std::string kMethodArray[] = { "Rest", "Motion", "Use" };
252 return kMethodArray[static_cast<int>(state)];
253}
254
255// Extension to use when creating sqlite table on disk
256inline const std::string& GetSqliteExtension() {
257 static const std::string sqliteExtension = ".sqlite3";
258 return sqliteExtension;
259}
260
261// Path to use when creating a table in memory
262inline const std::string& GetMemoryDatabasePath() {
263 static const std::string memoryPath = ":memory:";
264 return memoryPath;
265}
266
270class Identity {
271public:
281 Identity(const Identity& other)
282 : mEmail(other.mEmail),
283 mName(other.mName) { }
284
290 explicit Identity(const std::string& email) : mEmail(email) { }
291
298 explicit Identity(const std::string& email, const std::string& name) : mEmail(email), mName(name) { }
299
305 const std::string& GetEmail() const { return mEmail; }
306
312 const std::string& GetName() const { return mName; }
313
314private:
315 std::string mEmail;
316 std::string mName;
317};
318
323public:
329 public:
338 const std::string& authority,
339 const std::string& resource,
340 const std::string& scope = std::string(),
341 const std::string& claims = std::string())
342 : mAuthority(authority),
343 mResource(resource),
344 mScope(scope),
345 mClaims(claims) {
346 }
352 const std::string& GetAuthority() const { return mAuthority; }
358 const std::string& GetResource() const { return mResource; }
364 const std::string& GetScope() const { return mScope; }
370 const std::string& GetClaims() const { return mClaims; }
371 private:
372 std::string mAuthority;
373 std::string mResource;
374 std::string mScope;
375 std::string mClaims;
376 };
377
382 public:
387
393 OAuth2Token(const std::string& accessToken) : mAccessToken(accessToken) {}
394
400 const std::string& GetAccessToken() const { return mAccessToken; }
401
407 void SetAccessToken(const std::string& accessToken) { mAccessToken = accessToken; }
408
414 const std::string& GetErrorMessage() const { return mErrorMessage; }
415
421 void SetErrorMessage(const std::string& errorMessage) { mErrorMessage = errorMessage; }
422
423 private:
424 std::string mAccessToken;
425 std::string mErrorMessage;
426 };
427
444 virtual bool AcquireOAuth2Token(
445 const Identity& identity,
446 const OAuth2Challenge& challenge,
447 OAuth2Token& token) { UNUSED(identity); UNUSED(challenge); UNUSED(token); return false; }
448
463 virtual bool AcquireOAuth2Token(
464 const Identity& identity,
465 const OAuth2Challenge& challenge,
466 const std::shared_ptr<void>& context,
467 OAuth2Token& token) {
468 // Temporarily call into old 'AcquireOAuth2Token' method until it is fully deprecated (in case application
469 // hasn't yet implemented this new method)
470 UNUSED(context);
471 return AcquireOAuth2Token(identity, challenge, token);
472 }
473
475 virtual ~AuthDelegate() { }
476protected:
477 AuthDelegate() { }
479};
480
484enum class Consent : unsigned int {
486 Accept,
487 Reject
488};
489
497public:
511 virtual Consent GetUserConsent(const std::string& url) = 0;
512
514 virtual ~ConsentDelegate() { }
515protected:
516 ConsentDelegate() { }
518};
519
524 std::string applicationId;
525 std::string applicationName;
527};
528
534inline constexpr const char* GetCustomSettingPolicyDataName() {
535 return "policy_data";
536}
542inline constexpr const char* GetCustomSettingExportPolicyFileName() {
543 return "export_policy_file";
544}
550inline constexpr const char* GetCustomSettingSensitivityTypesDataName() {
551 return "sensitivity_types_data";
552}
558inline constexpr const char* GetCustomSettingPolicyDataFile() {
559 return "policy_file";
560}
566inline constexpr const char* GetCustomSettingSensitivityTypesDataFile() {
567 return "sensitivity_types_file";
568}
575 return "label_custom_properties_sync_enabled";
576}
583inline constexpr const char* GetCustomSettingPolicyTtlDays() {
584 return "PolicyTtlDays";
585}
592inline constexpr const char* GetCustomSettingSensitivityPolicyTtlDays() {
593 return "SensitivityPolicyTtlDays";
594}
602inline constexpr const char* GetEnforceMsgPfileProtection() {
603 return "EnforceMsgPfileProtection";
604}
610inline constexpr const char* GetCustomSettingEnableMsgFileType() {
611 return "enable_msg_file_type";
612}
618inline constexpr const char* GetCustomSettingContainerDecryptionOption() {
619 return "container_decryption_option";
620}
625inline constexpr const char* GetCustomSettingEnablePowerBIFileType() {
626 return "enable_power_bi_file_type";
627}
632inline constexpr const char* GetCustomSettingKeepPdfLinearization() {
633 return "keep_pdf_linearization";
634}
635inline constexpr const char* GetCustomSettingEnableDeprecatedRemoveActions() {
636 return "enable_deprecated_remove_actions";
637}
638inline constexpr const char* GetCustomSettingPrintDiscoveredInfoTypesToTrace() {
639 return "LogMatchedContentToTrace";
640}
641inline constexpr const char* GetCustomSettingTaskTimeoutMs() {
642 return "TaskTimeoutMs";
643}
644
645inline constexpr const char* GetCustomSettingLabelWithoutPolicy() {
646 return "label_without_policy";
647}
648
649inline constexpr const char* GetCustomSettingMaxFileSizeForProtection() {
650 return "max_file_size_for_protection";
651}
652
653inline constexpr const char* GetCustomSettingMaxNestedProtectedMsgs() {
654 return "max_nested_protected_msgs";
655}
656
657inline constexpr const char* GetCustomSettingMaxPolicyXmlVersion() {
658 return "max_policy_xml_version";
659}
660
666inline constexpr const char* GetCustomSettingDelegateApplicationInfo() {
667 return "delegate_application_info";
668}
669
676inline constexpr const char* GetCustomSettingEnableCoAuthMetadata() {
677 return "co_auth_metadata";
678}
679
685inline constexpr const char* GetCustomSettingLabelsForAllContentFormats() {
686 return "labels_for_all_content_formats";
687}
688
692class CaseInsensitiveComparator {
693public:
694 bool operator() (const std::string& lhs, const std::string& rhs) const {
695 if (lhs.size() != rhs.size())
696 return lhs.size() < rhs.size();
697
698#ifdef _WIN32
699 return _strnicmp(lhs.c_str(), rhs.c_str(), lhs.size()) < 0;
700#else
701 return strncasecmp(lhs.c_str(), rhs.c_str(), lhs.size()) < 0;
702#endif // WIN32
703 }
704};
710enum class CacheStorageType : unsigned int {
711 InMemory = 0,
712 OnDisk = 1,
713 OnDiskEncrypted = 2
714};
715
720 Default = 0,
721 PFileSuffix = 1,
722 PPrefix = 2,
723};
724
728enum class Cloud {
729 Unknown = 0,
730 Custom = 1,
731 Test = 2,
732 Commercial = 3,
733 Germany = 4,
734 US_DoD = 5,
735 US_GCC = 6,
736 US_GCC_High = 7,
737 US_Sec = 8,
738 US_Nat = 9,
739 China_01 = 10,
740};
741
745enum class DataBoundary {
746 Default = 0,
747 United_States = 1,
748 North_America = 1,
749 European_Union = 2,
750 Germany = 3,
752 Japan = 4,
753 Asia = 4,
754 Australia = 5,
755};
756
761public:
771 virtual bool Cancel() = 0;
773 virtual ~AsyncControl() = default;
775};
776
777MIP_NAMESPACE_END
778
779#endif // API_MIP_COMMON_TYPES_H_
Class used to cancel async operation.
Definition common_types.h:760
virtual bool Cancel()=0
Calling cancel will result in a attempt to cancel the task, in case of success the appropriate onFail...
a class that contains all the information required from the calling application in order to generate ...
Definition common_types.h:328
const std::string & GetScope() const
Get the scope string.
Definition common_types.h:364
const std::string & GetResource() const
Get the resource string.
Definition common_types.h:358
std::string mScope
Definition common_types.h:374
const std::string & GetClaims() const
Get the claims string.
Definition common_types.h:370
std::string mResource
Definition common_types.h:373
OAuth2Challenge(const std::string &authority, const std::string &resource, const std::string &scope=std::string(), const std::string &claims=std::string())
Construct a new OAuth2Challenge object.
Definition common_types.h:337
std::string mClaims
Definition common_types.h:375
const std::string & GetAuthority() const
Get the authority string.
Definition common_types.h:352
std::string mAuthority
Definition common_types.h:372
A class containing access token info provided by an application.
Definition common_types.h:381
void SetAccessToken(const std::string &accessToken)
Set the access token string.
Definition common_types.h:407
OAuth2Token(const std::string &accessToken)
Construct a new OAuth2Token object from JWT access token.
Definition common_types.h:393
OAuth2Token()
Construct a new OAuth2Token object.
Definition common_types.h:386
void SetErrorMessage(const std::string &errorMessage)
Set the error message.
Definition common_types.h:421
std::string mErrorMessage
Definition common_types.h:425
const std::string & GetAccessToken() const
Get the access token string.
Definition common_types.h:400
const std::string & GetErrorMessage() const
Get the error message, if any.
Definition common_types.h:414
std::string mAccessToken
Definition common_types.h:424
Delegate for auth related operations.
Definition common_types.h:322
virtual bool AcquireOAuth2Token(const Identity &identity, const OAuth2Challenge &challenge, const std::shared_ptr< void > &context, OAuth2Token &token)
This method is called when an auth token is required for the policy engine with the given identity an...
Definition common_types.h:463
virtual bool AcquireOAuth2Token(const Identity &identity, const OAuth2Challenge &challenge, OAuth2Token &token)
This method is called when an auth token is required for the policy engine with the given identity an...
Definition common_types.h:444
Delegate for consent related operations.
Definition common_types.h:496
virtual Consent GetUserConsent(const std::string &url)=0
Called when SDK requires user consent to connect to a service endpoint.
Abstraction for identity.
Definition common_types.h:270
Identity(const std::string &email, const std::string &name)
Identity constructor used when a user email address and user name is known.
Definition common_types.h:298
Identity()
Default Identity constructor used when a user email address is not known.
Definition common_types.h:275
const std::string & GetEmail() const
Get the email.
Definition common_types.h:305
std::string mName
Definition common_types.h:316
Identity(const Identity &other)
Identity copy constructor.
Definition common_types.h:281
const std::string & GetName() const
Get the user's friendly name. used for text marking.
Definition common_types.h:312
Identity(const std::string &email)
Identity constructor used when a user email address is known.
Definition common_types.h:290
std::string mEmail
Definition common_types.h:315
const std::string & GetSqliteExtension()
Definition common_types.h:256
constexpr const char * GetCustomSettingSensitivityTypesDataName()
Name of the setting to explicitly specify sensitivity data.
Definition common_types.h:550
FeatureId
Defines new features by name.
Definition common_types.h:151
PFileExtensionBehavior
Describes PFile extensions behavior.
Definition common_types.h:719
Cloud
Azure cloud identifier.
Definition common_types.h:728
@ US_GCC_High
@ China_01
@ Commercial
AssignmentMethod
The assignment method of the label on the document. Whether the Assignment of the label was done auto...
Definition common_types.h:75
CacheStorageType
Storage type for the caches.
Definition common_types.h:710
constexpr const char * GetCustomSettingPolicyDataName()
Name of the setting to explicitly specify policy data.
Definition common_types.h:534
FunctionalityFilterType operator&(FunctionalityFilterType firstFilter, FunctionalityFilterType secondFilter)
Definition common_types.h:140
constexpr const char * GetCustomSettingSensitivityPolicyTtlDays()
Name of the setting that enables overriding sensitivity policy ttl in days be default it will be 30 d...
Definition common_types.h:592
const std::string & GetFileContentFormat()
Definition common_types.h:100
FunctionalityFilterType operator|(FunctionalityFilterType firstFilter, FunctionalityFilterType secondFilter)
Definition common_types.h:136
VariableTextMarkingType
various dynamic fields can be set into the text message of the application Some known: ${Item....
Definition common_types.h:167
DataState
Defines what state of the data is the application acting upon.
Definition common_types.h:94
ContentMarkAlignment
Alignment for content marks (content header or content footer).
Definition common_types.h:65
Consent
A user's response when consent is requested to connect to a service endpoint.
Definition common_types.h:484
@ AcceptAlways
FunctionalityFilterType operator~(FunctionalityFilterType filter)
Definition common_types.h:144
const std::string & GetMemoryDatabasePath()
Definition common_types.h:262
Workload
The workload the application is working on, used primary to check for consent.
Definition common_types.h:210
static std::string GetDataStateString(DataState state)
Get the content state name.
Definition common_types.h:250
LabelFilterType
Label filter types, optional set of properties that can be used to filter labels or label behavior wh...
Definition common_types.h:114
@ DoubleKeyUserDefinedProtection
Definition common_types.h:123
@ CustomProtection
Definition common_types.h:116
@ TemplateProtection
Definition common_types.h:117
@ EncryptOnlyProtection
Definition common_types.h:124
@ DoNotForwardProtection
Definition common_types.h:118
@ HyokProtection
Definition common_types.h:120
@ MachineLearningClassifier
Definition common_types.h:126
@ AdhocProtection
Definition common_types.h:119
@ None
Definition common_types.h:115
@ DoubleKeyProtection
Definition common_types.h:122
@ ExtendedSensitiveInformationClassifier
Definition common_types.h:127
@ SensitiveInformationClassifier
Definition common_types.h:125
@ PredefinedTemplateProtection
Definition common_types.h:121
constexpr const char * GetCustomSettingPolicyDataFile()
Name of the setting to explicitly specify policy data file path.
Definition common_types.h:558
static std::string GetActionSourceString(ActionSource actionSource)
Get the action source name.
Definition common_types.h:239
Classifier
The type of classification the application should be running on the data to determine autolabeling st...
Definition common_types.h:201
@ ExtendedSensitiveInformation
@ SensitiveInformation
constexpr const char * GetCustomSettingPolicyTtlDays()
Name of the setting that enables overriding policy ttl in days be default it will be 30 days....
Definition common_types.h:583
constexpr const char * GetCustomSettingSensitivityTypesDataFile()
Name of the setting to explicitly specify sensitivity types data file path.
Definition common_types.h:566
DataBoundary
Diagnostic region identifier.
Definition common_types.h:745
@ Europe_MiddleEast_Africa
std::string GetAssignmentMethodString(AssignmentMethod method)
Converts AssignmentMethod enum to a string description.
Definition common_types.h:228
std::map< mip::Classifier, UniqueIdsAndContentFormats > ClassifierUniqueIdsAndContentFormats
Definition common_types.h:220
ActionSource
defines what triggered the SetLabel event
Definition common_types.h:84
WatermarkLayout
Layout for watermarks.
Definition common_types.h:57
LabelFilterType FunctionalityFilterType
Name change within the cpp workspace to imply the filters has greater scope than just label behavior....
Definition common_types.h:134
constexpr const char * GetCustomSettingLabelCustomPropertiesSyncEnabled()
Name of the setting that allows to enable label by custom properties and custom properties by label f...
Definition common_types.h:574
const std::string & GetEmailContentFormat()
Definition common_types.h:105
constexpr const char * GetCustomSettingExportPolicyFileName()
Name of the setting to explicitly specify file path to export SCC policy data to.
Definition common_types.h:542
MIP namespace macros.
A struct that includes application specific information.
Definition common_types.h:523
std::string applicationName
Definition common_types.h:525
std::string applicationVersion
Definition common_types.h:526
std::string applicationId
Definition common_types.h:524
Definition common_types.h:216
std::unordered_map< std::string, std::string > uniqueIds
Definition common_types.h:217
std::vector< std::string > contentFormats
Definition common_types.h:218