Microsoft Information Protection SDK - C++ 1.18
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
270enum class StorageTableVersion : unsigned int {
271 One = 1, // Version 1 of the storage table
272 Two = 2, // Version 2 of the storage table. Adds delete range support.
273};
274
278class Identity {
279public:
289 Identity(const Identity& other)
290 : mEmail(other.mEmail),
291 mName(other.mName) { }
292
298 explicit Identity(const std::string& email) : mEmail(email) { }
299
306 explicit Identity(const std::string& email, const std::string& name) : mEmail(email), mName(name) { }
307
313 const std::string& GetEmail() const { return mEmail; }
314
320 const std::string& GetName() const { return mName; }
321
322private:
323 std::string mEmail;
324 std::string mName;
325};
326
331public:
337 public:
346 const std::string& authority,
347 const std::string& resource,
348 const std::string& scope = std::string(),
349 const std::string& claims = std::string())
350 : mAuthority(authority),
351 mResource(resource),
352 mScope(scope),
353 mClaims(claims) {
354 }
360 const std::string& GetAuthority() const { return mAuthority; }
366 const std::string& GetResource() const { return mResource; }
372 const std::string& GetScope() const { return mScope; }
378 const std::string& GetClaims() const { return mClaims; }
379 private:
380 std::string mAuthority;
381 std::string mResource;
382 std::string mScope;
383 std::string mClaims;
384 };
385
390 public:
395
401 OAuth2Token(const std::string& accessToken) : mAccessToken(accessToken) {}
402
408 const std::string& GetAccessToken() const { return mAccessToken; }
409
415 void SetAccessToken(const std::string& accessToken) { mAccessToken = accessToken; }
416
422 const std::string& GetErrorMessage() const { return mErrorMessage; }
423
429 void SetErrorMessage(const std::string& errorMessage) { mErrorMessage = errorMessage; }
430
431 private:
432 std::string mAccessToken;
433 std::string mErrorMessage;
434 };
435
452 virtual bool AcquireOAuth2Token(
453 const Identity& identity,
454 const OAuth2Challenge& challenge,
455 OAuth2Token& token) { UNUSED(identity); UNUSED(challenge); UNUSED(token); return false; }
456
471 virtual bool AcquireOAuth2Token(
472 const Identity& identity,
473 const OAuth2Challenge& challenge,
474 const std::shared_ptr<void>& context,
475 OAuth2Token& token) {
476 // Temporarily call into old 'AcquireOAuth2Token' method until it is fully deprecated (in case application
477 // hasn't yet implemented this new method)
478 UNUSED(context);
479 return AcquireOAuth2Token(identity, challenge, token);
480 }
481
483 virtual ~AuthDelegate() { }
484protected:
485 AuthDelegate() { }
487};
488
492enum class Consent : unsigned int {
494 Accept,
495 Reject
496};
497
505public:
519 virtual Consent GetUserConsent(const std::string& url) = 0;
520
522 virtual ~ConsentDelegate() { }
523protected:
524 ConsentDelegate() { }
526};
527
532 std::string applicationId;
533 std::string applicationName;
535};
536
542inline constexpr const char* GetCustomSettingPolicyDataName() {
543 return "policy_data";
544}
550inline constexpr const char* GetCustomSettingExportPolicyFileName() {
551 return "export_policy_file";
552}
558inline constexpr const char* GetCustomSettingSensitivityTypesDataName() {
559 return "sensitivity_types_data";
560}
566inline constexpr const char* GetCustomSettingPolicyDataFile() {
567 return "policy_file";
568}
574inline constexpr const char* GetCustomSettingSensitivityTypesDataFile() {
575 return "sensitivity_types_file";
576}
583 return "label_custom_properties_sync_enabled";
584}
591inline constexpr const char* GetCustomSettingPolicyTtlDays() {
592 return "PolicyTtlDays";
593}
600inline constexpr const char* GetCustomSettingSensitivityPolicyTtlDays() {
601 return "SensitivityPolicyTtlDays";
602}
610inline constexpr const char* GetEnforceMsgPfileProtection() {
611 return "EnforceMsgPfileProtection";
612}
618inline constexpr const char* GetCustomSettingEnableMsgFileType() {
619 return "enable_msg_file_type";
620}
626inline constexpr const char* GetCustomSettingContainerDecryptionOption() {
627 return "container_decryption_option";
628}
633inline constexpr const char* GetCustomSettingEnablePowerBIFileType() {
634 return "enable_power_bi_file_type";
635}
640inline constexpr const char* GetCustomSettingEnableEmlFileType() {
641 return "enable_eml_file_type";
642}
647inline constexpr const char* GetCustomSettingKeepPdfLinearization() {
648 return "keep_pdf_linearization";
649}
650inline constexpr const char* GetCustomSettingEnableDeprecatedRemoveActions() {
651 return "enable_deprecated_remove_actions";
652}
653inline constexpr const char* GetCustomSettingPrintDiscoveredInfoTypesToTrace() {
654 return "LogMatchedContentToTrace";
655}
656inline constexpr const char* GetCustomSettingTaskTimeoutMs() {
657 return "TaskTimeoutMs";
658}
659
660inline constexpr const char* GetCustomSettingLabelWithoutPolicy() {
661 return "label_without_policy";
662}
663
664inline constexpr const char* GetCustomSettingMaxFileSizeForProtection() {
665 return "max_file_size_for_protection";
666}
667
668inline constexpr const char* GetCustomSettingMaxNestedProtectedMsgs() {
669 return "max_nested_protected_msgs";
670}
671
672inline constexpr const char* GetCustomSettingMaxPolicyXmlVersion() {
673 return "max_policy_xml_version";
674}
675
681inline constexpr const char* GetCustomSettingDelegateApplicationInfo() {
682 return "delegate_application_info";
683}
684
691inline constexpr const char* GetCustomSettingEnableCoAuthMetadata() {
692 return "co_auth_metadata";
693}
694
700inline constexpr const char* GetCustomSettingLabelsForAllContentFormats() {
701 return "labels_for_all_content_formats";
702}
709inline constexpr const char* GetCustomSettingDnsInfoTtlDays() {
710 return "DnsInfoTtlDays";
711}
712
716class CaseInsensitiveComparator {
717public:
718 bool operator() (const std::string& lhs, const std::string& rhs) const {
719 if (lhs.size() != rhs.size())
720 return lhs.size() < rhs.size();
721
722#ifdef _WIN32
723 return _strnicmp(lhs.c_str(), rhs.c_str(), lhs.size()) < 0;
724#else
725 return strncasecmp(lhs.c_str(), rhs.c_str(), lhs.size()) < 0;
726#endif // WIN32
727 }
728};
734enum class CacheStorageType : unsigned int {
735 InMemory = 0,
736 OnDisk = 1,
737 OnDiskEncrypted = 2
738};
739
744 Default = 0,
745 PFileSuffix = 1,
746 PPrefix = 2,
747};
748
752enum class Cloud {
753 Unknown = 0,
754 Custom = 1,
755 Test = 2,
756 Commercial = 3,
757 Germany = 4,
758 US_DoD = 5,
759 US_GCC = 6,
760 US_GCC_High = 7,
761 US_Sec = 8,
762 US_Nat = 9,
763 China_01 = 10,
764};
765
769enum class DataBoundary {
770 Default = 0,
771 United_States = 1,
772 North_America = 1,
773 European_Union = 2,
774 Germany = 3,
776 Japan = 4,
777 Asia = 4,
778 Australia = 5,
779};
780
784enum class ServiceType {
785 Protection = 0,
786 Policy = 1,
787 Telemetry = 2,
788};
789
794public:
804 virtual bool Cancel() = 0;
806 virtual ~AsyncControl() = default;
808};
809
810MIP_NAMESPACE_END
811
812#endif // API_MIP_COMMON_TYPES_H_
Class used to cancel async operation.
Definition common_types.h:793
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:336
const std::string & GetScope() const
Get the scope string.
Definition common_types.h:372
const std::string & GetResource() const
Get the resource string.
Definition common_types.h:366
std::string mScope
Definition common_types.h:382
const std::string & GetClaims() const
Get the claims string.
Definition common_types.h:378
std::string mResource
Definition common_types.h:381
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:345
std::string mClaims
Definition common_types.h:383
const std::string & GetAuthority() const
Get the authority string.
Definition common_types.h:360
std::string mAuthority
Definition common_types.h:380
A class containing access token info provided by an application.
Definition common_types.h:389
void SetAccessToken(const std::string &accessToken)
Set the access token string.
Definition common_types.h:415
OAuth2Token(const std::string &accessToken)
Construct a new OAuth2Token object from JWT access token.
Definition common_types.h:401
OAuth2Token()
Construct a new OAuth2Token object.
Definition common_types.h:394
void SetErrorMessage(const std::string &errorMessage)
Set the error message.
Definition common_types.h:429
std::string mErrorMessage
Definition common_types.h:433
const std::string & GetAccessToken() const
Get the access token string.
Definition common_types.h:408
const std::string & GetErrorMessage() const
Get the error message, if any.
Definition common_types.h:422
std::string mAccessToken
Definition common_types.h:432
Delegate for auth related operations.
Definition common_types.h:330
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:471
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:452
Delegate for consent related operations.
Definition common_types.h:504
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:278
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:306
Identity()
Default Identity constructor used when a user email address is not known.
Definition common_types.h:283
const std::string & GetEmail() const
Get the email.
Definition common_types.h:313
std::string mName
Definition common_types.h:324
Identity(const Identity &other)
Identity copy constructor.
Definition common_types.h:289
const std::string & GetName() const
Get the user's friendly name. used for text marking.
Definition common_types.h:320
Identity(const std::string &email)
Identity constructor used when a user email address is known.
Definition common_types.h:298
std::string mEmail
Definition common_types.h:323
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:558
FeatureId
Defines new features by name.
Definition common_types.h:151
PFileExtensionBehavior
Describes PFile extensions behavior.
Definition common_types.h:743
Cloud
Azure cloud identifier.
Definition common_types.h:752
@ 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:734
ServiceType
Service type identifier.
Definition common_types.h:784
constexpr const char * GetCustomSettingPolicyDataName()
Name of the setting to explicitly specify policy data.
Definition common_types.h:542
FunctionalityFilterType operator&(FunctionalityFilterType firstFilter, FunctionalityFilterType secondFilter)
Definition common_types.h:140
StorageTableVersion
The features available in the storage tables being used.
Definition common_types.h:270
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:600
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:492
@ 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:566
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:591
constexpr const char * GetCustomSettingSensitivityTypesDataFile()
Name of the setting to explicitly specify sensitivity types data file path.
Definition common_types.h:574
DataBoundary
Diagnostic region identifier for non-sovereign clouds.
Definition common_types.h:769
@ 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:582
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:550
MIP namespace macros.
A struct that includes application specific information.
Definition common_types.h:531
std::string applicationName
Definition common_types.h:533
std::string applicationVersion
Definition common_types.h:534
std::string applicationId
Definition common_types.h:532
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