< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.IdentityModel.Tokens.X509SubjectKeyIdentifierClause
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/Tokens/X509SubjectKeyIdentifierClause.cs
Line coverage
47%
Covered lines: 10
Uncovered lines: 11
Coverable lines: 21
Total lines: 74
Line coverage: 47.6%
Branch coverage
40%
Covered branches: 4
Total branches: 10
Branch coverage: 40%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%11100%
.ctor(...)100%11100%
GetSkiRawData(...)50%4460%
GetX509SubjectKeyIdentifier()100%110%
Matches(...)50%4475%
TryCreateFrom(...)0%220%
CanCreateFrom(...)100%110%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/Tokens/X509SubjectKeyIdentifierClause.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;
 5using CoreWCF.Security;
 6
 7namespace CoreWCF.IdentityModel.Tokens
 8{
 9    public class X509SubjectKeyIdentifierClause : BinaryKeyIdentifierClause
 10    {
 11        private const string SubjectKeyIdentifierOid = "2.5.29.14";
 12        private const int SkiDataOffset = 2;
 13
 14        public X509SubjectKeyIdentifierClause(byte[] ski)
 215            : this(ski, true)
 16        {
 217        }
 18
 19        internal X509SubjectKeyIdentifierClause(byte[] ski, bool cloneBuffer)
 220            : base(null, ski, cloneBuffer)
 21        {
 222        }
 23
 24        private static byte[] GetSkiRawData(X509Certificate2 certificate)
 25        {
 326            if (certificate == null)
 27            {
 028                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(certificate));
 29            }
 30
 331            if (certificate.Extensions[SubjectKeyIdentifierOid] is X509SubjectKeyIdentifierExtension skiExtension)
 32            {
 333                return skiExtension.RawData;
 34            }
 35            else
 36            {
 037                return null;
 38            }
 39        }
 40
 41        public byte[] GetX509SubjectKeyIdentifier()
 42        {
 043            return GetBuffer();
 44        }
 45
 46        public bool Matches(X509Certificate2 certificate)
 47        {
 348            if (certificate == null)
 49            {
 050                return false;
 51            }
 52
 353            byte[] data = GetSkiRawData(certificate);
 354            return data != null && Matches(data, SkiDataOffset);
 55        }
 56
 57        public static bool TryCreateFrom(X509Certificate2 certificate, out X509SubjectKeyIdentifierClause keyIdentifierC
 58        {
 059            byte[] data = GetSkiRawData(certificate);
 060            keyIdentifierClause = null;
 061            if (data != null)
 62            {
 063                byte[] ski = SecurityUtils.CloneBuffer(data, SkiDataOffset, data.Length - SkiDataOffset);
 064                keyIdentifierClause = new X509SubjectKeyIdentifierClause(ski, false);
 65            }
 066            return keyIdentifierClause != null;
 67        }
 68
 69        public static bool CanCreateFrom(X509Certificate2 certificate)
 70        {
 071            return null != GetSkiRawData(certificate);
 72        }
 73    }
 74}