Example #1
0
        bool ImportWindowsTransportSecurity(MetadataImporter importer,
                                            PolicyConversionContext context,
                                            XmlElement policyElement)
        {
            var protectionLevel = PolicyImportHelper.GetElement(
                importer, policyElement, "ProtectionLevel",
                PolicyImportHelper.FramingPolicyNS, true);

            if (protectionLevel == null)
            {
                importer.AddWarning(
                    "Invalid policy assertion: {0}", policyElement.OuterXml);
                return(false);
            }

            var element = new WindowsStreamSecurityBindingElement();

            switch (protectionLevel.InnerText.ToLowerInvariant())
            {
            case "none":
                element.ProtectionLevel = ProtectionLevel.None;
                break;

            case "sign":
                element.ProtectionLevel = ProtectionLevel.Sign;
                break;

            case "encryptandsign":
                element.ProtectionLevel = ProtectionLevel.EncryptAndSign;
                break;

            default:
                importer.AddWarning(
                    "Invalid policy assertion: {0}", protectionLevel.OuterXml);
                return(false);
            }

            context.BindingElements.Add(element);
            return(true);
        }