< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 15
Coverable lines: 15
Total lines: 111
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 6
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
SetNextBuffer(...)0%660%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/Common/src/System/Net/Security/SecurityBuffer.Windows.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.Diagnostics;
 5using System.Runtime.InteropServices;
 6using System.Security.Authentication.ExtendedProtection;
 7
 8namespace System.Net.Security
 9{
 10    [StructLayout(LayoutKind.Sequential)]
 11    internal ref struct InputSecurityBuffers
 12    {
 13        internal int Count;
 14        internal InputSecurityBuffer _item0;
 15        internal InputSecurityBuffer _item1;
 16        internal InputSecurityBuffer _item2;
 17
 18        internal void SetNextBuffer(InputSecurityBuffer buffer)
 019        {
 020            Debug.Assert(Count >= 0 && Count < 3);
 021            if (Count == 0)
 022            {
 023                _item0 = buffer;
 024            }
 025            else if (Count == 1)
 026            {
 027                _item1 = buffer;
 028            }
 29            else
 030            {
 031                _item2 = buffer;
 032            }
 33
 034            Count++;
 035        }
 36    }
 37
 38    [StructLayout(LayoutKind.Auto)]
 39    internal ref struct InputSecurityBuffer
 40    {
 41        public SecurityBufferType Type;
 42        public ReadOnlySpan<byte> Token;
 43        public SafeHandle? UnmanagedToken;
 44
 45        public InputSecurityBuffer(ReadOnlySpan<byte> data, SecurityBufferType tokentype)
 46        {
 47            Token = data;
 48            Type = tokentype;
 49            UnmanagedToken = null;
 50        }
 51
 52        public InputSecurityBuffer(ChannelBinding binding)
 53        {
 54            Type = SecurityBufferType.SECBUFFER_CHANNEL_BINDINGS;
 55            Token = default;
 56            UnmanagedToken = binding;
 57        }
 58    }
 59
 60    [StructLayout(LayoutKind.Auto)]
 61    internal struct SecurityBuffer
 62    {
 63        public int offset;
 64        public int size;
 65        public SecurityBufferType type;
 66        public byte[]? token;
 67        public SafeHandle? unmanagedToken;
 68
 69        public SecurityBuffer(byte[]? data, int offset, int size, SecurityBufferType tokentype)
 70        {
 71            Debug.Assert(offset >= 0 && offset <= (data == null ? 0 : data.Length), $"'offset' out of range.  [{offset}]
 72            Debug.Assert(size >= 0 && size <= (data == null ? 0 : data.Length - offset), $"'size' out of range.  [{size}
 73
 74            this.offset = data == null || offset < 0 ? 0 : Math.Min(offset, data.Length);
 75            this.size = data == null || size < 0 ? 0 : Math.Min(size, data.Length - this.offset);
 76            this.type = tokentype;
 77            this.token = size == 0 ? null : data;
 78            this.unmanagedToken = null;
 79        }
 80
 81        public SecurityBuffer(byte[]? data, SecurityBufferType tokentype)
 82        {
 83            this.offset = 0;
 84            this.size = data == null ? 0 : data.Length;
 85            this.type = tokentype;
 86            this.token = size == 0 ? null : data;
 87            this.unmanagedToken = null;
 88        }
 89
 90        public SecurityBuffer(int size, SecurityBufferType tokentype)
 91        {
 92            Debug.Assert(size >= 0, $"'size' out of range.  [{size}]");
 93
 94            this.offset = 0;
 95            this.size = size;
 96            this.type = tokentype;
 97            this.token = size == 0 ? null : new byte[size];
 98            this.unmanagedToken = null;
 99        }
 100
 101        public SecurityBuffer(ChannelBinding binding)
 102        {
 103            this.offset = 0;
 104            this.size = (binding == null ? 0 : binding.Size);
 105            this.type = SecurityBufferType.SECBUFFER_CHANNEL_BINDINGS;
 106            this.token = null;
 107            this.unmanagedToken = binding;
 108        }
 109    }
 110}
 111