标签保护类型查询

本文介绍如何使用 MIP SDK API 识别标签上配置的保护类型,以便应用程序可以在应用保护之前做出行为和 UI 决策。 它还汇总了每种保护类型的密钥 API 和预期行为。

概述

从 MIP SDK 1.18 开始, Label 该类公开用于确定标签适用的保护类型的方法。 以前,应用程序只能检查 HasRightsManagementPolicy() 以确定标签是否应用了任何保护。 新方法允许应用程序区分以下保护类型:

  • 不转发 防止收件人转发、打印或复制内容的保护。
  • 仅加密 对内容进行加密但不会限制收件人的解密操作的保护。
  • 临时 保护,当用户在应用时设置用户自定义权限(用户定义的权限)。

这些方法使应用程序能够更智能地决定如何处理标签。 例如,电子邮件应用程序可能会显示不同的 UI 选项,具体取决于标签是否应用“不转发”和“仅加密”保护。

查询标签保护类型

C++

mip::Label 类提供以下方法:

// Returns true if the label applies any protection.
bool HasRightsManagementPolicy() const;

// Returns true if the label applies Do Not Forward protection.
bool HasDoNotForwardProtection() const;

// Returns true if the label applies Encrypt Only protection.
bool HasEncryptOnlyProtection() const;

// Returns true if the label applies ad-hoc (user-defined) protection.
bool HasAdhocProtection() const;

示例:检查标签保护类型

for (const auto& label : engine->ListSensitivityLabels()) {
    std::cout << "Label: " << label->GetName() << std::endl;

    if (label->HasRightsManagementPolicy()) {
        if (label->HasDoNotForwardProtection()) {
            std::cout << "  Protection type: Do Not Forward" << std::endl;
        } else if (label->HasEncryptOnlyProtection()) {
            std::cout << "  Protection type: Encrypt Only" << std::endl;
        } else if (label->HasAdhocProtection()) {
            std::cout << "  Protection type: Ad-hoc (user-defined permissions)" << std::endl;
        } else {
            std::cout << "  Protection type: Template-based" << std::endl;
        }
    } else {
        std::cout << "  No protection" << std::endl;
    }
}

C# (.NET)

在 .NET 包装器中, Label 类公开匹配的属性:

label.HasRightsManagementPolicy  // bool
label.HasDoNotForwardProtection  // bool
label.HasEncryptOnlyProtection   // bool
label.HasAdhocProtection         // bool

示例:检查标签保护类型

foreach (var label in engine.SensitivityLabels)
{
    Console.WriteLine($"Label: {label.Name}");

    if (label.HasRightsManagementPolicy)
    {
        if (label.HasDoNotForwardProtection)
            Console.WriteLine("  Protection type: Do Not Forward");
        else if (label.HasEncryptOnlyProtection)
            Console.WriteLine("  Protection type: Encrypt Only");
        else if (label.HasAdhocProtection)
            Console.WriteLine("  Protection type: Ad-hoc (user-defined permissions)");
        else
            Console.WriteLine("  Protection type: Template-based");
    }
    else
    {
        Console.WriteLine("  No protection");
    }
}

与现有 API 的关系

这些新方法补充了现有 HasRightsManagementPolicy() 方法。 关系为:

  • 如果 HasRightsManagementPolicy() 返回 false,则所有三个新方法也返回 false
  • 如果HasRightsManagementPolicy()返回true,则至少有一个新方法返回true;如果标签使用基于模板的保护,则没有方法返回true
  • 标签可以将即席权限(用户定义的权限)与“不转发”或“仅加密”组合在一起。 在这些组合情况下:
    • 当标签应用“不转发保护”时,HasDoNotForwardProtection()返回true,无论它是否还包括即席行为。
    • HasEncryptOnlyProtection() true当标签应用“仅加密”保护时返回,无论它是否还包括即席行为。
    • HasAdhocProtection() true仅当标签应用独立的临时保护(不包括不转发或仅加密)时返回。

后续步骤