< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.IdentityModel.Tokens.Saml.SecurityTokenReference
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/Tokens/Saml/SecurityTokenReference.cs
Line coverage
18%
Covered lines: 4
Uncovered lines: 18
Coverable lines: 22
Total lines: 83
Line coverage: 18.1%
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(...)100%11100%
MatchesKey(...)0%10100%
Equals(...)0%10100%
GetHashCode()0%220%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/Tokens/Saml/SecurityTokenReference.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;
 6
 7namespace CoreWCF.IdentityModel.Tokens.Saml
 8{
 9    /// <summary>
 10    /// Represents the SecurityTokenReference property of X509Data as per:  https://www.w3.org/TR/2001/PR-xmldsig-core-2
 11    /// </summary>
 12    public class SecurityTokenReference
 13    {
 14        /// <summary>
 15        /// Creates an IssuerSerial using the specified IssuerName and SerialNumber.
 16        /// </summary>
 317        public SecurityTokenReference(SecurityKeyIdentifier securityKeyIdentifier)
 18        {
 319            SecurityKeyIdentifier = securityKeyIdentifier;
 320        }
 21
 22        /// <summary>
 23        /// Gets the SecurityKeyIdentifier
 24        /// </summary>
 1025        public SecurityKeyIdentifier SecurityKeyIdentifier { get; }
 26
 27        /// <summary>
 28        /// Compares two SecurityTokenReference instances.
 29        /// </summary>
 30        /// <param name="securityKey"></param>
 31        /// <returns></returns>
 32        public bool MatchesKey(Microsoft.IdentityModel.Tokens.SecurityKey securityKey)
 33        {
 034            if (securityKey == null)
 035                return false;
 36
 037            if (SecurityKeyIdentifier == null)
 038                return false;
 39
 040            if (securityKey is Microsoft.IdentityModel.Tokens.X509SecurityKey x509SecurityKey)
 41            {
 042                X509SubjectKeyIdentifierExtension skiExtension = x509SecurityKey.Certificate.Extensions["2.5.29.14"] as 
 043                if (skiExtension == null)
 044                    return false;
 45
 46                // TODO: skiExtension.SecurityKeyIdentifier.Value is base64 encoded, skiExtension.RawData is not
 47
 048                return SecurityKeyIdentifier?.Value == Convert.ToBase64String(skiExtension.RawData, 2, skiExtension.RawD
 49            }
 50
 051            return false;
 52        }
 53
 54        /// <summary>
 55        /// Determines whether the specified object is equal to the current object.
 56        /// </summary>
 57        /// <param name="obj">The object to compare with the current object.</param>
 58        /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns>
 59        public override bool Equals(object obj)
 60        {
 061            if (obj == null)
 062                return false;
 63
 064            if (ReferenceEquals(this, obj))
 065                return true;
 66
 067            if (obj is SecurityTokenReference other)
 068                return SecurityKeyIdentifier?.Value == other.SecurityKeyIdentifier?.Value;
 69
 070            return false;
 71        }
 72
 73        /// <summary>
 74        /// Serves as the default hash function.
 75        /// </summary>
 76        /// <returns>A hash code for the current object.</returns>
 77        public override int GetHashCode()
 78        {
 079            return SecurityKeyIdentifier?.GetHashCode() ?? 0;
 80        }
 81    }
 82}
 83