< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.IdentityModel.CanonicalFormWriter
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Security/CanonicalFormWriter.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 31
Coverable lines: 31
Total lines: 80
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 12
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%
EncodeAndWrite(...)0%660%
EncodeAndWrite(...)100%110%
EncodeAndWrite(...)0%660%
EncodeAndWrite(...)100%110%
EncodeAndWrite(...)100%110%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Security/CanonicalFormWriter.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.Text;
 6
 7namespace CoreWCF.IdentityModel
 8{
 9    internal abstract class CanonicalFormWriter
 10    {
 011        internal static readonly Encoding Utf8WithoutPreamble = Encoding.UTF8;
 12
 13        protected static void EncodeAndWrite(Stream stream, byte[] workBuffer, string s)
 14        {
 015            if (s.Length > workBuffer.Length)
 16            {
 017                EncodeAndWrite(stream, s);
 018                return;
 19            }
 20
 021            for (int i = 0; i < s.Length; i++)
 22            {
 023                char c = s[i];
 024                if (c < 127)
 25                {
 026                    workBuffer[i] = (byte)c;
 27                }
 28                else
 29                {
 030                    EncodeAndWrite(stream, s);
 031                    return;
 32                }
 33            }
 34
 035            stream.Write(workBuffer, 0, s.Length);
 036        }
 37
 38        protected static void EncodeAndWrite(Stream stream, byte[] workBuffer, char[] chars)
 39        {
 040            EncodeAndWrite(stream, workBuffer, chars, chars.Length);
 041        }
 42
 43        protected static void EncodeAndWrite(Stream stream, byte[] workBuffer, char[] chars, int count)
 44        {
 045            if (count > workBuffer.Length)
 46            {
 047                EncodeAndWrite(stream, chars, count);
 048                return;
 49            }
 50
 051            for (int i = 0; i < count; i++)
 52            {
 053                char c = chars[i];
 054                if (c < 127)
 55                {
 056                    workBuffer[i] = (byte)c;
 57                }
 58                else
 59                {
 060                    EncodeAndWrite(stream, chars, count);
 061                    return;
 62                }
 63            }
 64
 065            stream.Write(workBuffer, 0, count);
 066        }
 67
 68        private static void EncodeAndWrite(Stream stream, string s)
 69        {
 070            byte[] buffer = Utf8WithoutPreamble.GetBytes(s);
 071            stream.Write(buffer, 0, buffer.Length);
 072        }
 73
 74        private static void EncodeAndWrite(Stream stream, char[] chars, int count)
 75        {
 076            byte[] buffer = Utf8WithoutPreamble.GetBytes(chars, 0, count);
 077            stream.Write(buffer, 0, buffer.Length);
 078        }
 79    }
 80}