< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.IdentityModel.SignatureResourcePool
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/SignatureResourcePool.cs
Line coverage
38%
Covered lines: 8
Uncovered lines: 13
Coverable lines: 21
Total lines: 89
Line coverage: 38%
Branch coverage
25%
Covered branches: 3
Total branches: 12
Branch coverage: 25%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
TakeBase64Buffer()0%220%
TakeEncodingBuffer()0%220%
TakeHashAlgorithm(...)50%4466.66%
TakeHashStream(...)50%2275%
TakeHashStream(...)100%11100%
TakeUtf8Writer()0%220%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/SignatureResourcePool.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.IO;
 5using System.Security.Cryptography;
 6using System.Text;
 7using System.Xml;
 8
 9namespace CoreWCF.IdentityModel
 10{
 11    // for sequential use by one thread
 12    internal sealed class SignatureResourcePool
 13    {
 14        private const int BufferSize = 64;
 15        private HashStream _hashStream;
 16        private HashAlgorithm _hashAlgorithm;
 17        private XmlDictionaryWriter _utf8Writer;
 18        private byte[] _encodingBuffer;
 19        private char[] _base64Buffer;
 20
 21        public char[] TakeBase64Buffer()
 22        {
 023            if (_base64Buffer == null)
 24            {
 025                _base64Buffer = new char[BufferSize];
 26            }
 027            return _base64Buffer;
 28        }
 29
 30        public byte[] TakeEncodingBuffer()
 31        {
 032            if (_encodingBuffer == null)
 33            {
 034                _encodingBuffer = new byte[BufferSize];
 35            }
 036            return _encodingBuffer;
 37        }
 38
 39        public HashAlgorithm TakeHashAlgorithm(string algorithm)
 40        {
 2341            if (_hashAlgorithm == null)
 42            {
 2343                if (string.IsNullOrEmpty(algorithm))
 44                {
 045                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(algorithm, SR.Format("EmptyOrNullArgume
 46                }
 47
 2348                _hashAlgorithm = CryptoHelper.CreateHashAlgorithm(algorithm);
 49            }
 50            else
 51            {
 052                _hashAlgorithm.Initialize();
 53            }
 54
 2355            return _hashAlgorithm;
 56        }
 57
 58        public HashStream TakeHashStream(HashAlgorithm hash)
 59        {
 2360            if (_hashStream == null)
 61            {
 2362                _hashStream = new HashStream(hash);
 63            }
 64            else
 65            {
 066                _hashStream.Reset(hash);
 67            }
 2368            return _hashStream;
 69        }
 70
 71        public HashStream TakeHashStream(string algorithm)
 72        {
 2373            return TakeHashStream(TakeHashAlgorithm(algorithm));
 74        }
 75
 76        public XmlDictionaryWriter TakeUtf8Writer()
 77        {
 078            if (_utf8Writer == null)
 79            {
 080                _utf8Writer = XmlDictionaryWriter.CreateTextWriter(Stream.Null, Encoding.UTF8, false);
 81            }
 82            else
 83            {
 084                ((IXmlTextWriterInitializer)_utf8Writer).SetOutput(Stream.Null, Encoding.UTF8, false);
 85            }
 086            return _utf8Writer;
 87        }
 88    }
 89}