< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Security.DataProtectionSecurityStateEncoder
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Security/DataProtectionSecurityStateEncoder.cs
Line coverage
26%
Covered lines: 8
Uncovered lines: 22
Coverable lines: 30
Total lines: 83
Line coverage: 26.6%
Branch coverage
10%
Covered branches: 1
Total branches: 10
Branch coverage: 10%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor()100%11100%
.ctor(...)100%11100%
.ctor(...)50%2257.14%
GetEntropy()0%220%
ToString()0%220%
DecodeSecurityState(...)0%220%
EncodeSecurityState(...)0%220%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Security/DataProtectionSecurityStateEncoder.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;
 6using System.Text;
 7using CoreWCF.Runtime;
 8
 9namespace CoreWCF.Security
 10{
 11    public class DataProtectionSecurityStateEncoder : SecurityStateEncoder
 12    {
 13        private readonly byte[] _entropy;
 14
 6115        public DataProtectionSecurityStateEncoder() : this(true)
 16        {
 17            // empty
 6118        }
 19
 6120        public DataProtectionSecurityStateEncoder(bool useCurrentUserProtectionScope) : this(useCurrentUserProtectionSco
 6121        { }
 22
 6123        public DataProtectionSecurityStateEncoder(bool useCurrentUserProtectionScope, byte[] entropy)
 24        {
 6125            UseCurrentUserProtectionScope = useCurrentUserProtectionScope;
 6126            if (entropy == null)
 27            {
 6128                _entropy = null;
 29            }
 30            else
 31            {
 032                _entropy = Fx.AllocateByteArray(entropy.Length);
 033                Buffer.BlockCopy(entropy, 0, _entropy, 0, entropy.Length);
 34            }
 035        }
 36
 037        public bool UseCurrentUserProtectionScope { get; }
 38
 39        public byte[] GetEntropy()
 40        {
 041            byte[] result = null;
 042            if (_entropy != null)
 43            {
 044                result = Fx.AllocateByteArray(_entropy.Length);
 045                Buffer.BlockCopy(_entropy, 0, result, 0, _entropy.Length);
 46            }
 047            return result;
 48        }
 49
 50        public override string ToString()
 51        {
 052            StringBuilder result = new StringBuilder();
 053            result.Append(GetType().ToString());
 054            result.AppendFormat("{0}  UseCurrentUserProtectionScope={1}", Environment.NewLine, UseCurrentUserProtectionS
 055            result.AppendFormat("{0}  Entropy Length={1}", Environment.NewLine, (_entropy == null) ? 0 : _entropy.Length
 056            return result.ToString();
 57        }
 58
 59        protected internal override byte[] DecodeSecurityState(byte[] data)
 60        {
 61            try
 62            {
 063                return ProtectedData.Unprotect(data, _entropy, (UseCurrentUserProtectionScope) ? DataProtectionScope.Cur
 64            }
 065            catch (CryptographicException exception)
 66            {
 067                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CryptographicException(SR.SecurityStateEnc
 68            }
 069        }
 70
 71        protected internal override byte[] EncodeSecurityState(byte[] data)
 72        {
 73            try
 74            {
 075                return ProtectedData.Protect(data, _entropy, (UseCurrentUserProtectionScope) ? DataProtectionScope.Curre
 76            }
 077            catch (CryptographicException exception)
 78            {
 079                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CryptographicException(SR.SecurityStateEnc
 80            }
 081        }
 82    }
 83}