< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.X509CertificateEndpointIdentity
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/X509CertificateEndpointIdentity.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 42
Coverable lines: 42
Total lines: 101
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
.ctor(...)0%220%
.ctor(...)0%660%
.ctor(...)0%10100%
WriteContentsTo(...)0%440%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/X509CertificateEndpointIdentity.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;
 5using System.Security.Cryptography.X509Certificates;
 6using System.Xml;
 7using CoreWCF.IdentityModel.Claims;
 8
 9namespace CoreWCF
 10{
 11    public class X509CertificateEndpointIdentity : EndpointIdentity
 12    {
 013        public X509CertificateEndpointIdentity(X509Certificate2 certificate)
 14        {
 015            if (certificate == null)
 16            {
 017                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(certificate));
 18            }
 19
 020            Initialize(new Claim(ClaimTypes.Thumbprint, certificate.GetCertHash(), Rights.PossessProperty));
 21
 022            Certificates.Add(certificate);
 023        }
 24
 025        public X509CertificateEndpointIdentity(X509Certificate2 primaryCertificate, X509Certificate2Collection supportin
 26        {
 027            if (primaryCertificate == null)
 28            {
 029                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(primaryCertificate));
 30            }
 31
 032            if (supportingCertificates == null)
 33            {
 034                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(supportingCertificates));
 35            }
 36
 037            Initialize(new Claim(ClaimTypes.Thumbprint, primaryCertificate.GetCertHash(), Rights.PossessProperty));
 38
 039            Certificates.Add(primaryCertificate);
 40
 041            for (int i = 0; i < supportingCertificates.Count; ++i)
 42            {
 043                Certificates.Add(supportingCertificates[i]);
 44            }
 045        }
 46
 047        internal X509CertificateEndpointIdentity(XmlDictionaryReader reader)
 48        {
 049            if (reader == null)
 50            {
 051                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(reader));
 52            }
 53
 054            reader.MoveToContent();
 055            if (reader.IsEmptyElement)
 56            {
 057                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.Format(SR.UnexpectedEmptyE
 58            }
 59
 060            reader.ReadStartElement(XD.XmlSignatureDictionary.X509Data, XD.XmlSignatureDictionary.Namespace);
 061            while (reader.IsStartElement(XD.XmlSignatureDictionary.X509Certificate, XD.XmlSignatureDictionary.Namespace)
 62            {
 063                X509Certificate2 certificate = new X509Certificate2(Convert.FromBase64String(reader.ReadElementString())
 064                if (Certificates.Count == 0)
 65                {
 66                    // This is the first certificate. We assume this as the primary
 67                    // certificate and initialize the base class.
 068                    Initialize(new Claim(ClaimTypes.Thumbprint, certificate.GetCertHash(), Rights.PossessProperty));
 69                }
 70
 071                Certificates.Add(certificate);
 72            }
 73
 074            reader.ReadEndElement();
 75
 076            if (Certificates.Count == 0)
 77            {
 078                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.Format(SR.UnexpectedEmptyE
 79            }
 080        }
 81
 082        public X509Certificate2Collection Certificates { get; } = new X509Certificate2Collection();
 83
 84        internal override void WriteContentsTo(XmlDictionaryWriter writer)
 85        {
 086            if (writer == null)
 87            {
 088                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(writer));
 89            }
 90
 091            writer.WriteStartElement(XD.XmlSignatureDictionary.Prefix.Value, XD.XmlSignatureDictionary.KeyInfo, XD.XmlSi
 092            writer.WriteStartElement(XD.XmlSignatureDictionary.Prefix.Value, XD.XmlSignatureDictionary.X509Data, XD.XmlS
 093            for (int i = 0; i < Certificates.Count; ++i)
 94            {
 095                writer.WriteElementString(XD.XmlSignatureDictionary.X509Certificate, XD.XmlSignatureDictionary.Namespace
 96            }
 097            writer.WriteEndElement();
 098            writer.WriteEndElement();
 099        }
 100    }
 101}