< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.IdentityModel.Tokens.X509ThumbprintKeyIdentifierClause
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/Tokens/X509ThumbprintKeyIdentifierClause.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 14
Coverable lines: 14
Total lines: 56
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 4
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(...)100%110%
.ctor(...)100%110%
.ctor(...)100%110%
GetHash(...)0%220%
GetX509Thumbprint()100%110%
Matches(...)0%220%
ToString()100%110%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/Tokens/X509ThumbprintKeyIdentifierClause.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 X509ThumbprintKeyIdentifierClause : BinaryKeyIdentifierClause
 10    {
 11        public X509ThumbprintKeyIdentifierClause(X509Certificate2 certificate)
 012            : this(GetHash(certificate), false)
 13        {
 014        }
 15
 16        public X509ThumbprintKeyIdentifierClause(byte[] thumbprint)
 017            : this(thumbprint, true)
 18        {
 019        }
 20
 21        internal X509ThumbprintKeyIdentifierClause(byte[] thumbprint, bool cloneBuffer)
 022            : base(null, thumbprint, cloneBuffer)
 23        {
 024        }
 25
 26        private static byte[] GetHash(X509Certificate2 certificate)
 27        {
 028            if (certificate == null)
 29            {
 030                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(certificate));
 31            }
 32            //TODO  switch to stronger hash algorithm once we're no longer on netstandard2.0
 033            return certificate.GetCertHash();
 34        }
 35
 36        public byte[] GetX509Thumbprint()
 37        {
 038            return GetBuffer();
 39        }
 40
 41        public bool Matches(X509Certificate2 certificate)
 42        {
 043            if (certificate == null)
 44            {
 045                return false;
 46            }
 47
 048            return Matches(GetHash(certificate));
 49        }
 50
 51        public override string ToString()
 52        {
 053            return string.Format(CultureInfo.InvariantCulture, "X509ThumbprintKeyIdentifierClause(Hash = 0x{0})", ToHexS
 54        }
 55    }
 56}