< Summary

Information
Class: System.Net.Security.SslClientAuthenticationOptionsExtensions
Assembly: System.Net.Http
File(s): D:\runner\runtime\src\libraries\Common\src\System\Net\Security\SslClientAuthenticationOptionsExtensions.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 56
Coverable lines: 56
Total lines: 87
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 22
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
ShallowClone(...)0%22220%

File(s)

D:\runner\runtime\src\libraries\Common\src\System\Net\Security\SslClientAuthenticationOptionsExtensions.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.Generic;
 5#if DEBUG
 6using System.Collections;
 7using System.Diagnostics;
 8using System.Reflection;
 9#endif
 10
 11namespace System.Net.Security
 12{
 13    internal static class SslClientAuthenticationOptionsExtensions
 14    {
 15        public static SslClientAuthenticationOptions ShallowClone(this SslClientAuthenticationOptions options)
 016        {
 17            // Use non-default values to verify the clone works fine.
 018            var clone = new SslClientAuthenticationOptions()
 019            {
 020                AllowRenegotiation = options.AllowRenegotiation,
 021                AllowTlsResume = options.AllowTlsResume,
 022                ApplicationProtocols = options.ApplicationProtocols != null ? new List<SslApplicationProtocol>(options.A
 023                CertificateRevocationCheckMode = options.CertificateRevocationCheckMode,
 024                CertificateChainPolicy = options.CertificateChainPolicy,
 025                CipherSuitesPolicy = options.CipherSuitesPolicy,
 026                ClientCertificates = options.ClientCertificates,
 027                ClientCertificateContext = options.ClientCertificateContext,
 028                EnabledSslProtocols = options.EnabledSslProtocols,
 029                EncryptionPolicy = options.EncryptionPolicy,
 030                LocalCertificateSelectionCallback = options.LocalCertificateSelectionCallback,
 031                RemoteCertificateValidationCallback = options.RemoteCertificateValidationCallback,
 032                TargetHost = options.TargetHost,
 033#pragma warning disable CA1416 // Ignore SupportedOSPlatform checks, the value will be validated at runtime inside SslSt
 034                AllowRsaPssPadding = options.AllowRsaPssPadding,
 035                AllowRsaPkcs1Padding = options.AllowRsaPkcs1Padding
 036#pragma warning restore CA1416
 037            };
 38
 39#if DEBUG
 40            // Try to detect if a property gets added that we're not copying correctly.
 41            // The property count is guard for new properties that also needs to be added above.
 042            PropertyInfo[] properties = typeof(SslClientAuthenticationOptions).GetProperties(BindingFlags.Public | Bindi
 043            Debug.Assert(properties.Length == 15);
 044            foreach (PropertyInfo pi in properties)
 045            {
 046                object? origValue = pi.GetValue(options);
 047                object? cloneValue = pi.GetValue(clone);
 48
 049                if (origValue is IEnumerable origEnumerable)
 050                {
 051                    IEnumerable? cloneEnumerable = cloneValue as IEnumerable;
 052                    Debug.Assert(cloneEnumerable != null, $"{pi.Name}. Expected enumerable cloned value.");
 53
 054                    IEnumerator e1 = origEnumerable.GetEnumerator();
 55                    try
 056                    {
 057                        IEnumerator e2 = cloneEnumerable.GetEnumerator();
 58                        try
 059                        {
 060                            while (e1.MoveNext())
 061                            {
 062                                Debug.Assert(e2.MoveNext(), $"{pi.Name}. Cloned enumerator too short.");
 063                                Debug.Assert(Equals(e1.Current, e2.Current), $"{pi.Name}. Cloned enumerator's values don
 064                            }
 065                            Debug.Assert(!e2.MoveNext(), $"{pi.Name}. Cloned enumerator too long.");
 066                        }
 67                        finally
 068                        {
 069                            (e2 as IDisposable)?.Dispose();
 070                        }
 071                    }
 72                    finally
 073                    {
 074                        (e1 as IDisposable)?.Dispose();
 075                    }
 076                }
 77                else
 078                {
 079                    Debug.Assert(Equals(origValue, cloneValue), $"{pi.Name}. Expected: {origValue}, Actual: {cloneValue}
 080                }
 081            }
 82#endif
 83
 084            return clone;
 085        }
 86    }
 87}