< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.IdentityModel.CipherDataElement
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/CipherDataElement.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 33
Coverable lines: 33
Total lines: 83
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 8
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
ReadXml(...)0%440%
SetCipherValueFragments(...)100%110%
WriteXml(...)0%220%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/CipherDataElement.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.Xml;
 6
 7namespace CoreWCF.IdentityModel
 8{
 9    internal class CipherDataElement
 10    {
 11        private byte[] _iv;
 12        private byte[] _cipherText;
 13
 14        public byte[] CipherValue
 15        {
 16            get
 17            {
 018                if ( _iv != null )
 19                {
 020                    byte[] buffer = new byte[_iv.Length + _cipherText.Length];
 021                    Buffer.BlockCopy( _iv, 0, buffer, 0, _iv.Length );
 022                    Buffer.BlockCopy( _cipherText, 0, buffer, _iv.Length, _cipherText.Length );
 023                    _iv = null;
 24                }
 25
 026                return _cipherText;
 27            }
 28            set
 29            {
 030                _cipherText = value;
 031            }
 32        }
 33
 34        public void ReadXml( XmlDictionaryReader reader )
 35        {
 036            if ( reader == null )
 37            {
 038                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(reader));
 39            }
 40
 041            reader.MoveToContent();
 042            if ( !reader.IsStartElement( XmlEncryptionConstants.Elements.CipherData, XmlEncryptionConstants.Namespace ) 
 43            {
 044                throw DiagnosticUtility.ExceptionUtility.ThrowHelperXml( reader, SR.Format( SR.ID4188 ) );
 45            }
 46
 047            reader.ReadStartElement( XmlEncryptionConstants.Elements.CipherData, XmlEncryptionConstants.Namespace );
 048            reader.ReadStartElement( XmlEncryptionConstants.Elements.CipherValue, XmlEncryptionConstants.Namespace );
 49
 050            _cipherText = reader.ReadContentAsBase64();
 051            _iv         = null;
 52
 53            // <CipherValue>
 054            reader.MoveToContent();
 055            reader.ReadEndElement();
 56
 57
 58            // <CipherData>
 059            reader.MoveToContent();
 060            reader.ReadEndElement();
 061        }
 62
 63        public void SetCipherValueFragments( byte[] iv, byte[] cipherText )
 64        {
 065            _iv         = iv;
 066            _cipherText = cipherText;
 067        }
 68
 69        public void WriteXml( XmlWriter writer )
 70        {
 071            writer.WriteStartElement( XmlEncryptionConstants.Prefix, XmlEncryptionConstants.Elements.CipherData, XmlEncr
 072            writer.WriteStartElement( XmlEncryptionConstants.Prefix, XmlEncryptionConstants.Elements.CipherValue, XmlEnc
 73
 074            if ( _iv != null )
 075                writer.WriteBase64( _iv, 0, _iv.Length );
 76
 077            writer.WriteBase64( _cipherText, 0, _cipherText.Length );
 78
 079            writer.WriteEndElement(); // CipherValue
 080            writer.WriteEndElement(); // CipherData
 081        }
 82    }
 83}