< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 27
Coverable lines: 27
Total lines: 63
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 16
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
CreateForX509Store(...)0%14140%
CreateForX509Collection(...)0%220%
.ctor()100%110%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Net.Security/src/System/Net/Security/SslCertificateTrust.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.Security.Cryptography.X509Certificates;
 5
 6namespace System.Net.Security
 7{
 8    public sealed class SslCertificateTrust
 9    {
 10        internal X509Store? _store;
 11        internal X509Certificate2Collection? _trustList;
 12        internal bool _sendTrustInHandshake;
 13
 14        public static SslCertificateTrust CreateForX509Store(X509Store store, bool sendTrustInHandshake = false)
 015        {
 16
 17#if TARGET_WINDOWS
 018            if (sendTrustInHandshake && store.Location != StoreLocation.LocalMachine)
 019            {
 020                throw new PlatformNotSupportedException(SR.net_ssl_trust_store);
 21            }
 22#endif
 023            if (sendTrustInHandshake && !System.OperatingSystem.IsLinux() && !System.OperatingSystem.IsMacOS() &&
 024                !System.OperatingSystem.IsWindows())
 025            {
 026                throw new PlatformNotSupportedException(SR.net_ssl_trust_handshake);
 27            }
 028            if (!store.IsOpen)
 029            {
 030                store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
 031            }
 32
 033            var trust = new SslCertificateTrust();
 034            trust._store = store;
 035            trust._sendTrustInHandshake = sendTrustInHandshake;
 036            return trust;
 037        }
 38
 39        public static SslCertificateTrust CreateForX509Collection(X509Certificate2Collection trustList, bool sendTrustIn
 040        {
 41
 42#if TARGET_WINDOWS
 043            if (sendTrustInHandshake)
 044            {
 045                throw new PlatformNotSupportedException(SR.net_ssl_trust_collection);
 46            }
 47#else
 48            if (sendTrustInHandshake && !System.OperatingSystem.IsLinux() && !System.OperatingSystem.IsMacOS())
 49            {
 50                throw new PlatformNotSupportedException(SR.net_ssl_trust_handshake);
 51            }
 52#endif
 53
 054            var trust = new SslCertificateTrust();
 055            trust._trustList = trustList;
 056            trust._sendTrustInHandshake = sendTrustInHandshake;
 057            return trust;
 058        }
 59
 060        private SslCertificateTrust() { }
 61    }
 62}
 63