< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.IdentityModel.Tokens.X509RawDataKeyIdentifierClause
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/Tokens/X509RawDataKeyIdentifierClause.cs
Line coverage
28%
Covered lines: 6
Uncovered lines: 15
Coverable lines: 21
Total lines: 79
Line coverage: 28.5%
Branch coverage
25%
Covered branches: 2
Total branches: 8
Branch coverage: 25%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%110%
.ctor(...)100%110%
.ctor(...)100%11100%
CreateKey()0%440%
GetRawData(...)50%2266.66%
GetX509RawData()100%110%
Matches(...)50%2266.66%
ToString()100%110%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/Tokens/X509RawDataKeyIdentifierClause.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.Globalization;
 5using System.Security.Cryptography.X509Certificates;
 6
 7namespace CoreWCF.IdentityModel.Tokens
 8{
 9    public class X509RawDataKeyIdentifierClause : BinaryKeyIdentifierClause
 10    {
 11        private X509Certificate2 _certificate;
 12        private X509AsymmetricSecurityKey _key;
 13
 14        public X509RawDataKeyIdentifierClause(X509Certificate2 certificate)
 015            : this(GetRawData(certificate), false)
 16        {
 017            _certificate = certificate;
 018        }
 19
 20        public X509RawDataKeyIdentifierClause(byte[] certificateRawData)
 021            : this(certificateRawData, true)
 22        {
 023        }
 24
 25        internal X509RawDataKeyIdentifierClause(byte[] certificateRawData, bool cloneBuffer)
 5026            : base(null, certificateRawData, cloneBuffer)
 27        {
 5028        }
 29
 30        public override bool CanCreateKey
 31        {
 032            get { return true; }
 33        }
 34
 35        public override SecurityKey CreateKey()
 36        {
 037            if (_key == null)
 38            {
 039                if (_certificate == null)
 40                {
 041                    _certificate = new X509Certificate2(GetBuffer());
 42                }
 43
 044                _key = new X509AsymmetricSecurityKey(_certificate);
 45            }
 046            return _key;
 47        }
 48
 49        private static byte[] GetRawData(X509Certificate certificate)
 50        {
 5051            if (certificate == null)
 52            {
 053                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(certificate));
 54            }
 55
 5056            return certificate.GetRawCertData();
 57        }
 58
 59        public byte[] GetX509RawData()
 60        {
 061            return GetBuffer();
 62        }
 63
 64        public bool Matches(X509Certificate2 certificate)
 65        {
 5066            if (certificate == null)
 67            {
 068                return false;
 69            }
 70
 5071            return Matches(GetRawData(certificate));
 72        }
 73
 74        public override string ToString()
 75        {
 076            return string.Format(CultureInfo.InvariantCulture, "X509RawDataKeyIdentifierClause(RawData = {0})", ToBase64
 77        }
 78    }
 79}