< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.IdentityModel.Tokens.RsaKeyIdentifierClause
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/Tokens/RsaKeyIdentifierClause.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 30
Coverable lines: 30
Total lines: 94
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 16
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.cctor()100%110%
.ctor(...)0%220%
CreateKey()0%220%
GetExponent()100%110%
GetModulus()100%110%
Matches(...)0%440%
Matches(...)0%440%
ToString()100%110%
WriteExponentAsBase64(...)0%220%
WriteModulusAsBase64(...)0%220%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/Tokens/RsaKeyIdentifierClause.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.Globalization;
 6using System.Security.Cryptography;
 7using System.Xml;
 8using CoreWCF.Security;
 9
 10namespace CoreWCF.IdentityModel.Tokens
 11{
 12    public class RsaKeyIdentifierClause : SecurityKeyIdentifierClause
 13    {
 014        private static readonly string s_clauseType = XmlSignatureStrings.Namespace + XmlSignatureStrings.RsaKeyValue;
 15        private readonly RSAParameters _rsaParameters;
 16        private RsaSecurityKey _rsaSecurityKey;
 17
 18        public RsaKeyIdentifierClause(RSA rsa)
 019            : base(s_clauseType)
 20        {
 021            Rsa = rsa ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(rsa));
 022            _rsaParameters = rsa.ExportParameters(false);
 023        }
 24
 25        public override bool CanCreateKey
 26        {
 027            get { return true; }
 28        }
 29
 030        public RSA Rsa { get; }
 31
 32        public override SecurityKey CreateKey()
 33        {
 034            if (_rsaSecurityKey == null)
 35            {
 036                _rsaSecurityKey = new RsaSecurityKey(Rsa);
 37            }
 038            return _rsaSecurityKey;
 39        }
 40
 41        public byte[] GetExponent()
 42        {
 043            return SecurityUtils.CloneBuffer(_rsaParameters.Exponent);
 44        }
 45
 46        public byte[] GetModulus()
 47        {
 048            return SecurityUtils.CloneBuffer(_rsaParameters.Modulus);
 49        }
 50
 51        public override bool Matches(SecurityKeyIdentifierClause keyIdentifierClause)
 52        {
 053            RsaKeyIdentifierClause that = keyIdentifierClause as RsaKeyIdentifierClause;
 054            return ReferenceEquals(this, that) || (that != null && that.Matches(Rsa));
 55        }
 56
 57        public bool Matches(RSA rsa)
 58        {
 059            if (rsa == null)
 60            {
 061                return false;
 62            }
 63
 064            RSAParameters rsaParameters = rsa.ExportParameters(false);
 065            return SecurityUtils.MatchesBuffer(_rsaParameters.Modulus, rsaParameters.Modulus) &&
 066                SecurityUtils.MatchesBuffer(_rsaParameters.Exponent, rsaParameters.Exponent);
 67        }
 68
 69        public override string ToString()
 70        {
 071            return string.Format(CultureInfo.InvariantCulture, "RsaKeyIdentifierClause(Modulus = {0}, Exponent = {1})",
 072                Convert.ToBase64String(_rsaParameters.Modulus),
 073                Convert.ToBase64String(_rsaParameters.Exponent));
 74        }
 75
 76        public void WriteExponentAsBase64(XmlWriter writer)
 77        {
 078            if (writer == null)
 79            {
 080                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(writer));
 81            }
 082            writer.WriteBase64(_rsaParameters.Exponent, 0, _rsaParameters.Exponent.Length);
 083        }
 84
 85        public void WriteModulusAsBase64(XmlWriter writer)
 86        {
 087            if (writer == null)
 88            {
 089                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(writer));
 90            }
 091            writer.WriteBase64(_rsaParameters.Modulus, 0, _rsaParameters.Modulus.Length);
 092        }
 93    }
 94}