< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 81
Coverable lines: 81
Total lines: 159
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 20
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)0%660%
.ctor(...)0%220%
.ctor(...)0%220%
.ctor(...)100%110%
.ctor(...)100%110%
System.Runtime.Serialization.ISerializable.GetObjectData(...)100%110%
ToString()0%880%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Net.Security/src/System/Security/Authentication/ExtendedProtection/ExtendedProtectionPolicy.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.Collections;
 5using System.ComponentModel;
 6using System.Runtime.InteropServices;
 7using System.Runtime.Serialization;
 8using System.Text;
 9
 10namespace System.Security.Authentication.ExtendedProtection
 11{
 12    /// <summary>
 13    /// This class contains the necessary settings for specifying how Extended Protection
 14    /// should behave. Use one of the Build* methods to create an instance of this type.
 15    /// </summary>
 16    public class ExtendedProtectionPolicy : ISerializable
 17    {
 18        private readonly ServiceNameCollection? _customServiceNames;
 19        private readonly PolicyEnforcement _policyEnforcement;
 20        private readonly ProtectionScenario _protectionScenario;
 21        private readonly ChannelBinding? _customChannelBinding;
 22
 023        public ExtendedProtectionPolicy(PolicyEnforcement policyEnforcement,
 024                                        ProtectionScenario protectionScenario,
 025                                        ServiceNameCollection? customServiceNames)
 026        {
 027            if (policyEnforcement == PolicyEnforcement.Never)
 028            {
 029                throw new ArgumentException(SR.security_ExtendedProtectionPolicy_UseDifferentConstructorForNever, nameof
 30            }
 31
 032            if (customServiceNames != null && customServiceNames.Count == 0)
 033            {
 034                throw new ArgumentException(SR.security_ExtendedProtectionPolicy_NoEmptyServiceNameCollection, nameof(cu
 35            }
 36
 037            _policyEnforcement = policyEnforcement;
 038            _protectionScenario = protectionScenario;
 039            _customServiceNames = customServiceNames;
 040        }
 41
 42        public ExtendedProtectionPolicy(PolicyEnforcement policyEnforcement,
 43                                        ProtectionScenario protectionScenario,
 44                                        ICollection? customServiceNames)
 045            : this(policyEnforcement, protectionScenario,
 046                   customServiceNames == null ? (ServiceNameCollection?)null : new ServiceNameCollection(customServiceNa
 047        {
 048        }
 49
 050        public ExtendedProtectionPolicy(PolicyEnforcement policyEnforcement,
 051                                        ChannelBinding customChannelBinding)
 052        {
 053            if (policyEnforcement == PolicyEnforcement.Never)
 054            {
 055                throw new ArgumentException(SR.security_ExtendedProtectionPolicy_UseDifferentConstructorForNever, nameof
 56            }
 057            ArgumentNullException.ThrowIfNull(customChannelBinding);
 58
 059            _policyEnforcement = policyEnforcement;
 060            _protectionScenario = ProtectionScenario.TransportSelected;
 061            _customChannelBinding = customChannelBinding;
 062        }
 63
 064        public ExtendedProtectionPolicy(PolicyEnforcement policyEnforcement)
 065        {
 66            // This is the only constructor which allows PolicyEnforcement.Never.
 067            _policyEnforcement = policyEnforcement;
 068            _protectionScenario = ProtectionScenario.TransportSelected;
 069        }
 70
 71        [Obsolete(Obsoletions.LegacyFormatterImplMessage, DiagnosticId = Obsoletions.LegacyFormatterImplDiagId, UrlForma
 72        [EditorBrowsable(EditorBrowsableState.Never)]
 073        protected ExtendedProtectionPolicy(SerializationInfo info, StreamingContext context)
 074        {
 075            throw new PlatformNotSupportedException();
 76        }
 77
 78        void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
 079        {
 080            throw new PlatformNotSupportedException();
 81        }
 82
 83        public ServiceNameCollection? CustomServiceNames
 84        {
 085            get { return _customServiceNames; }
 86        }
 87
 88        public PolicyEnforcement PolicyEnforcement
 89        {
 090            get { return _policyEnforcement; }
 91        }
 92
 93        public ProtectionScenario ProtectionScenario
 94        {
 095            get { return _protectionScenario; }
 96        }
 97
 98        public ChannelBinding? CustomChannelBinding
 99        {
 0100            get { return _customChannelBinding; }
 101        }
 102
 103        public override string ToString()
 0104        {
 0105            StringBuilder sb = new StringBuilder();
 0106            sb.Append("ProtectionScenario=");
 0107            sb.Append($"{_protectionScenario}");
 0108            sb.Append("; PolicyEnforcement=");
 0109            sb.Append($"{_policyEnforcement}");
 110
 0111            sb.Append("; CustomChannelBinding=");
 0112            if (_customChannelBinding == null)
 0113            {
 0114                sb.Append("<null>");
 0115            }
 116            else
 0117            {
 0118                sb.Append(_customChannelBinding.ToString());
 0119            }
 120
 0121            sb.Append("; ServiceNames=");
 0122            if (_customServiceNames == null)
 0123            {
 0124                sb.Append("<null>");
 0125            }
 126            else
 0127            {
 0128                bool first = true;
 0129                foreach (string serviceName in _customServiceNames)
 0130                {
 0131                    if (first)
 0132                    {
 0133                        first = false;
 0134                    }
 135                    else
 0136                    {
 0137                        sb.Append(", ");
 0138                    }
 139
 0140                    sb.Append(serviceName);
 0141                }
 0142            }
 143
 0144            return sb.ToString();
 0145        }
 146
 147        public static bool OSSupportsExtendedProtection
 148        {
 149            get
 0150            {
 151                // ExtendedProtection is supported on all Windows versions supported by current .NET version.
 152                // Linux is supported via GSSAPI (Managed implements only client-side).
 153                // MacOS's Heimdal-derived GSS.framework does not reject a channel binding mismatch (the exchange comple
 0154                return OperatingSystem.IsWindows() || OperatingSystem.IsLinux();
 0155            }
 156        }
 157    }
 158}
 159